all built with the latest

This commit is contained in:
Alex Huang 2013-01-09 05:02:39 -08:00
commit 0bcb64605f
63 changed files with 564 additions and 858 deletions

View File

@ -22,9 +22,7 @@ import com.cloud.utils.component.ComponentLocator;
public class UserContext {
private static ThreadLocal<UserContext> s_currentContext = new ThreadLocal<UserContext>();
private static final ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
private static final AccountService _accountMgr = locator.getManager(AccountService.class);
private long userId;
private String sessionId;
private Account account;
@ -34,8 +32,6 @@ public class UserContext {
private boolean apiServer;
private static UserContext s_adminContext = new UserContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false);
public UserContext() {
}
@ -86,10 +82,10 @@ public class UserContext {
// however, there are many places that run background jobs assume the system context.
//
// If there is a security concern, all entry points from user (including the front end that takes HTTP
// request in and
// request in and
// the core async-job manager that runs commands from user) have explicitly setup the UserContext.
//
return s_adminContext;
return UserContextInitializer.getInstance().getAdminContext();
}
return context;
}

View File

@ -0,0 +1,40 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.user;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
@Component
public class UserContextInitializer {
@Inject private AccountService _accountMgr;
private static UserContextInitializer s_instance;
public UserContextInitializer() {
s_instance = this;
}
public static UserContextInitializer getInstance() {
return s_instance;
}
public UserContext getAdminContext() {
return new UserContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false);
}
}

View File

@ -58,4 +58,6 @@
<bean id="eventBus" class = "org.apache.cloudstack.framework.eventbus.EventBusBase" />
<bean id="userVmManager" class ="com.cloud.vm.UserVmManagerImpl" />
</beans>

View File

@ -0,0 +1,21 @@
package org.apache.cloudstack.engine.cloud.entity.api;
import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
import org.springframework.stereotype.Component;
@Component
public class VMEntityManagerImpl implements VMEntityManager {
@Override
public VMEntityVO loadVirtualMachine(String vmId) {
// TODO Auto-generated method stub
return null;
}
@Override
public void saveVirtualMachine(VMEntityVO vmInstanceVO) {
// TODO Auto-generated method stub
}
}

View File

@ -5,15 +5,18 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
public class VirtualMachineEntityImpl implements VirtualMachineEntity {
private VMEntityManager manager;
@Inject private VMEntityManager manager;
private VMEntityVO vmEntityVO;

View File

@ -32,6 +32,7 @@ import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl;
import org.apache.cloudstack.engine.cloud.entity.api.VMEntityManager;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.service.api.OrchestrationService;
import org.springframework.stereotype.Component;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.InsufficientCapacityException;
@ -49,7 +50,7 @@ import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.VMInstanceDao;
@Component
public class CloudOrchestrator implements OrchestrationService {
@Inject

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@ -44,8 +45,8 @@ import com.cloud.vm.VirtualMachineProfile;
public class RandomAllocator implements HostAllocator {
private static final Logger s_logger = Logger.getLogger(RandomAllocator.class);
private String _name;
private HostDao _hostDao;
private ResourceManager _resourceMgr;
@Inject private HostDao _hostDao;
@Inject private ResourceManager _resourceMgr;
@Override
public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type,
@ -119,13 +120,6 @@ public class RandomAllocator implements HostAllocator {
@Override
public boolean configure(String name, Map<String, Object> params) {
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_hostDao = locator.getDao(HostDao.class);
_resourceMgr = locator.getManager(ResourceManager.class);
if (_hostDao == null) {
s_logger.error("Unable to get host dao.");
return false;
}
_name=name;
return true;

View File

@ -348,13 +348,6 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
super.configure(name, params);
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException(
"Unable to get the configuration dao.");
}
createVmwareToolsIso();
if (s_logger.isInfoEnabled()) {

View File

@ -114,8 +114,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
private String _instance;
@Inject AgentManager _agentMgr;
@Inject
protected NetworkManager _netMgr;
@Inject NetworkManager _netMgr;
@Inject HostDao _hostDao;
@Inject ClusterDao _clusterDao;
@Inject ClusterDetailsDao _clusterDetailsDao;
@ -125,8 +124,8 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
@Inject SecondaryStorageVmManager _ssvmMgr;
@Inject CiscoNexusVSMDeviceDao _nexusDao;
@Inject ClusterVSMMapDao _vsmMapDao;
ConfigurationServer _configServer;
@Inject ConfigurationDao _configDao;
@Inject ConfigurationServer _configServer;
String _mountParent;
StorageLayer _storage;
@ -174,24 +173,18 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
if(!configDao.isPremium()) {
if(!_configDao.isPremium()) {
s_logger.error("Vmware component can only run under premium distribution");
throw new ConfigurationException("Vmware component can only run under premium distribution");
}
_instance = configDao.getValue(Config.InstanceName.key());
_instance = _configDao.getValue(Config.InstanceName.key());
if (_instance == null) {
_instance = "DEFAULT";
}
s_logger.info("VmwareManagerImpl config - instance.name: " + _instance);
_mountParent = configDao.getValue(Config.MountParent.key());
_mountParent = _configDao.getValue(Config.MountParent.key());
if (_mountParent == null) {
_mountParent = File.separator + "mnt";
}
@ -220,7 +213,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
}
}
value = configDao.getValue(Config.VmwareUseNexusVSwitch.key());
value = _configDao.getValue(Config.VmwareUseNexusVSwitch.key());
if(value == null) {
_nexusVSwitchActive = false;
}
@ -229,7 +222,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
_nexusVSwitchActive = Boolean.parseBoolean(value);
}
_privateNetworkVSwitchName = configDao.getValue(Config.VmwarePrivateNetworkVSwitch.key());
_privateNetworkVSwitchName = _configDao.getValue(Config.VmwarePrivateNetworkVSwitch.key());
if (_privateNetworkVSwitchName == null) {
if (_nexusVSwitchActive) {
@ -239,7 +232,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
}
}
_publicNetworkVSwitchName = configDao.getValue(Config.VmwarePublicNetworkVSwitch.key());
_publicNetworkVSwitchName = _configDao.getValue(Config.VmwarePublicNetworkVSwitch.key());
if (_publicNetworkVSwitchName == null) {
if (_nexusVSwitchActive) {
@ -249,7 +242,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
}
}
_guestNetworkVSwitchName = configDao.getValue(Config.VmwareGuestNetworkVSwitch.key());
_guestNetworkVSwitchName = _configDao.getValue(Config.VmwareGuestNetworkVSwitch.key());
if (_guestNetworkVSwitchName == null) {
if (_nexusVSwitchActive) {
@ -259,69 +252,66 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
}
}
_serviceConsoleName = configDao.getValue(Config.VmwareServiceConsole.key());
_serviceConsoleName = _configDao.getValue(Config.VmwareServiceConsole.key());
if(_serviceConsoleName == null) {
_serviceConsoleName = "Service Console";
}
_managemetPortGroupName = configDao.getValue(Config.VmwareManagementPortGroup.key());
_managemetPortGroupName = _configDao.getValue(Config.VmwareManagementPortGroup.key());
if(_managemetPortGroupName == null) {
_managemetPortGroupName = "Management Network";
}
_defaultSystemVmNicAdapterType = configDao.getValue(Config.VmwareSystemVmNicDeviceType.key());
_defaultSystemVmNicAdapterType = _configDao.getValue(Config.VmwareSystemVmNicDeviceType.key());
if(_defaultSystemVmNicAdapterType == null)
_defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
_additionalPortRangeStart = NumbersUtil.parseInt(configDao.getValue(Config.VmwareAdditionalVncPortRangeStart.key()), 59000);
_additionalPortRangeStart = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareAdditionalVncPortRangeStart.key()), 59000);
if(_additionalPortRangeStart > 65535) {
s_logger.warn("Invalid port range start port (" + _additionalPortRangeStart + ") for additional VNC port allocation, reset it to default start port 59000");
_additionalPortRangeStart = 59000;
}
_additionalPortRangeSize = NumbersUtil.parseInt(configDao.getValue(Config.VmwareAdditionalVncPortRangeSize.key()), 1000);
_additionalPortRangeSize = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareAdditionalVncPortRangeSize.key()), 1000);
if(_additionalPortRangeSize < 0 || _additionalPortRangeStart + _additionalPortRangeSize > 65535) {
s_logger.warn("Invalid port range size (" + _additionalPortRangeSize + " for range starts at " + _additionalPortRangeStart);
_additionalPortRangeSize = Math.min(1000, 65535 - _additionalPortRangeStart);
}
_routerExtraPublicNics = NumbersUtil.parseInt(configDao.getValue(Config.RouterExtraPublicNics.key()), 2);
_routerExtraPublicNics = NumbersUtil.parseInt(_configDao.getValue(Config.RouterExtraPublicNics.key()), 2);
_maxHostsPerCluster = NumbersUtil.parseInt(configDao.getValue(Config.VmwarePerClusterHostMax.key()), VmwareManager.MAX_HOSTS_PER_CLUSTER);
_cpuOverprovisioningFactor = configDao.getValue(Config.CPUOverprovisioningFactor.key());
_maxHostsPerCluster = NumbersUtil.parseInt(_configDao.getValue(Config.VmwarePerClusterHostMax.key()), VmwareManager.MAX_HOSTS_PER_CLUSTER);
_cpuOverprovisioningFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
if(_cpuOverprovisioningFactor == null || _cpuOverprovisioningFactor.isEmpty())
_cpuOverprovisioningFactor = "1";
_memOverprovisioningFactor = configDao.getValue(Config.MemOverprovisioningFactor.key());
_memOverprovisioningFactor = _configDao.getValue(Config.MemOverprovisioningFactor.key());
if(_memOverprovisioningFactor == null || _memOverprovisioningFactor.isEmpty())
_memOverprovisioningFactor = "1";
_reserveCpu = configDao.getValue(Config.VmwareReserveCpu.key());
_reserveCpu = _configDao.getValue(Config.VmwareReserveCpu.key());
if(_reserveCpu == null || _reserveCpu.isEmpty())
_reserveCpu = "false";
_reserveMem = configDao.getValue(Config.VmwareReserveMem.key());
_reserveMem = _configDao.getValue(Config.VmwareReserveMem.key());
if(_reserveMem == null || _reserveMem.isEmpty())
_reserveMem = "false";
_recycleHungWorker = configDao.getValue(Config.VmwareRecycleHungWorker.key());
_recycleHungWorker = _configDao.getValue(Config.VmwareRecycleHungWorker.key());
if(_recycleHungWorker == null || _recycleHungWorker.isEmpty())
_recycleHungWorker = "false";
_rootDiskController = configDao.getValue(Config.VmwareRootDiskControllerType.key());
_rootDiskController = _configDao.getValue(Config.VmwareRootDiskControllerType.key());
if(_rootDiskController == null || _rootDiskController.isEmpty())
_rootDiskController = DiskControllerType.ide.toString();
s_logger.info("Additional VNC port allocation range is settled at " + _additionalPortRangeStart + " to " + (_additionalPortRangeStart + _additionalPortRangeSize));
value = configDao.getValue("vmware.host.scan.interval");
value = _configDao.getValue("vmware.host.scan.interval");
_hostScanInterval = NumbersUtil.parseLong(value, DEFAULT_HOST_SCAN_INTERVAL);
s_logger.info("VmwareManagerImpl config - vmware.host.scan.interval: " + _hostScanInterval);
((VmwareStorageManagerImpl)_storageMgr).configure(params);
if(_configServer == null)
_configServer = (ConfigurationServer)ComponentLocator.getComponent(ConfigurationServer.Name);
_agentMgr.registerForHostEvents(this, true, true, true);
s_logger.info("VmwareManagerImpl has been successfully configured");

View File

@ -21,6 +21,7 @@ import java.util.Hashtable;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
@ -36,10 +37,8 @@ import org.bouncycastle.util.encoders.Base64;
import org.springframework.stereotype.Component;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.server.ManagementServer;
import com.cloud.user.UserAccount;
import com.cloud.user.dao.UserAccountDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
@ -48,8 +47,8 @@ import com.cloud.utils.exception.CloudRuntimeException;
public class LDAPUserAuthenticator extends DefaultUserAuthenticator {
public static final Logger s_logger = Logger.getLogger(LDAPUserAuthenticator.class);
private ConfigurationDao _configDao;
private UserAccountDao _userAccountDao;
@Inject private ConfigurationDao _configDao;
@Inject private UserAccountDao _userAccountDao;
@Override
public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) {
@ -157,9 +156,6 @@ public class LDAPUserAuthenticator extends DefaultUserAuthenticator {
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
super.configure(name, params);
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
_configDao = locator.getDao(ConfigurationDao.class);
_userAccountDao = locator.getDao(UserAccountDao.class);
return true;
}

View File

@ -21,6 +21,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
@ -42,7 +43,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
public class MD5UserAuthenticator extends DefaultUserAuthenticator {
public static final Logger s_logger = Logger.getLogger(MD5UserAuthenticator.class);
private UserAccountDao _userAccountDao;
@Inject private UserAccountDao _userAccountDao;
@Override
public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) {
@ -65,8 +66,6 @@ public class MD5UserAuthenticator extends DefaultUserAuthenticator {
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
super.configure(name, params);
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
_userAccountDao = locator.getDao(UserAccountDao.class);
return true;
}

View File

@ -21,6 +21,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
@ -38,7 +39,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
public class PlainTextUserAuthenticator extends DefaultUserAuthenticator {
public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class);
private UserAccountDao _userAccountDao;
@Inject private UserAccountDao _userAccountDao;
@Override
public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) {
@ -85,8 +86,6 @@ public class PlainTextUserAuthenticator extends DefaultUserAuthenticator {
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
super.configure(name, params);
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
_userAccountDao = locator.getDao(UserAccountDao.class);
return true;
}

View File

@ -231,13 +231,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_name = name;
final ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
final Map<String, String> configs = configDao.getConfiguration("AgentManager", params);
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
_port = NumbersUtil.parseInt(configs.get("port"), 8250);
final int workers = NumbersUtil.parseInt(configs.get("workers"), 5);

View File

@ -122,6 +122,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
@Inject
protected AgentManager _agentMgr;
@Inject ConfigurationDao _configDao;
protected ClusteredAgentManagerImpl() {
super();
@ -135,8 +136,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
s_logger.info("Configuring ClusterAgentManagerImpl. management server node id(msid): " + _nodeId);
ConfigurationDao configDao = ComponentLocator.getCurrentLocator().getDao(ConfigurationDao.class);
Map<String, String> params = configDao.getConfiguration(xmlParams);
Map<String, String> params = _configDao.getConfiguration(xmlParams);
String value = params.get(Config.DirectAgentLoadSize.key());
_loadSize = NumbersUtil.parseInt(value, 16);

View File

@ -40,8 +40,6 @@ import com.cloud.host.Host.Type;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
import com.cloud.offering.ServiceOffering;
import com.cloud.resource.ResourceManager;
import com.cloud.service.dao.ServiceOfferingDao;
@ -52,7 +50,6 @@ import com.cloud.storage.dao.GuestOSCategoryDao;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.user.Account;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.ConsoleProxyDao;
@ -396,7 +393,6 @@ public class FirstFitAllocator implements HostAllocator {
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
if (_configDao != null) {
Map<String, String> configs = _configDao.getConfiguration(params);
String opFactor = configs.get("cpu.overprovisioning.factor");

View File

@ -21,10 +21,12 @@ import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
import com.cloud.agent.manager.allocator.HostAllocator;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.host.Host;
@ -38,7 +40,7 @@ import com.cloud.vm.VirtualMachineProfile;
@Component
@Local(value={HostAllocator.class})
public class TestingAllocator implements HostAllocator {
HostDao _hostDao;
@Inject HostDao _hostDao;
Long _computingHost;
Long _storageHost;
Long _routingHost;
@ -81,9 +83,6 @@ public class TestingAllocator implements HostAllocator {
value = (String)params.get(Host.Type.Storage.toString());
_storageHost = (value != null) ? Long.parseLong(value) : null;
ComponentLocator _locator = ComponentLocator.getCurrentLocator();
_hostDao = _locator.getDao(HostDao.class);
_name = name;
return true;

View File

@ -106,7 +106,6 @@ public class AlertManagerImpl implements AlertManager {
@Inject private ConfigurationDao _configDao;
@Inject private ResourceManager _resourceMgr;
@Inject private ConfigurationManager _configMgr;
private Timer _timer = null;
private float _cpuOverProvisioningFactor = 1;
private long _capacityCheckPeriod = 60L * 60L * 1000L; // one hour by default
@ -126,14 +125,7 @@ public class AlertManagerImpl implements AlertManager {
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
s_logger.error("Unable to get the configuration dao.");
return false;
}
Map<String, String> configs = configDao.getConfiguration("management-server", params);
Map<String, String> configs = _configDao.getConfiguration("management-server", params);
// set up the email system for alerts
String emailAddressList = configs.get("alert.email.addresses");

View File

@ -19,6 +19,7 @@ package com.cloud.alert;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
@ -29,8 +30,6 @@ import com.cloud.cluster.ClusterNodeJoinEventArgs;
import com.cloud.cluster.ClusterNodeLeftEventArgs;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.dao.ManagementServerHostDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.GlobalLock;
import com.cloud.utils.events.EventArgs;
import com.cloud.utils.events.SubscriptionMgr;
@ -40,10 +39,9 @@ public class ClusterAlertAdapter implements AlertAdapter {
private static final Logger s_logger = Logger.getLogger(ClusterAlertAdapter.class);
private AlertManager _alertMgr;
private String _name;
private ManagementServerHostDao _mshostDao;
@Inject private AlertManager _alertMgr;
@Inject private ManagementServerHostDao _mshostDao;
public void onClusterAlert(Object sender, EventArgs args) {
if (s_logger.isDebugEnabled()) {
@ -109,19 +107,7 @@ public class ClusterAlertAdapter implements AlertAdapter {
s_logger.info("Start configuring cluster alert manager : " + name);
}
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_mshostDao = locator.getDao(ManagementServerHostDao.class);
if (_mshostDao == null) {
throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName());
}
_alertMgr = locator.getManager(AlertManager.class);
if (_alertMgr == null) {
throw new ConfigurationException("Unable to get " + AlertManager.class.getName());
}
try {
try {
SubscriptionMgr.getInstance().subscribe(ClusterManager.ALERT_SUBJECT, this, "onClusterAlert");
} catch (SecurityException e) {
throw new ConfigurationException("Unable to register cluster event subscription");

View File

@ -19,6 +19,7 @@ package com.cloud.alert;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
@ -41,11 +42,11 @@ public class ConsoleProxyAlertAdapter implements AlertAdapter {
private static final Logger s_logger = Logger.getLogger(ConsoleProxyAlertAdapter.class);
private AlertManager _alertMgr;
@Inject private AlertManager _alertMgr;
private String _name;
private DataCenterDao _dcDao;
private ConsoleProxyDao _consoleProxyDao;
@Inject private DataCenterDao _dcDao;
@Inject private ConsoleProxyDao _consoleProxyDao;
public void onProxyAlert(Object sender, ConsoleProxyAlertEventArgs args) {
if(s_logger.isDebugEnabled())
@ -187,23 +188,6 @@ public class ConsoleProxyAlertAdapter implements AlertAdapter {
if (s_logger.isInfoEnabled())
s_logger.info("Start configuring console proxy alert manager : " + name);
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_dcDao = locator.getDao(DataCenterDao.class);
if (_dcDao == null) {
throw new ConfigurationException("Unable to get " + DataCenterDao.class.getName());
}
_consoleProxyDao = locator.getDao(ConsoleProxyDao.class);
if (_consoleProxyDao == null) {
throw new ConfigurationException("Unable to get " + ConsoleProxyDao.class.getName());
}
_alertMgr = locator.getManager(AlertManager.class);
if (_alertMgr == null) {
throw new ConfigurationException("Unable to get " + AlertManager.class.getName());
}
try {
SubscriptionMgr.getInstance().subscribe(ConsoleProxyManager.ALERT_SUBJECT, this, "onProxyAlert");
} catch (SecurityException e) {

View File

@ -119,7 +119,6 @@ import com.cloud.event.EventUtils;
import com.cloud.exception.CloudAuthenticationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.server.ManagementServer;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.DomainManager;
@ -130,7 +129,7 @@ import com.cloud.user.UserVO;
import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.PluggableService;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
@ -151,6 +150,9 @@ public class ApiServer implements HttpRequestHandler {
@Inject private ConfigurationDao _configDao;
@Inject protected List<APIAccessChecker> _apiAccessCheckers;
@Inject List<PluggableService> _pluggableServices;
@Inject IdentityDao _identityDao;
private Account _systemAccount = null;
private User _systemUser = null;
private static int _workerCount = 0;
@ -683,10 +685,8 @@ public class ApiServer implements HttpRequestHandler {
}
public Long fetchDomainId(String domainUUID){
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
IdentityDao identityDao = locator.getDao(IdentityDao.class);
try{
Long domainId = identityDao.getIdentityId("domain", domainUUID);
Long domainId = _identityDao.getIdentityId("domain", domainUUID);
return domainId;
}catch(InvalidParameterValueException ex){
return null;

View File

@ -19,6 +19,7 @@ package com.cloud.async;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.springframework.stereotype.Component;
@ -46,23 +47,23 @@ import com.cloud.vm.dao.UserVmDao;
public class AsyncJobExecutorContextImpl implements AsyncJobExecutorContext {
private String _name;
private AgentManager _agentMgr;
private NetworkManager _networkMgr;
private UserVmManager _vmMgr;
private SnapshotManager _snapMgr;
private AccountManager _accountMgr;
private StorageManager _storageMgr;
private EventDao _eventDao;
private UserVmDao _vmDao;
private AccountDao _accountDao;
private VolumeDao _volumeDao;
private DomainRouterDao _routerDao;
private IPAddressDao _ipAddressDao;
private AsyncJobDao _jobDao;
private UserDao _userDao;
private VirtualMachineManager _itMgr;
@Inject private AgentManager _agentMgr;
@Inject private NetworkManager _networkMgr;
@Inject private UserVmManager _vmMgr;
@Inject private SnapshotManager _snapMgr;
@Inject private AccountManager _accountMgr;
@Inject private StorageManager _storageMgr;
@Inject private EventDao _eventDao;
@Inject private UserVmDao _vmDao;
@Inject private AccountDao _accountDao;
@Inject private VolumeDao _volumeDao;
@Inject private DomainRouterDao _routerDao;
@Inject private IPAddressDao _ipAddressDao;
@Inject private AsyncJobDao _jobDao;
@Inject private UserDao _userDao;
@Inject private VirtualMachineManager _itMgr;
private ManagementServer _managementServer;
@Inject private ManagementServer _managementServer;
@Override
public ManagementServer getManagementServer() {
@ -150,87 +151,6 @@ public class AsyncJobExecutorContextImpl implements AsyncJobExecutorContext {
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_managementServer = (ManagementServer)ComponentLocator.getComponent("management-server");
if (_managementServer == null) {
throw new ConfigurationException("unable to get " + ManagementServer.class.getName());
}
_agentMgr = locator.getManager(AgentManager.class);
if (_agentMgr == null) {
throw new ConfigurationException("unable to get " + AgentManager.class.getName());
}
_networkMgr = locator.getManager(NetworkManager.class);
if (_networkMgr == null) {
throw new ConfigurationException("unable to get " + NetworkManager.class.getName());
}
_vmMgr = locator.getManager(UserVmManager.class);
if (_vmMgr == null) {
throw new ConfigurationException("unable to get " + UserVmManager.class.getName());
}
_snapMgr = locator.getManager(SnapshotManager.class);
if (_snapMgr == null) {
throw new ConfigurationException("unable to get " + SnapshotManager.class.getName());
}
_accountMgr = locator.getManager(AccountManager.class);
if (_accountMgr == null) {
throw new ConfigurationException("unable to get " + AccountManager.class.getName());
}
_storageMgr = locator.getManager(StorageManager.class);
if (_storageMgr == null) {
throw new ConfigurationException("unable to get " + StorageManager.class.getName());
}
_eventDao = locator.getDao(EventDao.class);
if (_eventDao == null) {
throw new ConfigurationException("unable to get " + EventDao.class.getName());
}
_vmDao = locator.getDao(UserVmDao.class);
if (_vmDao == null) {
throw new ConfigurationException("unable to get " + UserVmDao.class.getName());
}
_accountDao = locator.getDao(AccountDao.class);
if (_accountDao == null) {
throw new ConfigurationException("unable to get " + AccountDao.class.getName());
}
_volumeDao = locator.getDao(VolumeDao.class);
if (_volumeDao == null) {
throw new ConfigurationException("unable to get " + VolumeDao.class.getName());
}
_routerDao = locator.getDao(DomainRouterDao.class);
if (_routerDao == null) {
throw new ConfigurationException("unable to get " + DomainRouterDao.class.getName());
}
_ipAddressDao = locator.getDao(IPAddressDao.class);
if (_ipAddressDao == null) {
throw new ConfigurationException("unable to get " + IPAddressDao.class.getName());
}
_jobDao = locator.getDao(AsyncJobDao.class);
if(_jobDao == null) {
throw new ConfigurationException("unable to get " + AsyncJobDao.class.getName());
}
_userDao = locator.getDao(UserDao.class);
if(_userDao == null) {
throw new ConfigurationException("unable to get " + UserDao.class.getName());
}
_itMgr = locator.getManager(VirtualMachineManager.class);
if (_itMgr == null) {
throw new ConfigurationException("unable to get " + VirtualMachineManager.class.getName());
}
return true;
}

View File

@ -32,6 +32,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
@ -87,12 +88,13 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
private String _name;
private AsyncJobExecutorContext _context;
private SyncQueueManager _queueMgr;
private ClusterManager _clusterMgr;
private AccountManager _accountMgr;
private AccountDao _accountDao;
private AsyncJobDao _jobDao;
@Inject private AsyncJobExecutorContext _context;
@Inject private SyncQueueManager _queueMgr;
@Inject private ClusterManager _clusterMgr;
@Inject private AccountManager _accountMgr;
@Inject private AccountDao _accountDao;
@Inject private AsyncJobDao _jobDao;
@Inject private ConfigurationDao _configDao;
private long _jobExpireSeconds = 86400; // 1 day
private long _jobCancelThresholdSeconds = 3600; // 1 hour (for cancelling the jobs blocking other jobs)
@ -697,47 +699,14 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
int expireMinutes = NumbersUtil.parseInt(
configDao.getValue(Config.JobExpireMinutes.key()), 24*60);
_configDao.getValue(Config.JobExpireMinutes.key()), 24*60);
_jobExpireSeconds = (long)expireMinutes*60;
_jobCancelThresholdSeconds = NumbersUtil.parseInt(
configDao.getValue(Config.JobCancelThresholdMinutes.key()), 60);
_configDao.getValue(Config.JobCancelThresholdMinutes.key()), 60);
_jobCancelThresholdSeconds *= 60;
_accountDao = locator.getDao(AccountDao.class);
if (_accountDao == null) {
throw new ConfigurationException("Unable to get " + AccountDao.class.getName());
}
_jobDao = locator.getDao(AsyncJobDao.class);
if (_jobDao == null) {
throw new ConfigurationException("Unable to get "
+ AsyncJobDao.class.getName());
}
_context = locator.getManager(AsyncJobExecutorContext.class);
if (_context == null) {
throw new ConfigurationException("Unable to get "
+ AsyncJobExecutorContext.class.getName());
}
_queueMgr = locator.getManager(SyncQueueManager.class);
if(_queueMgr == null) {
throw new ConfigurationException("Unable to get "
+ SyncQueueManager.class.getName());
}
_clusterMgr = locator.getManager(ClusterManager.class);
_accountMgr = locator.getManager(AccountManager.class);
_dispatcher = ApiDispatcher.getInstance();

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
@ -42,8 +43,8 @@ public class SyncQueueManagerImpl implements SyncQueueManager {
private String _name;
private SyncQueueDao _syncQueueDao;
private SyncQueueItemDao _syncQueueItemDao;
@Inject private SyncQueueDao _syncQueueDao;
@Inject private SyncQueueItemDao _syncQueueItemDao;
@Override
@DB
@ -243,20 +244,6 @@ public class SyncQueueManagerImpl implements SyncQueueManager {
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_syncQueueDao = locator.getDao(SyncQueueDao.class);
if (_syncQueueDao == null) {
throw new ConfigurationException("Unable to get "
+ SyncQueueDao.class.getName());
}
_syncQueueItemDao = locator.getDao(SyncQueueItemDao.class);
if (_syncQueueItemDao == null) {
throw new ConfigurationException("Unable to get "
+ SyncQueueDao.class.getName());
}
return true;
}

View File

@ -23,7 +23,6 @@ import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.IAgentControl;
import com.cloud.agent.api.Answer;
@ -66,7 +65,6 @@ import com.cloud.utils.script.Script2.ParamType;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
@Component
@Local(value = ServerResource.class)
public class BareMetalResourceBase implements ServerResource {
private static final Logger s_logger = Logger.getLogger(BareMetalResourceBase.class);

View File

@ -33,8 +33,6 @@ import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.StopAnswer;
@ -84,7 +82,6 @@ import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
@ -105,13 +102,11 @@ import com.cloud.vm.VirtualMachineName;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfile.Param;
@Component
@Primary
@Local(value={BareMetalVmManager.class, BareMetalVmService.class})
public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMetalVmManager, BareMetalVmService, Manager,
StateListener<State, VirtualMachine.Event, VirtualMachine> {
private static final Logger s_logger = Logger.getLogger(BareMetalVmManagerImpl.class);
private ConfigurationDao _configDao;
@Inject ConfigurationDao _configDao;
@Inject PxeServerManager _pxeMgr;
@Inject ResourceManager _resourceMgr;
@ -444,12 +439,6 @@ public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMet
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_configDao = locator.getDao(ConfigurationDao.class);
if (_configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
_instance = configs.get("instance.name");

View File

@ -59,6 +59,8 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste
@Inject
private ClusterManager _clusterMgr;
@Inject ConfigurationDao _configDao;
long _msId;
private final ScheduledExecutorService _cleanupScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Task-Cleanup"));
@ -79,10 +81,7 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste
_clusterMgr.registerListener(this);
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> params = configDao.getConfiguration(xmlParams);
Map<String, String> params = _configDao.getConfiguration(xmlParams);
_cleanupRetryInterval = NumbersUtil.parseInt(params.get(Config.TaskCleanupRetryInterval.key()), 600);
_maidDao.takeover(_msId, _msId);

View File

@ -127,10 +127,11 @@ public class ClusterManagerImpl implements ClusterManager {
@Inject
private List<ClusterServiceAdapter> _serviceAdapters;
private ManagementServerHostDao _mshostDao;
private ManagementServerHostPeerDao _mshostPeerDao;
private HostDao _hostDao;
private HostTransferMapDao _hostTransferDao;
@Inject private ManagementServerHostDao _mshostDao;
@Inject private ManagementServerHostPeerDao _mshostPeerDao;
@Inject private HostDao _hostDao;
@Inject private HostTransferMapDao _hostTransferDao;
@Inject private ConfigurationDao _configDao;
//
// pay attention to _mshostId and _msid
@ -1257,38 +1258,7 @@ public class ClusterManagerImpl implements ClusterManager {
}
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_agentMgr = locator.getManager(AgentManager.class);
if (_agentMgr == null) {
throw new ConfigurationException("Unable to get " + AgentManager.class.getName());
}
_mshostDao = locator.getDao(ManagementServerHostDao.class);
if (_mshostDao == null) {
throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName());
}
_mshostPeerDao = locator.getDao(ManagementServerHostPeerDao.class);
if (_mshostPeerDao == null) {
throw new ConfigurationException("Unable to get " + ManagementServerHostPeerDao.class.getName());
}
_hostDao = locator.getDao(HostDao.class);
if (_hostDao == null) {
throw new ConfigurationException("Unable to get " + HostDao.class.getName());
}
_hostTransferDao = locator.getDao(HostTransferMapDao.class);
if (_hostTransferDao == null) {
throw new ConfigurationException("Unable to get agent transfer map dao");
}
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
Map<String, String> configs = configDao.getConfiguration("management-server", params);
Map<String, String> configs = _configDao.getConfiguration("management-server", params);
String value = configs.get("cluster.heartbeat.interval");
if (value != null) {
@ -1338,7 +1308,7 @@ public class ClusterManagerImpl implements ClusterManager {
throw new ConfigurationException("Unable to set current cluster service adapter");
}
_agentLBEnabled = Boolean.valueOf(configDao.getValue(Config.AgentLbEnable.key()));
_agentLBEnabled = Boolean.valueOf(_configDao.getValue(Config.AgentLbEnable.key()));
String connectedAgentsThreshold = configs.get("agent.load.threshold");

View File

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Properties;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
@ -35,7 +36,6 @@ import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.ComponentLocator;
@Component
@Local(value={ClusterServiceAdapter.class})
@ -45,11 +45,11 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter {
private static final int DEFAULT_SERVICE_PORT = 9090;
private static final int DEFAULT_REQUEST_TIMEOUT = 300; // 300 seconds
private ClusterManager _manager;
@Inject private ClusterManager _manager;
private ManagementServerHostDao _mshostDao;
@Inject private ManagementServerHostDao _mshostDao;
private ConfigurationDao _configDao;
@Inject private ConfigurationDao _configDao;
private ClusterServiceServletContainer _servletContainer;
@ -134,23 +134,6 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter {
if(_mshostDao != null)
return;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_manager = locator.getManager(ClusterManager.class);
if(_manager == null)
throw new ConfigurationException("Unable to get " + ClusterManager.class.getName());
_mshostDao = locator.getDao(ManagementServerHostDao.class);
if(_mshostDao == null)
throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName());
if(_mshostDao == null)
throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName());
_configDao = locator.getDao(ConfigurationDao.class);
if(_configDao == null)
throw new ConfigurationException("Unable to get " + ConfigurationDao.class.getName());
String value = _configDao.getValue(Config.ClusterMessageTimeOutSeconds.key());
_clusterRequestTimeoutSeconds = NumbersUtil.parseInt(value, DEFAULT_REQUEST_TIMEOUT);
s_logger.info("Configure cluster request time out. timeout: " + _clusterRequestTimeoutSeconds + " seconds");

View File

@ -24,7 +24,6 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.Listener;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.exception.AgentUnavailableException;

View File

@ -87,6 +87,9 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu
VirtualMachineManager _itMgr;
@Inject
protected ConsoleProxyDao _cpDao;
@Inject ConfigurationDao _configDao;
public int getVncPort(VMInstanceVO vm) {
if (vm.getHostId() == null) {
return -1;
@ -104,13 +107,7 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
Map<String, String> configs = configDao.getConfiguration("management-server", params);
Map<String, String> configs = _configDao.getConfiguration("management-server", params);
String value = configs.get("consoleproxy.url.port");
if (value != null) {
_consoleProxyUrlPort = NumbersUtil.parseInt(value, ConsoleProxyManager.DEFAULT_PROXY_URL_PORT);

View File

@ -81,14 +81,6 @@ public class ConsoleProxyBalanceAllocator implements ConsoleProxyAllocator {
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
Map<String, String> configs = configDao.getConfiguration();
return true;
}

View File

@ -1452,13 +1452,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
Map<String, String> configs = configDao.getConfiguration("management-server", params);
Map<String, String> configs = _configDao.getConfiguration("management-server", params);
String value = configs.get(Config.ConsoleProxyCmdPort.key());
value = configs.get("consoleproxy.sslEnabled");
@ -1505,7 +1499,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
prepareDefaultCertificate();
Map<String, String> agentMgrConfigs = configDao.getConfiguration("AgentManager", params);
Map<String, String> agentMgrConfigs = _configDao.getConfiguration("AgentManager", params);
_mgmt_host = agentMgrConfigs.get("host");
if (_mgmt_host == null) {
s_logger.warn("Critical warning! Please configure your management server host address right after you have started your management server and then restart it, otherwise you won't be able to do console access");

View File

@ -40,6 +40,7 @@ public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager imp
String _ip = null;
@Inject ConsoleProxyDao _proxyDao;
@Inject ResourceManager _resourceMgr;
@Inject ConfigurationDao _configDao;
@Override
protected HostVO findHost(VMInstanceVO vm) {
@ -58,10 +59,7 @@ public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager imp
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> dbParams = configDao.getConfiguration("ManagementServer", params);
Map<String, String> dbParams = _configDao.getConfiguration("ManagementServer", params);
_ip = dbParams.get("public.ip");
if (_ip == null) {

View File

@ -33,7 +33,6 @@ import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria2;
@Component
@Local(value=EntityManager.class)

View File

@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.springframework.stereotype.Component;
@ -59,9 +60,9 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
protected SearchBuilder<VlanVO> NetworkVlanSearch;
protected SearchBuilder<VlanVO> PhysicalNetworkVlanSearch;
protected PodVlanMapDaoImpl _podVlanMapDao = new PodVlanMapDaoImpl();
protected AccountVlanMapDao _accountVlanMapDao = new AccountVlanMapDaoImpl();
protected IPAddressDao _ipAddressDao = null;
@Inject protected PodVlanMapDao _podVlanMapDao;
@Inject protected AccountVlanMapDao _accountVlanMapDao;
@Inject protected IPAddressDao _ipAddressDao;
@Override
public VlanVO findByZoneAndVlanId(long zoneId, String vlanId) {
@ -177,13 +178,6 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
boolean result = super.configure(name, params);
if (result) {
final ComponentLocator locator = ComponentLocator.getCurrentLocator();
_ipAddressDao = locator.getDao(IPAddressDao.class);
if (_ipAddressDao == null) {
throw new ConfigurationException("Unable to get " + IPAddressDao.class.getName());
}
}
ZoneTypeAllPodsSearch = createSearchBuilder();
ZoneTypeAllPodsSearch.and("zoneId", ZoneTypeAllPodsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
ZoneTypeAllPodsSearch.and("vlanType", ZoneTypeAllPodsSearch.entity().getVlanType(), SearchCriteria.Op.EQ);

View File

@ -16,16 +16,27 @@
// under the License.
package com.cloud.event;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
import com.cloud.event.dao.EventDao;
import com.cloud.server.ManagementServer;
import com.cloud.user.AccountVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.component.ComponentLocator;
@Component
public class EventUtils {
private static EventDao _eventDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(EventDao.class);
private static AccountDao _accountDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(AccountDao.class);
private static EventDao _eventDao;
private static AccountDao _accountDao;
@Inject EventDao _placeHoderEventDao;
@Inject AccountDao _placeHoderAccountDao;
public EventUtils() {
_eventDao = _placeHoderEventDao;
_accountDao = _placeHoderAccountDao;
}
public static Long saveEvent(Long userId, Long accountId, Long domainId, String type, String description) {
EventVO event = new EventVO();
event.setUserId(userId);

View File

@ -41,21 +41,12 @@ public class HighAvailabilityManagerExtImpl extends HighAvailabilityManagerImpl
@Inject
UsageJobDao _usageJobDao;
ConfigurationDao configDao;
@Inject ConfigurationDao configDao;
@Override
public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException {
super.configure(name, xmlParams);
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null)
{
s_logger.warn("Unable to get a configuration dao to check config value for enableUsageServer");
return false;
}
return true;
}

View File

@ -141,7 +141,11 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
AccountManager _accountMgr;
@Inject
ResourceManager _resourceMgr;
@Inject
ManagementServer _msServer;
@Inject
ConfigurationDao _configDao;
String _instance;
ScheduledExecutorService _executor;
int _stopRetryInterval;
@ -690,15 +694,11 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
@Override
public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
_serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId();
_serverId = _msServer.getId();
Map<String, String> params = new HashMap<String, String>();
final ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao != null) {
params = configDao.getConfiguration(Long.toHexString(_serverId), xmlParams);
}
params = _configDao.getConfiguration(Long.toHexString(_serverId), xmlParams);
String value = params.get(Config.HAWorkers.key());
final int count = NumbersUtil.parseInt(value, 1);

View File

@ -53,7 +53,6 @@ import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.kvm.discoverer.KvmDummyResourceBase;
import com.cloud.network.NetworkManager;
import com.cloud.network.PhysicalNetworkSetupInfo;
import com.cloud.resource.Discoverer;
@ -62,323 +61,321 @@ import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceStateAdapter;
import com.cloud.resource.ServerResource;
import com.cloud.resource.UnableDeleteHostException;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.script.Script;
import com.cloud.utils.ssh.SSHCmdHelper;
@Component
@Local(value=Discoverer.class)
public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
Listener, ResourceStateAdapter {
private static final Logger s_logger = Logger.getLogger(KvmServerDiscoverer.class);
private ConfigurationDao _configDao;
private String _hostIp;
private int _waitTime = 5; /*wait for 5 minutes*/
private String _kvmPrivateNic;
private String _kvmPublicNic;
private String _kvmGuestNic;
@Inject HostDao _hostDao = null;
@Inject ClusterDao _clusterDao;
@Inject ResourceManager _resourceMgr;
@Inject AgentManager _agentMgr;
@Inject NetworkManager _networkMgr;
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
// TODO Auto-generated method stub
return false;
}
Listener, ResourceStateAdapter {
private static final Logger s_logger = Logger.getLogger(KvmServerDiscoverer.class);
private String _hostIp;
private final int _waitTime = 5; /*wait for 5 minutes*/
private String _kvmPrivateNic;
private String _kvmPublicNic;
private String _kvmGuestNic;
@Inject HostDao _hostDao = null;
@Inject ClusterDao _clusterDao;
@Inject ResourceManager _resourceMgr;
@Inject AgentManager _agentMgr;
@Inject NetworkManager _networkMgr;
@Inject ConfigurationDao _configDao;
@Override
public boolean processCommands(long agentId, long seq, Command[] commands) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
// TODO Auto-generated method stub
return false;
}
@Override
public AgentControlAnswer processControlCommand(long agentId,
AgentControlCommand cmd) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean processCommands(long agentId, long seq, Command[] commands) {
// TODO Auto-generated method stub
return false;
}
@Override
public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) {
}
@Override
public AgentControlAnswer processControlCommand(long agentId,
AgentControlCommand cmd) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean processDisconnect(long agentId, Status state) {
// TODO Auto-generated method stub
return false;
}
@Override
public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) {
}
@Override
public boolean isRecurring() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean processDisconnect(long agentId, Status state) {
// TODO Auto-generated method stub
return false;
}
@Override
public int getTimeout() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isRecurring() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean processTimeout(long agentId, long seq) {
// TODO Auto-generated method stub
return false;
}
@Override
public int getTimeout() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean processTimeout(long agentId, long seq) {
// TODO Auto-generated method stub
return false;
}
@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId,
Long podId, Long clusterId, URI uri, String username,
String password, List<String> hostTags) throws DiscoveryException {
@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId,
Long podId, Long clusterId, URI uri, String username,
String password, List<String> hostTags) throws DiscoveryException {
ClusterVO cluster = _clusterDao.findById(clusterId);
if(cluster == null || cluster.getHypervisorType() != HypervisorType.KVM) {
if(s_logger.isInfoEnabled())
s_logger.info("invalid cluster id or cluster is not for KVM hypervisors");
return null;
if(s_logger.isInfoEnabled())
s_logger.info("invalid cluster id or cluster is not for KVM hypervisors");
return null;
}
Map<KvmDummyResourceBase, Map<String, String>> resources = new HashMap<KvmDummyResourceBase, Map<String, String>>();
Map<String, String> details = new HashMap<String, String>();
if (!uri.getScheme().equals("http")) {
Map<KvmDummyResourceBase, Map<String, String>> resources = new HashMap<KvmDummyResourceBase, Map<String, String>>();
Map<String, String> details = new HashMap<String, String>();
if (!uri.getScheme().equals("http")) {
String msg = "urlString is not http so we're not taking care of the discovery for this: " + uri;
s_logger.debug(msg);
return null;
}
com.trilead.ssh2.Connection sshConnection = null;
String agentIp = null;
try {
String hostname = uri.getHost();
InetAddress ia = InetAddress.getByName(hostname);
agentIp = ia.getHostAddress();
String guid = UUID.nameUUIDFromBytes(agentIp.getBytes()).toString();
String guidWithTail = guid + "-LibvirtComputingResource";/*tail added by agent.java*/
if (_resourceMgr.findHostByGuid(guidWithTail) != null) {
s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database.");
return null;
}
sshConnection = new com.trilead.ssh2.Connection(agentIp, 22);
}
com.trilead.ssh2.Connection sshConnection = null;
String agentIp = null;
try {
sshConnection.connect(null, 60000, 60000);
if (!sshConnection.authenticateWithPassword(username, password)) {
s_logger.debug("Failed to authenticate");
throw new DiscoveredWithErrorException("Authentication error");
}
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "lsmod|grep kvm", 3)) {
s_logger.debug("It's not a KVM enabled machine");
return null;
}
List <PhysicalNetworkSetupInfo> netInfos = _networkMgr.getPhysicalNetworkInfo(dcId, HypervisorType.KVM);
String kvmPrivateNic = null;
String kvmPublicNic = null;
String kvmGuestNic = null;
String hostname = uri.getHost();
InetAddress ia = InetAddress.getByName(hostname);
agentIp = ia.getHostAddress();
String guid = UUID.nameUUIDFromBytes(agentIp.getBytes()).toString();
String guidWithTail = guid + "-LibvirtComputingResource";/*tail added by agent.java*/
if (_resourceMgr.findHostByGuid(guidWithTail) != null) {
s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database.");
return null;
}
for (PhysicalNetworkSetupInfo info : netInfos) {
if (info.getPrivateNetworkName() != null) {
kvmPrivateNic = info.getPrivateNetworkName();
}
if (info.getPublicNetworkName() != null) {
kvmPublicNic = info.getPublicNetworkName();
}
if (info.getGuestNetworkName() != null) {
kvmGuestNic = info.getGuestNetworkName();
}
}
sshConnection = new com.trilead.ssh2.Connection(agentIp, 22);
sshConnection.connect(null, 60000, 60000);
if (!sshConnection.authenticateWithPassword(username, password)) {
s_logger.debug("Failed to authenticate");
throw new DiscoveredWithErrorException("Authentication error");
}
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "lsmod|grep kvm", 3)) {
s_logger.debug("It's not a KVM enabled machine");
return null;
}
List <PhysicalNetworkSetupInfo> netInfos = _networkMgr.getPhysicalNetworkInfo(dcId, HypervisorType.KVM);
String kvmPrivateNic = null;
String kvmPublicNic = null;
String kvmGuestNic = null;
for (PhysicalNetworkSetupInfo info : netInfos) {
if (info.getPrivateNetworkName() != null) {
kvmPrivateNic = info.getPrivateNetworkName();
}
if (info.getPublicNetworkName() != null) {
kvmPublicNic = info.getPublicNetworkName();
}
if (info.getGuestNetworkName() != null) {
kvmGuestNic = info.getGuestNetworkName();
}
}
if (kvmPrivateNic == null && kvmPublicNic == null && kvmGuestNic == null) {
kvmPrivateNic = _kvmPrivateNic;
kvmPublicNic = _kvmPublicNic;
kvmGuestNic = _kvmGuestNic;
}
if (kvmPublicNic == null) {
kvmPublicNic = (kvmGuestNic != null) ? kvmGuestNic : kvmPrivateNic;
}
if (kvmPrivateNic == null) {
kvmPrivateNic = (kvmPublicNic != null) ? kvmPublicNic : kvmGuestNic;
}
if (kvmGuestNic == null) {
kvmGuestNic = (kvmPublicNic != null) ? kvmPublicNic : kvmPrivateNic;
}
if (kvmPrivateNic == null && kvmPublicNic == null && kvmGuestNic == null) {
kvmPrivateNic = _kvmPrivateNic;
kvmPublicNic = _kvmPublicNic;
kvmGuestNic = _kvmGuestNic;
}
if (kvmPublicNic == null) {
kvmPublicNic = (kvmGuestNic != null) ? kvmGuestNic : kvmPrivateNic;
}
if (kvmPrivateNic == null) {
kvmPrivateNic = (kvmPublicNic != null) ? kvmPublicNic : kvmGuestNic;
}
if (kvmGuestNic == null) {
kvmGuestNic = (kvmPublicNic != null) ? kvmPublicNic : kvmPrivateNic;
}
String parameters = " -m " + _hostIp + " -z " + dcId + " -p " + podId + " -c " + clusterId + " -g " + guid + " -a";
parameters += " --pubNic=" + kvmPublicNic;
parameters += " --prvNic=" + kvmPrivateNic;
parameters += " --guestNic=" + kvmGuestNic;
SSHCmdHelper.sshExecuteCmd(sshConnection, "cloud-setup-agent " + parameters, 3);
KvmDummyResourceBase kvmResource = new KvmDummyResourceBase();
Map<String, Object> params = new HashMap<String, Object>();
params.put("zone", Long.toString(dcId));
params.put("pod", Long.toString(podId));
params.put("cluster", Long.toString(clusterId));
params.put("guid", guid);
params.put("agentIp", agentIp);
kvmResource.configure("kvm agent", params);
resources.put(kvmResource, details);
HostVO connectedHost = waitForHostConnect(dcId, podId, clusterId, guidWithTail);
if (connectedHost == null)
return null;
details.put("guid", guidWithTail);
// place a place holder guid derived from cluster ID
if (cluster.getGuid() == null) {
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString());
_clusterDao.update(clusterId, cluster);
}
//save user name and password
_hostDao.loadDetails(connectedHost);
Map<String, String> hostDetails = connectedHost.getDetails();
hostDetails.put("password", password);
hostDetails.put("username", username);
_hostDao.saveDetails(connectedHost);
return resources;
} catch (DiscoveredWithErrorException e){
throw e;
}catch (Exception e) {
String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage();
s_logger.warn(msg);
} finally {
if (sshConnection != null)
sshConnection.close();
}
return null;
}
SSHCmdHelper.sshExecuteCmd(sshConnection, "cloud-setup-agent " + parameters, 3);
private HostVO waitForHostConnect(long dcId, long podId, long clusterId, String guid) {
for (int i = 0; i < _waitTime *2; i++) {
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, clusterId, podId, dcId);
for (HostVO host : hosts) {
if (host.getGuid().equalsIgnoreCase(guid)) {
return host;
}
}
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
s_logger.debug("Failed to sleep: " + e.toString());
}
}
s_logger.debug("Timeout, to wait for the host connecting to mgt svr, assuming it is failed");
List<HostVO> hosts = _resourceMgr.findHostByGuid(dcId, guid);
if (hosts.size() == 1) {
return hosts.get(0);
} else {
return null;
}
}
@Override
KvmDummyResourceBase kvmResource = new KvmDummyResourceBase();
Map<String, Object> params = new HashMap<String, Object>();
params.put("zone", Long.toString(dcId));
params.put("pod", Long.toString(podId));
params.put("cluster", Long.toString(clusterId));
params.put("guid", guid);
params.put("agentIp", agentIp);
kvmResource.configure("kvm agent", params);
resources.put(kvmResource, details);
HostVO connectedHost = waitForHostConnect(dcId, podId, clusterId, guidWithTail);
if (connectedHost == null)
return null;
details.put("guid", guidWithTail);
// place a place holder guid derived from cluster ID
if (cluster.getGuid() == null) {
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString());
_clusterDao.update(clusterId, cluster);
}
//save user name and password
_hostDao.loadDetails(connectedHost);
Map<String, String> hostDetails = connectedHost.getDetails();
hostDetails.put("password", password);
hostDetails.put("username", username);
_hostDao.saveDetails(connectedHost);
return resources;
} catch (DiscoveredWithErrorException e){
throw e;
}catch (Exception e) {
String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage();
s_logger.warn(msg);
} finally {
if (sshConnection != null)
sshConnection.close();
}
return null;
}
private HostVO waitForHostConnect(long dcId, long podId, long clusterId, String guid) {
for (int i = 0; i < _waitTime *2; i++) {
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, clusterId, podId, dcId);
for (HostVO host : hosts) {
if (host.getGuid().equalsIgnoreCase(guid)) {
return host;
}
}
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
s_logger.debug("Failed to sleep: " + e.toString());
}
}
s_logger.debug("Timeout, to wait for the host connecting to mgt svr, assuming it is failed");
List<HostVO> hosts = _resourceMgr.findHostByGuid(dcId, guid);
if (hosts.size() == 1) {
return hosts.get(0);
} else {
return null;
}
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_configDao = locator.getDao(ConfigurationDao.class);
_kvmPrivateNic = _configDao.getValue(Config.KvmPrivateNetwork.key());
if (_kvmPrivateNic == null) {
_kvmPrivateNic = "cloudbr0";
}
_kvmPublicNic = _configDao.getValue(Config.KvmPublicNetwork.key());
if (_kvmPublicNic == null) {
_kvmPublicNic = _kvmPrivateNic;
}
_kvmGuestNic = _configDao.getValue(Config.KvmGuestNetwork.key());
if (_kvmGuestNic == null) {
_kvmGuestNic = _kvmPrivateNic;
}
_hostIp = _configDao.getValue("host");
if (_hostIp == null) {
throw new ConfigurationException("Can't get host IP");
}
_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
return true;
}
protected String getPatchPath() {
// _setupAgentPath = Script.findScript(getPatchPath(), "setup_agent.sh");
_kvmPrivateNic = _configDao.getValue(Config.KvmPrivateNetwork.key());
if (_kvmPrivateNic == null) {
_kvmPrivateNic = "cloudbr0";
}
_kvmPublicNic = _configDao.getValue(Config.KvmPublicNetwork.key());
if (_kvmPublicNic == null) {
_kvmPublicNic = _kvmPrivateNic;
}
_kvmGuestNic = _configDao.getValue(Config.KvmGuestNetwork.key());
if (_kvmGuestNic == null) {
_kvmGuestNic = _kvmPrivateNic;
}
_hostIp = _configDao.getValue("host");
if (_hostIp == null) {
throw new ConfigurationException("Can't get host IP");
}
_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
return true;
}
protected String getPatchPath() {
return "scripts/vm/hypervisor/kvm/";
}
@Override
public void postDiscovery(List<HostVO> hosts, long msId)
throws DiscoveryException {
// TODO Auto-generated method stub
}
public Hypervisor.HypervisorType getHypervisorType() {
return Hypervisor.HypervisorType.KVM;
}
@Override
public boolean matchHypervisor(String hypervisor) {
// for backwards compatibility, if not supplied, always let to try it
if(hypervisor == null)
return true;
return Hypervisor.HypervisorType.KVM.toString().equalsIgnoreCase(hypervisor);
public void postDiscovery(List<HostVO> hosts, long msId)
throws DiscoveryException {
// TODO Auto-generated method stub
}
@Override
@Override
public Hypervisor.HypervisorType getHypervisorType() {
return Hypervisor.HypervisorType.KVM;
}
@Override
public boolean matchHypervisor(String hypervisor) {
// for backwards compatibility, if not supplied, always let to try it
if(hypervisor == null)
return true;
return Hypervisor.HypervisorType.KVM.toString().equalsIgnoreCase(hypervisor);
}
@Override
public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
StartupCommand firstCmd = cmd[0];
if (!(firstCmd instanceof StartupRoutingCommand)) {
return null;
}
StartupCommand firstCmd = cmd[0];
if (!(firstCmd instanceof StartupRoutingCommand)) {
return null;
}
StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
if (ssCmd.getHypervisorType() != HypervisorType.KVM) {
return null;
}
StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
if (ssCmd.getHypervisorType() != HypervisorType.KVM) {
return null;
}
/* KVM requires host are the same in cluster */
ClusterVO clusterVO = _clusterDao.findById(host.getClusterId());
List<HostVO> hostsInCluster = _resourceMgr.listAllHostsInCluster(clusterVO.getId());
if (!hostsInCluster.isEmpty()) {
HostVO oneHost = hostsInCluster.get(0);
_hostDao.loadDetails(oneHost);
String hostOsInCluster = oneHost.getDetail("Host.OS");
String hostOs = ssCmd.getHostDetails().get("Host.OS");
if (!hostOsInCluster.equalsIgnoreCase(hostOs)) {
throw new IllegalArgumentException("Can't add host: " + firstCmd.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster,"
+ "in which there are " + hostOsInCluster + " hosts added");
}
}
_hostDao.loadDetails(host);
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.KVM, host.getDetails(), null);
/* KVM requires host are the same in cluster */
ClusterVO clusterVO = _clusterDao.findById(host.getClusterId());
List<HostVO> hostsInCluster = _resourceMgr.listAllHostsInCluster(clusterVO.getId());
if (!hostsInCluster.isEmpty()) {
HostVO oneHost = hostsInCluster.get(0);
_hostDao.loadDetails(oneHost);
String hostOsInCluster = oneHost.getDetail("Host.OS");
String hostOs = ssCmd.getHostDetails().get("Host.OS");
if (!hostOsInCluster.equalsIgnoreCase(hostOs)) {
throw new IllegalArgumentException("Can't add host: " + firstCmd.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster,"
+ "in which there are " + hostOsInCluster + " hosts added");
}
}
_hostDao.loadDetails(host);
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.KVM, host.getDetails(), null);
}
@Override
@Override
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details,
List<String> hostTags) {
// TODO Auto-generated method stub
return null;
// TODO Auto-generated method stub
return null;
}
@Override
@Override
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
if (host.getType() != Host.Type.Routing || host.getHypervisorType() != HypervisorType.KVM) {
return null;
}
_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
try {
ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null);
@ -388,15 +385,15 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
} catch (OperationTimedoutException e) {
s_logger.warn("Sending ShutdownCommand failed: ", e);
}
return new DeleteHostAnswer(true);
}
@Override
public boolean stop() {
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
return super.stop();
}
}

View File

@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Properties;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.commons.httpclient.HttpClient;
@ -66,7 +67,8 @@ public class UpgradeManagerImpl implements UpgradeManager {
String _agentPath;
long _checkInterval;
AgentUpgradeDao _upgradeDao;
@Inject AgentUpgradeDao _upgradeDao;
@Inject ConfigurationDao _configDao;
@Override
public State registerForUpgrade(long hostId, String version) {
@ -151,18 +153,7 @@ public class UpgradeManagerImpl implements UpgradeManager {
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
final ComponentLocator locator = ComponentLocator.getCurrentLocator();
_upgradeDao = locator.getDao(AgentUpgradeDao.class);
if (_upgradeDao == null) {
throw new ConfigurationException("Unable to retrieve the storage layer.");
}
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
final Map<String, String> configs = configDao.getConfiguration("UpgradeManager", params);
final Map<String, String> configs = _configDao.getConfiguration("UpgradeManager", params);
File agentUpgradeFile = PropertiesUtil.findConfigFile("agent-update.properties");
Properties agentUpgradeProps = new Properties();

View File

@ -144,8 +144,6 @@ public class ExteralIpAddressAllocator implements IpAddrAllocator{
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_configDao = locator.getDao(ConfigurationDao.class);
_isExternalIpAllocatorEnabled = Boolean.parseBoolean(_configDao.getValue("direct.attach.network.externalIpAllocator.enabled"));
_externalIpAllocatorUrl = _configDao.getValue("direct.attach.network.externalIpAllocator.url");
_name = name;

View File

@ -57,6 +57,7 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
@Inject protected FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao;
@Inject ResourceTagsDaoImpl _tagsDao;
@Inject IPAddressDao _ipDao;
protected FirewallRulesDaoImpl() {
super();
@ -184,8 +185,6 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
@Override
public List<FirewallRuleVO> listStaticNatByVmId(long vmId) {
IPAddressDao _ipDao = ComponentLocator.getLocator("management-server").getDao(IPAddressDao.class);
if (VmSearch == null) {
SearchBuilder<IPAddressVO> IpSearch = _ipDao.createSearchBuilder();
IpSearch.and("associatedWithVmId", IpSearch.entity().getAssociatedWithVmId(), SearchCriteria.Op.EQ);

View File

@ -61,6 +61,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
private static final Logger s_logger = Logger.getLogger(ControlNetworkGuru.class);
@Inject DataCenterDao _dcDao;
@Inject NetworkManager _networkMgr;
@Inject ConfigurationDao _configDao;
String _cidr;
String _gateway;
@ -211,10 +212,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> dbParams = configDao.getConfiguration(params);
Map<String, String> dbParams = _configDao.getConfiguration(params);
_cidr = dbParams.get(Config.ControlCidr);
if (_cidr == null) {

View File

@ -591,8 +591,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
_checkExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterStatusMonitor"));
_networkStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("NetworkStatsUpdater"));
final ComponentLocator locator = ComponentLocator.getCurrentLocator();
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
_mgmt_host = configs.get("host");
@ -643,11 +641,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
s_logger.info("Router configurations: " + "ramsize=" + _routerRamSize);
final UserStatisticsDao statsDao = locator.getDao(UserStatisticsDao.class);
if (statsDao == null) {
throw new ConfigurationException("Unable to get " + UserStatisticsDao.class.getName());
}
_agentMgr.registerForHostEvents(new SshKeysDistriMonitor(_agentMgr, _hostDao, _configDao), true, false, false);
_itMgr.registerGuru(VirtualMachine.Type.DomainRouter, this);

View File

@ -162,6 +162,9 @@ public class SecurityGroupManagerImpl implements SecurityGroupManager, SecurityG
@Inject
ResourceTagDao _resourceTagDao;
@Inject
ManagementServer _msServer;
ScheduledExecutorService _executorPool;
ScheduledExecutorService _cleanupExecutor;
@ -861,8 +864,7 @@ public class SecurityGroupManagerImpl implements SecurityGroupManager, SecurityG
_answerListener = new SecurityGroupListener(this, _agentMgr, _workDao);
_agentMgr.registerForHostEvents(_answerListener, true, true, true);
_serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId();
_serverId = _msServer.getId();
s_logger.info("SecurityGroupManager: num worker threads=" + _numWorkerThreads +
", time between cleanups=" + _timeBetweenCleanups + " global lock timeout=" + _globalWorkLockTimeout);

View File

@ -207,9 +207,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
txn.commit();
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> configs = configDao.getConfiguration(params);
Map<String, String> configs = _configDao.getConfiguration(params);
String value = configs.get(Config.VpcCleanupInterval.key());
_cleanupInterval = NumbersUtil.parseInt(value, 60 * 60); // 1 hour

View File

@ -99,6 +99,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag
@Inject FirewallRulesDao _rulesDao;
@Inject FirewallManager _firewallMgr;
@Inject UsageEventDao _usageEventDao;
@Inject ConfigurationDao _configDao;
int _userLimit;
int _pskLength;
@ -585,9 +586,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> configs = configDao.getConfiguration(params);
Map<String, String> configs = _configDao.getConfiguration(params);
_userLimit = NumbersUtil.parseInt(configs.get(Config.RemoteAccessVpnUserLimit.key()), 8);

View File

@ -93,6 +93,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
@Inject VpcDao _vpcDao;
@Inject IPAddressDao _ipAddressDao;
@Inject AccountDao _accountDao;
@Inject ConfigurationDao _configDao;
@Inject VpcManager _vpcMgr;
@Inject AccountManager _accountMgr;
@ -104,9 +105,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> configs = configDao.getConfiguration(params);
Map<String, String> configs = _configDao.getConfiguration(params);
_connLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnConnectionPerVpnGatewayLimit.key()), 4);
_subnetsLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnSubnetsPerCustomerGatewayLimit.key()), 10);
return true;

View File

@ -48,8 +48,7 @@ public abstract class DiscovererBase implements Discoverer {
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
ConfigurationDao dao = ComponentLocator.getCurrentLocator().getDao(ConfigurationDao.class);
_params = dao.getConfiguration(params);
_params = _configDao.getConfiguration(params);
_name = name;
return true;

View File

@ -329,6 +329,8 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
protected ResourceTagDao _resourceTagDao;
@Inject
protected List<StoragePoolAllocator> _storagePoolAllocators;
@Inject ConfigurationDao _configDao;
@Inject ManagementServer _msServer;
// TODO : we don't have any instantiated pool discover, disable injection temporarily
// @Inject
@ -941,15 +943,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
s_logger.error("Unable to get the configuration dao.");
return false;
}
Map<String, String> configs = configDao.getConfiguration("management-server", params);
Map<String, String> configs = _configDao.getConfiguration("management-server", params);
String overProvisioningFactorStr = configs.get("storage.overprovisioning.factor");
if (overProvisioningFactorStr != null) {
@ -967,27 +961,27 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
String storageCleanupEnabled = configs.get("storage.cleanup.enabled");
_storageCleanupEnabled = (storageCleanupEnabled == null) ? true : Boolean.parseBoolean(storageCleanupEnabled);
String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
String value = _configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
_createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
value = configDao.getValue(Config.CopyVolumeWait.toString());
value = _configDao.getValue(Config.CopyVolumeWait.toString());
_copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
value = configDao.getValue(Config.RecreateSystemVmEnabled.key());
value = _configDao.getValue(Config.RecreateSystemVmEnabled.key());
_recreateSystemVmEnabled = Boolean.parseBoolean(value);
value = configDao.getValue(Config.StorageTemplateCleanupEnabled.key());
value = _configDao.getValue(Config.StorageTemplateCleanupEnabled.key());
_templateCleanupEnabled = (value == null ? true : Boolean.parseBoolean(value));
String time = configs.get("storage.cleanup.interval");
_storageCleanupInterval = NumbersUtil.parseInt(time, 86400);
String storageUsedThreshold = configDao.getValue(Config.StorageCapacityDisableThreshold.key());
String storageUsedThreshold = _configDao.getValue(Config.StorageCapacityDisableThreshold.key());
if (storageUsedThreshold != null) {
_storageUsedThreshold = Double.parseDouble(storageUsedThreshold);
}
String storageAllocatedThreshold = configDao.getValue(Config.StorageAllocatedCapacityDisableThreshold.key());
String storageAllocatedThreshold = _configDao.getValue(Config.StorageAllocatedCapacityDisableThreshold.key());
if (storageAllocatedThreshold != null) {
_storageAllocatedThreshold = Double.parseDouble(storageAllocatedThreshold);
}
@ -1003,13 +997,13 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
_agentMgr.registerForHostEvents(ComponentLocator.inject(LocalStoragePoolListener.class), true, false, false);
String maxVolumeSizeInGbString = configDao.getValue("storage.max.volume.size");
String maxVolumeSizeInGbString = _configDao.getValue("storage.max.volume.size");
_maxVolumeSizeInGb = NumbersUtil.parseLong(maxVolumeSizeInGbString, 2000);
String _customDiskOfferingMinSizeStr = configDao.getValue(Config.CustomDiskOfferingMinSize.toString());
String _customDiskOfferingMinSizeStr = _configDao.getValue(Config.CustomDiskOfferingMinSize.toString());
_customDiskOfferingMinSize = NumbersUtil.parseInt(_customDiskOfferingMinSizeStr, Integer.parseInt(Config.CustomDiskOfferingMinSize.getDefaultValue()));
String _customDiskOfferingMaxSizeStr = configDao.getValue(Config.CustomDiskOfferingMaxSize.toString());
String _customDiskOfferingMaxSizeStr = _configDao.getValue(Config.CustomDiskOfferingMaxSize.toString());
_customDiskOfferingMaxSize = NumbersUtil.parseInt(_customDiskOfferingMaxSizeStr, Integer.parseInt(Config.CustomDiskOfferingMaxSize.getDefaultValue()));
HostTemplateStatesSearch = _vmTemplateHostDao.createSearchBuilder();
@ -1023,7 +1017,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
HostSearch.done();
HostTemplateStatesSearch.done();
_serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId();
_serverId = _msServer.getId();
UpHostsInPoolSearch = _storagePoolHostDao.createSearchBuilder(Long.class);
UpHostsInPoolSearch.selectField(UpHostsInPoolSearch.entity().getHostId());

View File

@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
@ -42,8 +43,8 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl
StoragePoolAllocator _firstFitStoragePoolAllocator;
StoragePoolAllocator _localStoragePoolAllocator;
StorageManager _storageMgr;
ConfigurationDao _configDao;
@Inject StorageManager _storageMgr;
@Inject ConfigurationDao _configDao;
boolean _storagePoolCleanupEnabled;
@Override
@ -94,16 +95,6 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl
_localStoragePoolAllocator = ComponentLocator.inject(LocalStoragePoolAllocator.class);
_localStoragePoolAllocator.configure("GCLocalStoragePoolAllocator", params);
_storageMgr = locator.getManager(StorageManager.class);
if (_storageMgr == null) {
throw new ConfigurationException("Unable to get " + StorageManager.class.getName());
}
_configDao = locator.getDao(ConfigurationDao.class);
if (_configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
String storagePoolCleanupEnabled = _configDao.getValue("storage.pool.cleanup.enabled");
_storagePoolCleanupEnabled = (storagePoolCleanupEnabled == null) ? true : Boolean.parseBoolean(storagePoolCleanupEnabled);

View File

@ -793,27 +793,21 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
Map<String, String> configs = configDao.getConfiguration("management-server", params);
Map<String, String> configs = _configDao.getConfiguration("management-server", params);
_secStorageVmMtuSize = NumbersUtil.parseInt(configs.get("secstorage.vm.mtu.size"), DEFAULT_SS_VM_MTUSIZE);
String useServiceVM = configDao.getValue("secondary.storage.vm");
String useServiceVM = _configDao.getValue("secondary.storage.vm");
boolean _useServiceVM = false;
if ("true".equalsIgnoreCase(useServiceVM)) {
_useServiceVM = true;
}
String sslcopy = configDao.getValue("secstorage.encrypt.copy");
String sslcopy = _configDao.getValue("secstorage.encrypt.copy");
if ("true".equalsIgnoreCase(sslcopy)) {
_useSSlCopy = true;
}
_allowedInternalSites = configDao.getValue("secstorage.allowed.internal.sites");
_allowedInternalSites = _configDao.getValue("secstorage.allowed.internal.sites");
String value = configs.get("secstorage.capacityscan.interval");
_capacityScanInterval = NumbersUtil.parseLong(value, DEFAULT_CAPACITY_SCAN_INTERVAL);
@ -823,7 +817,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
_instance = "DEFAULT";
}
Map<String, String> agentMgrConfigs = configDao.getConfiguration("AgentManager", params);
Map<String, String> agentMgrConfigs = _configDao.getConfiguration("AgentManager", params);
_mgmt_host = agentMgrConfigs.get("host");
if (_mgmt_host == null) {
s_logger.warn("Critical warning! Please configure your management server host address right after you have started your management server and then restart it, otherwise you won't have access to secondary storage");

View File

@ -189,6 +189,8 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
private VolumeDao _volumeDao;
@Inject
private ResourceTagDao _resourceTagDao;
@Inject
private ConfigurationDao _configDao;
String _name;
private int _totalRetries;
@ -1432,23 +1434,16 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
throw new ConfigurationException("Unable to get the configuration dao.");
}
String value = configDao.getValue(Config.BackupSnapshotWait.toString());
String value = _configDao.getValue(Config.BackupSnapshotWait.toString());
_backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
Type.HOURLY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.hourly"), HOURLYMAX));
Type.DAILY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.daily"), DAILYMAX));
Type.WEEKLY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.weekly"), WEEKLYMAX));
Type.MONTHLY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.monthly"), MONTHLYMAX));
_deltaSnapshotMax = NumbersUtil.parseInt(configDao.getValue("snapshot.delta.max"), DELTAMAX);
_totalRetries = NumbersUtil.parseInt(configDao.getValue("total.retries"), 4);
_pauseInterval = 2 * NumbersUtil.parseInt(configDao.getValue("ping.interval"), 60);
Type.HOURLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.hourly"), HOURLYMAX));
Type.DAILY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.daily"), DAILYMAX));
Type.WEEKLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.weekly"), WEEKLYMAX));
Type.MONTHLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.monthly"), MONTHLYMAX));
_deltaSnapshotMax = NumbersUtil.parseInt(_configDao.getValue("snapshot.delta.max"), DELTAMAX);
_totalRetries = NumbersUtil.parseInt(_configDao.getValue("total.retries"), 4);
_pauseInterval = 2 * NumbersUtil.parseInt(_configDao.getValue("ping.interval"), 60);
s_logger.info("Snapshot Manager is configured.");

View File

@ -74,7 +74,8 @@ public class SnapshotSchedulerImpl implements SnapshotScheduler {
@Inject protected SnapshotPolicyDao _snapshotPolicyDao;
@Inject protected AsyncJobManager _asyncMgr;
@Inject protected VolumeDao _volsDao;
@Inject protected ConfigurationDao _configDao;
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 5; // 5 seconds
private int _snapshotPollInterval;
private Timer _testClockTimer;
@ -336,23 +337,16 @@ public class SnapshotSchedulerImpl implements SnapshotScheduler {
throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
s_logger.error("Unable to get the configuration dao. " + ConfigurationDao.class.getName());
return false;
}
_snapshotPollInterval = NumbersUtil.parseInt(configDao.getValue("snapshot.poll.interval"), 300);
boolean snapshotsRecurringTest = Boolean.parseBoolean(configDao.getValue("snapshot.recurring.test"));
_snapshotPollInterval = NumbersUtil.parseInt(_configDao.getValue("snapshot.poll.interval"), 300);
boolean snapshotsRecurringTest = Boolean.parseBoolean(_configDao.getValue("snapshot.recurring.test"));
if (snapshotsRecurringTest) {
// look for some test values in the configuration table so that snapshots can be taken more frequently (QA test code)
int minutesPerHour = NumbersUtil.parseInt(configDao.getValue("snapshot.test.minutes.per.hour"), 60);
int hoursPerDay = NumbersUtil.parseInt(configDao.getValue("snapshot.test.hours.per.day"), 24);
int daysPerWeek = NumbersUtil.parseInt(configDao.getValue("snapshot.test.days.per.week"), 7);
int daysPerMonth = NumbersUtil.parseInt(configDao.getValue("snapshot.test.days.per.month"), 30);
int weeksPerMonth = NumbersUtil.parseInt(configDao.getValue("snapshot.test.weeks.per.month"), 4);
int monthsPerYear = NumbersUtil.parseInt(configDao.getValue("snapshot.test.months.per.year"), 12);
int minutesPerHour = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.minutes.per.hour"), 60);
int hoursPerDay = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.hours.per.day"), 24);
int daysPerWeek = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.week"), 7);
int daysPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.month"), 30);
int weeksPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.weeks.per.month"), 4);
int monthsPerYear = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.months.per.year"), 12);
_testTimerTask = new TestClock(this, minutesPerHour, hoursPerDay, daysPerWeek, daysPerMonth, weeksPerMonth, monthsPerYear);
}

View File

@ -1066,8 +1066,6 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
_routerTemplateId = NumbersUtil.parseInt(configs.get("router.template.id"), 1);

View File

@ -248,9 +248,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
throw new ConfigurationException("Unable to find the system user using " + User.UID_SYSTEM);
}
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> configs = configDao.getConfiguration(params);
Map<String, String> configs = _configDao.getConfiguration(params);
String loginAttempts = configs.get(Config.IncorrectLoginAttemptsAllowed.key());
_allowedLoginAttempts = NumbersUtil.parseInt(loginAttempts, 5);

View File

@ -54,7 +54,6 @@ import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity;
import org.apache.cloudstack.engine.service.api.OrchestrationService;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
@ -237,7 +236,6 @@ import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.UserVmDetailsDao;
import com.cloud.vm.dao.VMInstanceDao;
@Component
@Local(value = { UserVmManager.class, UserVmService.class })
public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager {
private static final Logger s_logger = Logger
@ -4547,5 +4545,4 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
@Override
public void prepareStop(VirtualMachineProfile<UserVmVO> profile) {
}
}

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -141,8 +140,6 @@ import com.cloud.utils.Journal;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GlobalLock;
@ -239,6 +236,9 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
@Inject
protected ResourceManager _resourceMgr;
@Inject
protected ConfigurationDao _configDao;
Map<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>>();
protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine;
@ -428,9 +428,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
public boolean configure(String name, Map<String, Object> xmlParams) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> params = configDao.getConfiguration(xmlParams);
Map<String, String> params = _configDao.getConfiguration(xmlParams);
_retry = NumbersUtil.parseInt(params.get(Config.StartRetry.key()), 10);

View File

@ -284,7 +284,6 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
@Override
public List<UserVmVO> listByNetworkIdAndStates(long networkId, State... states) {
if (UserVmSearch == null) {
NicDao _nicDao = ComponentLocator.getLocator("management-server").getDao(NicDao.class);
SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder();
nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
nicSearch.and("ip4Address", nicSearch.entity().getIp4Address(), SearchCriteria.Op.NNULL);

View File

@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Properties;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.mail.Authenticator;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
@ -32,6 +33,7 @@ import javax.mail.internet.InternetAddress;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.alert.AlertManager;
import com.cloud.alert.AlertVO;
@ -43,26 +45,21 @@ import com.sun.mail.smtp.SMTPMessage;
import com.sun.mail.smtp.SMTPSSLTransport;
import com.sun.mail.smtp.SMTPTransport;
@Component
@Local(value={AlertManager.class})
public class UsageAlertManagerImpl implements AlertManager {
private static final Logger s_logger = Logger.getLogger(UsageAlertManagerImpl.class.getName());
private String _name = null;
private EmailAlert _emailAlert;
private AlertDao _alertDao;
@Inject private AlertDao _alertDao;
@Inject private ConfigurationDao _configDao;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
s_logger.error("Unable to get the configuration dao.");
return false;
}
Map<String, String> configs = configDao.getConfiguration("management-server", params);
Map<String, String> configs = _configDao.getConfiguration("management-server", params);
// set up the email system for alerts
String emailAddressList = configs.get("alert.email.addresses");
@ -85,14 +82,7 @@ public class UsageAlertManagerImpl implements AlertManager {
}
_emailAlert = new EmailAlert(emailAddresses, smtpHost, smtpPort, useAuth, smtpUsername, smtpPassword, emailSender, smtpDebug);
_alertDao = locator.getDao(AlertDao.class);
if (_alertDao == null) {
s_logger.error("Unable to get the alert dao.");
return false;
}
return true;
return true;
}
@Override

View File

@ -124,7 +124,7 @@ public class UsageManagerImpl implements UsageManager, Runnable {
private Future m_heartbeat = null;
private Future m_sanity = null;
protected UsageManagerImpl() {
public UsageManagerImpl() {
}
private void mergeConfigs(Map<String, String> dbParams, Map<String, Object> xmlParams) {

View File

@ -23,7 +23,6 @@ import org.apache.log4j.Logger;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
@ -85,9 +84,21 @@ public class ComponentContext implements ApplicationContextAware {
}
public static <T> boolean isPrimary(Object instance, Class<T> beanType) {
Map<String, T> matchedTypes = ComponentContext.getComponentsOfType(beanType);
// we assume single line of interface inheritance of beanType
Class<?> componentType = beanType;
Class<?> targetClass = getTargetClass(instance);
Class<?> interfaces[] = targetClass.getInterfaces();
for(Class<?> intf : interfaces) {
if(beanType.isAssignableFrom(intf)) {
componentType = intf;
break;
}
}
Map<String, T> matchedTypes = (Map<String, T>)ComponentContext.getComponentsOfType(componentType);
if(matchedTypes.size() > 1) {
Primary primary = getTargetClass(instance).getAnnotation(Primary.class);
Primary primary = targetClass.getAnnotation(Primary.class);
if(primary != null)
return true;
@ -96,7 +107,7 @@ public class ComponentContext implements ApplicationContextAware {
return true;
}
public static Class<?> getTargetClass(Object instance) {
if(instance instanceof Advised) {
try {

View File

@ -24,7 +24,6 @@ import com.cloud.utils.db.GenericDao;
@Component
public class ComponentLocator {
public static ComponentLocator getCurrentLocator() {
return ComponentContext.getCompanent(ComponentLocator.class);
}