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 { public class UserContext {
private static ThreadLocal<UserContext> s_currentContext = new ThreadLocal<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 long userId;
private String sessionId; private String sessionId;
private Account account; private Account account;
@ -34,8 +32,6 @@ public class UserContext {
private boolean apiServer; private boolean apiServer;
private static UserContext s_adminContext = new UserContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false);
public UserContext() { public UserContext() {
} }
@ -86,10 +82,10 @@ public class UserContext {
// however, there are many places that run background jobs assume the system context. // 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 // 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. // the core async-job manager that runs commands from user) have explicitly setup the UserContext.
// //
return s_adminContext; return UserContextInitializer.getInstance().getAdminContext();
} }
return context; 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="eventBus" class = "org.apache.cloudstack.framework.eventbus.EventBusBase" />
<bean id="userVmManager" class ="com.cloud.vm.UserVmManagerImpl" />
</beans> </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.List;
import java.util.Map; import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO; import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.deploy.DeploymentPlanner.ExcludeList;
public class VirtualMachineEntityImpl implements VirtualMachineEntity { public class VirtualMachineEntityImpl implements VirtualMachineEntity {
private VMEntityManager manager; @Inject private VMEntityManager manager;
private VMEntityVO vmEntityVO; 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.VMEntityManager;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.service.api.OrchestrationService; import org.apache.cloudstack.engine.service.api.OrchestrationService;
import org.springframework.stereotype.Component;
import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientCapacityException;
@ -49,7 +50,7 @@ import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.VMInstanceDao; import com.cloud.vm.dao.VMInstanceDao;
@Component
public class CloudOrchestrator implements OrchestrationService { public class CloudOrchestrator implements OrchestrationService {
@Inject @Inject

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -44,8 +45,8 @@ import com.cloud.vm.VirtualMachineProfile;
public class RandomAllocator implements HostAllocator { public class RandomAllocator implements HostAllocator {
private static final Logger s_logger = Logger.getLogger(RandomAllocator.class); private static final Logger s_logger = Logger.getLogger(RandomAllocator.class);
private String _name; private String _name;
private HostDao _hostDao; @Inject private HostDao _hostDao;
private ResourceManager _resourceMgr; @Inject private ResourceManager _resourceMgr;
@Override @Override
public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type, public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type,
@ -119,13 +120,6 @@ public class RandomAllocator implements HostAllocator {
@Override @Override
public boolean configure(String name, Map<String, Object> params) { 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; _name=name;
return true; return true;

View File

@ -348,13 +348,6 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
super.configure(name, params); 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(); createVmwareToolsIso();
if (s_logger.isInfoEnabled()) { if (s_logger.isInfoEnabled()) {

View File

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

View File

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

View File

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

View File

@ -21,6 +21,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.Map; import java.util.Map;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -38,7 +39,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
public class PlainTextUserAuthenticator extends DefaultUserAuthenticator { public class PlainTextUserAuthenticator extends DefaultUserAuthenticator {
public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class); public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class);
private UserAccountDao _userAccountDao; @Inject private UserAccountDao _userAccountDao;
@Override @Override
public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) { 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) public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException { throws ConfigurationException {
super.configure(name, params); super.configure(name, params);
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
_userAccountDao = locator.getDao(UserAccountDao.class);
return true; 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 { public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_name = name; _name = name;
final ComponentLocator locator = ComponentLocator.getCurrentLocator(); final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
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);
_port = NumbersUtil.parseInt(configs.get("port"), 8250); _port = NumbersUtil.parseInt(configs.get("port"), 8250);
final int workers = NumbersUtil.parseInt(configs.get("workers"), 5); final int workers = NumbersUtil.parseInt(configs.get("workers"), 5);

View File

@ -122,6 +122,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
@Inject @Inject
protected AgentManager _agentMgr; protected AgentManager _agentMgr;
@Inject ConfigurationDao _configDao;
protected ClusteredAgentManagerImpl() { protected ClusteredAgentManagerImpl() {
super(); super();
@ -135,8 +136,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
s_logger.info("Configuring ClusterAgentManagerImpl. management server node id(msid): " + _nodeId); 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()); String value = params.get(Config.DirectAgentLoadSize.key());
_loadSize = NumbersUtil.parseInt(value, 16); _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.HostVO;
import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao; 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.offering.ServiceOffering;
import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceManager;
import com.cloud.service.dao.ServiceOfferingDao; 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.storage.dao.GuestOSDao;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.ConsoleProxyDao;
@ -396,7 +393,6 @@ public class FirstFitAllocator implements HostAllocator {
@Override @Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
if (_configDao != null) { if (_configDao != null) {
Map<String, String> configs = _configDao.getConfiguration(params); Map<String, String> configs = _configDao.getConfiguration(params);
String opFactor = configs.get("cpu.overprovisioning.factor"); String opFactor = configs.get("cpu.overprovisioning.factor");

View File

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

View File

@ -106,7 +106,6 @@ public class AlertManagerImpl implements AlertManager {
@Inject private ConfigurationDao _configDao; @Inject private ConfigurationDao _configDao;
@Inject private ResourceManager _resourceMgr; @Inject private ResourceManager _resourceMgr;
@Inject private ConfigurationManager _configMgr; @Inject private ConfigurationManager _configMgr;
private Timer _timer = null; private Timer _timer = null;
private float _cpuOverProvisioningFactor = 1; private float _cpuOverProvisioningFactor = 1;
private long _capacityCheckPeriod = 60L * 60L * 1000L; // one hour by default 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 { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> configs = _configDao.getConfiguration("management-server", params);
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);
// set up the email system for alerts // set up the email system for alerts
String emailAddressList = configs.get("alert.email.addresses"); String emailAddressList = configs.get("alert.email.addresses");

View File

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

View File

@ -19,6 +19,7 @@ package com.cloud.alert;
import java.util.Map; import java.util.Map;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; 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 static final Logger s_logger = Logger.getLogger(ConsoleProxyAlertAdapter.class);
private AlertManager _alertMgr; @Inject private AlertManager _alertMgr;
private String _name; private String _name;
private DataCenterDao _dcDao; @Inject private DataCenterDao _dcDao;
private ConsoleProxyDao _consoleProxyDao; @Inject private ConsoleProxyDao _consoleProxyDao;
public void onProxyAlert(Object sender, ConsoleProxyAlertEventArgs args) { public void onProxyAlert(Object sender, ConsoleProxyAlertEventArgs args) {
if(s_logger.isDebugEnabled()) if(s_logger.isDebugEnabled())
@ -187,23 +188,6 @@ public class ConsoleProxyAlertAdapter implements AlertAdapter {
if (s_logger.isInfoEnabled()) if (s_logger.isInfoEnabled())
s_logger.info("Start configuring console proxy alert manager : " + name); 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 { try {
SubscriptionMgr.getInstance().subscribe(ConsoleProxyManager.ALERT_SUBJECT, this, "onProxyAlert"); SubscriptionMgr.getInstance().subscribe(ConsoleProxyManager.ALERT_SUBJECT, this, "onProxyAlert");
} catch (SecurityException e) { } catch (SecurityException e) {

View File

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

View File

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

View File

@ -32,6 +32,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd; import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
@ -87,12 +88,13 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
private String _name; private String _name;
private AsyncJobExecutorContext _context; @Inject private AsyncJobExecutorContext _context;
private SyncQueueManager _queueMgr; @Inject private SyncQueueManager _queueMgr;
private ClusterManager _clusterMgr; @Inject private ClusterManager _clusterMgr;
private AccountManager _accountMgr; @Inject private AccountManager _accountMgr;
private AccountDao _accountDao; @Inject private AccountDao _accountDao;
private AsyncJobDao _jobDao; @Inject private AsyncJobDao _jobDao;
@Inject private ConfigurationDao _configDao;
private long _jobExpireSeconds = 86400; // 1 day private long _jobExpireSeconds = 86400; // 1 day
private long _jobCancelThresholdSeconds = 3600; // 1 hour (for cancelling the jobs blocking other jobs) 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 { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _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( int expireMinutes = NumbersUtil.parseInt(
configDao.getValue(Config.JobExpireMinutes.key()), 24*60); _configDao.getValue(Config.JobExpireMinutes.key()), 24*60);
_jobExpireSeconds = (long)expireMinutes*60; _jobExpireSeconds = (long)expireMinutes*60;
_jobCancelThresholdSeconds = NumbersUtil.parseInt( _jobCancelThresholdSeconds = NumbersUtil.parseInt(
configDao.getValue(Config.JobCancelThresholdMinutes.key()), 60); _configDao.getValue(Config.JobCancelThresholdMinutes.key()), 60);
_jobCancelThresholdSeconds *= 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(); _dispatcher = ApiDispatcher.getInstance();

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -42,8 +43,8 @@ public class SyncQueueManagerImpl implements SyncQueueManager {
private String _name; private String _name;
private SyncQueueDao _syncQueueDao; @Inject private SyncQueueDao _syncQueueDao;
private SyncQueueItemDao _syncQueueItemDao; @Inject private SyncQueueItemDao _syncQueueItemDao;
@Override @Override
@DB @DB
@ -243,20 +244,6 @@ public class SyncQueueManagerImpl implements SyncQueueManager {
@Override @Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _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; return true;
} }

View File

@ -23,7 +23,6 @@ import javax.ejb.Local;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.IAgentControl; import com.cloud.agent.IAgentControl;
import com.cloud.agent.api.Answer; 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;
import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachine.State;
@Component
@Local(value = ServerResource.class) @Local(value = ServerResource.class)
public class BareMetalResourceBase implements ServerResource { public class BareMetalResourceBase implements ServerResource {
private static final Logger s_logger = Logger.getLogger(BareMetalResourceBase.class); 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.AttachVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd; import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
import org.apache.log4j.Logger; 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.Answer;
import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.StopAnswer;
@ -84,7 +82,6 @@ import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.component.Adapters; import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager; import com.cloud.utils.component.Manager;
import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB; 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;
import com.cloud.vm.VirtualMachineProfile.Param; import com.cloud.vm.VirtualMachineProfile.Param;
@Component
@Primary
@Local(value={BareMetalVmManager.class, BareMetalVmService.class}) @Local(value={BareMetalVmManager.class, BareMetalVmService.class})
public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMetalVmManager, BareMetalVmService, Manager, public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMetalVmManager, BareMetalVmService, Manager,
StateListener<State, VirtualMachine.Event, VirtualMachine> { StateListener<State, VirtualMachine.Event, VirtualMachine> {
private static final Logger s_logger = Logger.getLogger(BareMetalVmManagerImpl.class); private static final Logger s_logger = Logger.getLogger(BareMetalVmManagerImpl.class);
private ConfigurationDao _configDao; @Inject ConfigurationDao _configDao;
@Inject PxeServerManager _pxeMgr; @Inject PxeServerManager _pxeMgr;
@Inject ResourceManager _resourceMgr; @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 { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _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); Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
_instance = configs.get("instance.name"); _instance = configs.get("instance.name");

View File

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

View File

@ -127,10 +127,11 @@ public class ClusterManagerImpl implements ClusterManager {
@Inject @Inject
private List<ClusterServiceAdapter> _serviceAdapters; private List<ClusterServiceAdapter> _serviceAdapters;
private ManagementServerHostDao _mshostDao; @Inject private ManagementServerHostDao _mshostDao;
private ManagementServerHostPeerDao _mshostPeerDao; @Inject private ManagementServerHostPeerDao _mshostPeerDao;
private HostDao _hostDao; @Inject private HostDao _hostDao;
private HostTransferMapDao _hostTransferDao; @Inject private HostTransferMapDao _hostTransferDao;
@Inject private ConfigurationDao _configDao;
// //
// pay attention to _mshostId and _msid // pay attention to _mshostId and _msid
@ -1257,38 +1258,7 @@ public class ClusterManagerImpl implements ClusterManager {
} }
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> configs = _configDao.getConfiguration("management-server", params);
_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);
String value = configs.get("cluster.heartbeat.interval"); String value = configs.get("cluster.heartbeat.interval");
if (value != null) { if (value != null) {
@ -1338,7 +1308,7 @@ public class ClusterManagerImpl implements ClusterManager {
throw new ConfigurationException("Unable to set current cluster service adapter"); 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"); String connectedAgentsThreshold = configs.get("agent.load.threshold");

View File

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -35,7 +36,6 @@ import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.PropertiesUtil; import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.ComponentLocator;
@Component @Component
@Local(value={ClusterServiceAdapter.class}) @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_SERVICE_PORT = 9090;
private static final int DEFAULT_REQUEST_TIMEOUT = 300; // 300 seconds 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; private ClusterServiceServletContainer _servletContainer;
@ -134,23 +134,6 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter {
if(_mshostDao != null) if(_mshostDao != null)
return; 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()); String value = _configDao.getValue(Config.ClusterMessageTimeOutSeconds.key());
_clusterRequestTimeoutSeconds = NumbersUtil.parseInt(value, DEFAULT_REQUEST_TIMEOUT); _clusterRequestTimeoutSeconds = NumbersUtil.parseInt(value, DEFAULT_REQUEST_TIMEOUT);
s_logger.info("Configure cluster request time out. timeout: " + _clusterRequestTimeoutSeconds + " seconds"); 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.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.cloud.agent.Listener;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command; import com.cloud.agent.api.Command;
import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.AgentUnavailableException;

View File

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

View File

@ -81,14 +81,6 @@ public class ConsoleProxyBalanceAllocator implements ConsoleProxyAllocator {
@Override @Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _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; return true;
} }

View File

@ -1452,13 +1452,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> configs = _configDao.getConfiguration("management-server", params);
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);
String value = configs.get(Config.ConsoleProxyCmdPort.key()); String value = configs.get(Config.ConsoleProxyCmdPort.key());
value = configs.get("consoleproxy.sslEnabled"); value = configs.get("consoleproxy.sslEnabled");
@ -1505,7 +1499,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
prepareDefaultCertificate(); prepareDefaultCertificate();
Map<String, String> agentMgrConfigs = configDao.getConfiguration("AgentManager", params); Map<String, String> agentMgrConfigs = _configDao.getConfiguration("AgentManager", params);
_mgmt_host = agentMgrConfigs.get("host"); _mgmt_host = agentMgrConfigs.get("host");
if (_mgmt_host == null) { 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"); 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; String _ip = null;
@Inject ConsoleProxyDao _proxyDao; @Inject ConsoleProxyDao _proxyDao;
@Inject ResourceManager _resourceMgr; @Inject ResourceManager _resourceMgr;
@Inject ConfigurationDao _configDao;
@Override @Override
protected HostVO findHost(VMInstanceVO vm) { 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 { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params); super.configure(name, params);
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> dbParams = _configDao.getConfiguration("ManagementServer", params);
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> dbParams = configDao.getConfiguration("ManagementServer", params);
_ip = dbParams.get("public.ip"); _ip = dbParams.get("public.ip");
if (_ip == null) { 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.GenericSearchBuilder;
import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria2;
@Component @Component
@Local(value=EntityManager.class) @Local(value=EntityManager.class)

View File

@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.springframework.stereotype.Component; 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> NetworkVlanSearch;
protected SearchBuilder<VlanVO> PhysicalNetworkVlanSearch; protected SearchBuilder<VlanVO> PhysicalNetworkVlanSearch;
protected PodVlanMapDaoImpl _podVlanMapDao = new PodVlanMapDaoImpl(); @Inject protected PodVlanMapDao _podVlanMapDao;
protected AccountVlanMapDao _accountVlanMapDao = new AccountVlanMapDaoImpl(); @Inject protected AccountVlanMapDao _accountVlanMapDao;
protected IPAddressDao _ipAddressDao = null; @Inject protected IPAddressDao _ipAddressDao;
@Override @Override
public VlanVO findByZoneAndVlanId(long zoneId, String vlanId) { 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) public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException { throws ConfigurationException {
boolean result = super.configure(name, params); 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 = createSearchBuilder();
ZoneTypeAllPodsSearch.and("zoneId", ZoneTypeAllPodsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); ZoneTypeAllPodsSearch.and("zoneId", ZoneTypeAllPodsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
ZoneTypeAllPodsSearch.and("vlanType", ZoneTypeAllPodsSearch.entity().getVlanType(), SearchCriteria.Op.EQ); ZoneTypeAllPodsSearch.and("vlanType", ZoneTypeAllPodsSearch.entity().getVlanType(), SearchCriteria.Op.EQ);

View File

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

View File

@ -41,21 +41,12 @@ public class HighAvailabilityManagerExtImpl extends HighAvailabilityManagerImpl
@Inject @Inject
UsageJobDao _usageJobDao; UsageJobDao _usageJobDao;
ConfigurationDao configDao;
@Inject ConfigurationDao configDao;
@Override @Override
public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException { public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException {
super.configure(name, xmlParams); 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; return true;
} }

View File

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

View File

@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpClient;
@ -66,7 +67,8 @@ public class UpgradeManagerImpl implements UpgradeManager {
String _agentPath; String _agentPath;
long _checkInterval; long _checkInterval;
AgentUpgradeDao _upgradeDao; @Inject AgentUpgradeDao _upgradeDao;
@Inject ConfigurationDao _configDao;
@Override @Override
public State registerForUpgrade(long hostId, String version) { 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 { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _name = name;
final ComponentLocator locator = ComponentLocator.getCurrentLocator(); final Map<String, String> configs = _configDao.getConfiguration("UpgradeManager", params);
_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);
File agentUpgradeFile = PropertiesUtil.findConfigFile("agent-update.properties"); File agentUpgradeFile = PropertiesUtil.findConfigFile("agent-update.properties");
Properties agentUpgradeProps = new Properties(); Properties agentUpgradeProps = new Properties();

View File

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

View File

@ -57,6 +57,7 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
@Inject protected FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao; @Inject protected FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao;
@Inject ResourceTagsDaoImpl _tagsDao; @Inject ResourceTagsDaoImpl _tagsDao;
@Inject IPAddressDao _ipDao;
protected FirewallRulesDaoImpl() { protected FirewallRulesDaoImpl() {
super(); super();
@ -184,8 +185,6 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
@Override @Override
public List<FirewallRuleVO> listStaticNatByVmId(long vmId) { public List<FirewallRuleVO> listStaticNatByVmId(long vmId) {
IPAddressDao _ipDao = ComponentLocator.getLocator("management-server").getDao(IPAddressDao.class);
if (VmSearch == null) { if (VmSearch == null) {
SearchBuilder<IPAddressVO> IpSearch = _ipDao.createSearchBuilder(); SearchBuilder<IPAddressVO> IpSearch = _ipDao.createSearchBuilder();
IpSearch.and("associatedWithVmId", IpSearch.entity().getAssociatedWithVmId(), SearchCriteria.Op.EQ); 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); private static final Logger s_logger = Logger.getLogger(ControlNetworkGuru.class);
@Inject DataCenterDao _dcDao; @Inject DataCenterDao _dcDao;
@Inject NetworkManager _networkMgr; @Inject NetworkManager _networkMgr;
@Inject ConfigurationDao _configDao;
String _cidr; String _cidr;
String _gateway; String _gateway;
@ -211,10 +212,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params); super.configure(name, params);
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> dbParams = _configDao.getConfiguration(params);
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> dbParams = configDao.getConfiguration(params);
_cidr = dbParams.get(Config.ControlCidr); _cidr = dbParams.get(Config.ControlCidr);
if (_cidr == null) { if (_cidr == null) {

View File

@ -591,8 +591,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
_checkExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterStatusMonitor")); _checkExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterStatusMonitor"));
_networkStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("NetworkStatsUpdater")); _networkStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("NetworkStatsUpdater"));
final ComponentLocator locator = ComponentLocator.getCurrentLocator();
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params); final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
_mgmt_host = configs.get("host"); _mgmt_host = configs.get("host");
@ -643,11 +641,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
s_logger.info("Router configurations: " + "ramsize=" + _routerRamSize); 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); _agentMgr.registerForHostEvents(new SshKeysDistriMonitor(_agentMgr, _hostDao, _configDao), true, false, false);
_itMgr.registerGuru(VirtualMachine.Type.DomainRouter, this); _itMgr.registerGuru(VirtualMachine.Type.DomainRouter, this);

View File

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

View File

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

View File

@ -99,6 +99,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag
@Inject FirewallRulesDao _rulesDao; @Inject FirewallRulesDao _rulesDao;
@Inject FirewallManager _firewallMgr; @Inject FirewallManager _firewallMgr;
@Inject UsageEventDao _usageEventDao; @Inject UsageEventDao _usageEventDao;
@Inject ConfigurationDao _configDao;
int _userLimit; int _userLimit;
int _pskLength; int _pskLength;
@ -585,9 +586,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> configs = _configDao.getConfiguration(params);
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> configs = configDao.getConfiguration(params);
_userLimit = NumbersUtil.parseInt(configs.get(Config.RemoteAccessVpnUserLimit.key()), 8); _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 VpcDao _vpcDao;
@Inject IPAddressDao _ipAddressDao; @Inject IPAddressDao _ipAddressDao;
@Inject AccountDao _accountDao; @Inject AccountDao _accountDao;
@Inject ConfigurationDao _configDao;
@Inject VpcManager _vpcMgr; @Inject VpcManager _vpcMgr;
@Inject AccountManager _accountMgr; @Inject AccountManager _accountMgr;
@ -104,9 +105,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> configs = _configDao.getConfiguration(params);
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> configs = configDao.getConfiguration(params);
_connLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnConnectionPerVpnGatewayLimit.key()), 4); _connLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnConnectionPerVpnGatewayLimit.key()), 4);
_subnetsLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnSubnetsPerCustomerGatewayLimit.key()), 10); _subnetsLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnSubnetsPerCustomerGatewayLimit.key()), 10);
return true; return true;

View File

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

View File

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

View File

@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -42,8 +43,8 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl
StoragePoolAllocator _firstFitStoragePoolAllocator; StoragePoolAllocator _firstFitStoragePoolAllocator;
StoragePoolAllocator _localStoragePoolAllocator; StoragePoolAllocator _localStoragePoolAllocator;
StorageManager _storageMgr; @Inject StorageManager _storageMgr;
ConfigurationDao _configDao; @Inject ConfigurationDao _configDao;
boolean _storagePoolCleanupEnabled; boolean _storagePoolCleanupEnabled;
@Override @Override
@ -94,16 +95,6 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl
_localStoragePoolAllocator = ComponentLocator.inject(LocalStoragePoolAllocator.class); _localStoragePoolAllocator = ComponentLocator.inject(LocalStoragePoolAllocator.class);
_localStoragePoolAllocator.configure("GCLocalStoragePoolAllocator", params); _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"); String storagePoolCleanupEnabled = _configDao.getValue("storage.pool.cleanup.enabled");
_storagePoolCleanupEnabled = (storagePoolCleanupEnabled == null) ? true : Boolean.parseBoolean(storagePoolCleanupEnabled); _storagePoolCleanupEnabled = (storagePoolCleanupEnabled == null) ? true : Boolean.parseBoolean(storagePoolCleanupEnabled);

View File

@ -793,27 +793,21 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> configs = _configDao.getConfiguration("management-server", params);
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);
_secStorageVmMtuSize = NumbersUtil.parseInt(configs.get("secstorage.vm.mtu.size"), DEFAULT_SS_VM_MTUSIZE); _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; boolean _useServiceVM = false;
if ("true".equalsIgnoreCase(useServiceVM)) { if ("true".equalsIgnoreCase(useServiceVM)) {
_useServiceVM = true; _useServiceVM = true;
} }
String sslcopy = configDao.getValue("secstorage.encrypt.copy"); String sslcopy = _configDao.getValue("secstorage.encrypt.copy");
if ("true".equalsIgnoreCase(sslcopy)) { if ("true".equalsIgnoreCase(sslcopy)) {
_useSSlCopy = true; _useSSlCopy = true;
} }
_allowedInternalSites = configDao.getValue("secstorage.allowed.internal.sites"); _allowedInternalSites = _configDao.getValue("secstorage.allowed.internal.sites");
String value = configs.get("secstorage.capacityscan.interval"); String value = configs.get("secstorage.capacityscan.interval");
_capacityScanInterval = NumbersUtil.parseLong(value, DEFAULT_CAPACITY_SCAN_INTERVAL); _capacityScanInterval = NumbersUtil.parseLong(value, DEFAULT_CAPACITY_SCAN_INTERVAL);
@ -823,7 +817,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
_instance = "DEFAULT"; _instance = "DEFAULT";
} }
Map<String, String> agentMgrConfigs = configDao.getConfiguration("AgentManager", params); Map<String, String> agentMgrConfigs = _configDao.getConfiguration("AgentManager", params);
_mgmt_host = agentMgrConfigs.get("host"); _mgmt_host = agentMgrConfigs.get("host");
if (_mgmt_host == null) { 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"); 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; private VolumeDao _volumeDao;
@Inject @Inject
private ResourceTagDao _resourceTagDao; private ResourceTagDao _resourceTagDao;
@Inject
private ConfigurationDao _configDao;
String _name; String _name;
private int _totalRetries; 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 { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator(); String value = _configDao.getValue(Config.BackupSnapshotWait.toString());
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());
_backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue())); _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
Type.HOURLY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.hourly"), HOURLYMAX)); Type.HOURLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.hourly"), HOURLYMAX));
Type.DAILY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.daily"), DAILYMAX)); Type.DAILY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.daily"), DAILYMAX));
Type.WEEKLY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.weekly"), WEEKLYMAX)); Type.WEEKLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.weekly"), WEEKLYMAX));
Type.MONTHLY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.monthly"), MONTHLYMAX)); Type.MONTHLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.monthly"), MONTHLYMAX));
_deltaSnapshotMax = NumbersUtil.parseInt(configDao.getValue("snapshot.delta.max"), DELTAMAX); _deltaSnapshotMax = NumbersUtil.parseInt(_configDao.getValue("snapshot.delta.max"), DELTAMAX);
_totalRetries = NumbersUtil.parseInt(configDao.getValue("total.retries"), 4); _totalRetries = NumbersUtil.parseInt(_configDao.getValue("total.retries"), 4);
_pauseInterval = 2 * NumbersUtil.parseInt(configDao.getValue("ping.interval"), 60); _pauseInterval = 2 * NumbersUtil.parseInt(_configDao.getValue("ping.interval"), 60);
s_logger.info("Snapshot Manager is configured."); s_logger.info("Snapshot Manager is configured.");

View File

@ -74,7 +74,8 @@ public class SnapshotSchedulerImpl implements SnapshotScheduler {
@Inject protected SnapshotPolicyDao _snapshotPolicyDao; @Inject protected SnapshotPolicyDao _snapshotPolicyDao;
@Inject protected AsyncJobManager _asyncMgr; @Inject protected AsyncJobManager _asyncMgr;
@Inject protected VolumeDao _volsDao; @Inject protected VolumeDao _volsDao;
@Inject protected ConfigurationDao _configDao;
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 5; // 5 seconds private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 5; // 5 seconds
private int _snapshotPollInterval; private int _snapshotPollInterval;
private Timer _testClockTimer; private Timer _testClockTimer;
@ -336,23 +337,16 @@ public class SnapshotSchedulerImpl implements SnapshotScheduler {
throws ConfigurationException { throws ConfigurationException {
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator(); _snapshotPollInterval = NumbersUtil.parseInt(_configDao.getValue("snapshot.poll.interval"), 300);
boolean snapshotsRecurringTest = Boolean.parseBoolean(_configDao.getValue("snapshot.recurring.test"));
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"));
if (snapshotsRecurringTest) { if (snapshotsRecurringTest) {
// look for some test values in the configuration table so that snapshots can be taken more frequently (QA test code) // 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 minutesPerHour = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.minutes.per.hour"), 60);
int hoursPerDay = NumbersUtil.parseInt(configDao.getValue("snapshot.test.hours.per.day"), 24); 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 daysPerWeek = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.week"), 7);
int daysPerMonth = NumbersUtil.parseInt(configDao.getValue("snapshot.test.days.per.month"), 30); 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 weeksPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.weeks.per.month"), 4);
int monthsPerYear = NumbersUtil.parseInt(configDao.getValue("snapshot.test.months.per.year"), 12); int monthsPerYear = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.months.per.year"), 12);
_testTimerTask = new TestClock(this, minutesPerHour, hoursPerDay, daysPerWeek, daysPerMonth, weeksPerMonth, monthsPerYear); _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 { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params); final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
_routerTemplateId = NumbersUtil.parseInt(configs.get("router.template.id"), 1); _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); throw new ConfigurationException("Unable to find the system user using " + User.UID_SYSTEM);
} }
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> configs = _configDao.getConfiguration(params);
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> configs = configDao.getConfiguration(params);
String loginAttempts = configs.get(Config.IncorrectLoginAttemptsAllowed.key()); String loginAttempts = configs.get(Config.IncorrectLoginAttemptsAllowed.key());
_allowedLoginAttempts = NumbersUtil.parseInt(loginAttempts, 5); _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.cloudstack.engine.service.api.OrchestrationService;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager; import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer; 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.UserVmDetailsDao;
import com.cloud.vm.dao.VMInstanceDao; import com.cloud.vm.dao.VMInstanceDao;
@Component
@Local(value = { UserVmManager.class, UserVmService.class }) @Local(value = { UserVmManager.class, UserVmService.class })
public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager { public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager {
private static final Logger s_logger = Logger private static final Logger s_logger = Logger
@ -4547,5 +4545,4 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
@Override @Override
public void prepareStop(VirtualMachineProfile<UserVmVO> profile) { public void prepareStop(VirtualMachineProfile<UserVmVO> profile) {
} }
} }

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -141,8 +140,6 @@ import com.cloud.utils.Journal;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.Ternary; 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.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.GlobalLock;
@ -239,6 +236,9 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
@Inject @Inject
protected ResourceManager _resourceMgr; protected ResourceManager _resourceMgr;
@Inject
protected ConfigurationDao _configDao;
Map<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>>(); Map<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>>();
protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine; 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 { public boolean configure(String name, Map<String, Object> xmlParams) throws ConfigurationException {
_name = name; _name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator(); Map<String, String> params = _configDao.getConfiguration(xmlParams);
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> params = configDao.getConfiguration(xmlParams);
_retry = NumbersUtil.parseInt(params.get(Config.StartRetry.key()), 10); _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 @Override
public List<UserVmVO> listByNetworkIdAndStates(long networkId, State... states) { public List<UserVmVO> listByNetworkIdAndStates(long networkId, State... states) {
if (UserVmSearch == null) { if (UserVmSearch == null) {
NicDao _nicDao = ComponentLocator.getLocator("management-server").getDao(NicDao.class);
SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder(); SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder();
nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
nicSearch.and("ip4Address", nicSearch.entity().getIp4Address(), SearchCriteria.Op.NNULL); nicSearch.and("ip4Address", nicSearch.entity().getIp4Address(), SearchCriteria.Op.NNULL);

View File

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

View File

@ -124,7 +124,7 @@ public class UsageManagerImpl implements UsageManager, Runnable {
private Future m_heartbeat = null; private Future m_heartbeat = null;
private Future m_sanity = null; private Future m_sanity = null;
protected UsageManagerImpl() { public UsageManagerImpl() {
} }
private void mergeConfigs(Map<String, String> dbParams, Map<String, Object> xmlParams) { 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.Advisor;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; 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) { 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) { if(matchedTypes.size() > 1) {
Primary primary = getTargetClass(instance).getAnnotation(Primary.class); Primary primary = targetClass.getAnnotation(Primary.class);
if(primary != null) if(primary != null)
return true; return true;
@ -96,7 +107,7 @@ public class ComponentContext implements ApplicationContextAware {
return true; return true;
} }
public static Class<?> getTargetClass(Object instance) { public static Class<?> getTargetClass(Object instance) {
if(instance instanceof Advised) { if(instance instanceof Advised) {
try { try {

View File

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