diff --git a/api/src/com/cloud/user/UserContext.java b/api/src/com/cloud/user/UserContext.java index b140728e596..786590eed09 100644 --- a/api/src/com/cloud/user/UserContext.java +++ b/api/src/com/cloud/user/UserContext.java @@ -22,9 +22,7 @@ import com.cloud.utils.component.ComponentLocator; public class UserContext { private static ThreadLocal s_currentContext = new ThreadLocal(); - private static final ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - private static final AccountService _accountMgr = locator.getManager(AccountService.class); - + private long userId; private String sessionId; private Account account; @@ -34,8 +32,6 @@ public class UserContext { private boolean apiServer; - private static UserContext s_adminContext = new UserContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false); - public UserContext() { } @@ -86,10 +82,10 @@ public class UserContext { // however, there are many places that run background jobs assume the system context. // // If there is a security concern, all entry points from user (including the front end that takes HTTP -// request in and + // request in and // the core async-job manager that runs commands from user) have explicitly setup the UserContext. // - return s_adminContext; + return UserContextInitializer.getInstance().getAdminContext(); } return context; } diff --git a/api/src/com/cloud/user/UserContextInitializer.java b/api/src/com/cloud/user/UserContextInitializer.java new file mode 100644 index 00000000000..a54596373eb --- /dev/null +++ b/api/src/com/cloud/user/UserContextInitializer.java @@ -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); + } +} diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in index 34bb853c52e..07c9aeef873 100644 --- a/client/tomcatconf/applicationContext.xml.in +++ b/client/tomcatconf/applicationContext.xml.in @@ -58,4 +58,6 @@ + + diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java new file mode 100644 index 00000000000..a29fa9f4e92 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java @@ -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 + + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java index 70530dcc557..fba899e04b5 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java @@ -5,15 +5,18 @@ import java.util.Date; import java.util.List; import java.util.Map; +import javax.inject.Inject; + import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO; + import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlanner.ExcludeList; public class VirtualMachineEntityImpl implements VirtualMachineEntity { - private VMEntityManager manager; + @Inject private VMEntityManager manager; private VMEntityVO vmEntityVO; diff --git a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java index 30595f01c9e..b6219f5ad1c 100755 --- a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java @@ -32,6 +32,7 @@ import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl; import org.apache.cloudstack.engine.cloud.entity.api.VMEntityManager; import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; import org.apache.cloudstack.engine.service.api.OrchestrationService; +import org.springframework.stereotype.Component; import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.InsufficientCapacityException; @@ -49,7 +50,7 @@ import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.VMInstanceDao; - +@Component public class CloudOrchestrator implements OrchestrationService { @Inject diff --git a/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java index 79c11d1c4c7..241b114589a 100755 --- a/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java +++ b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -44,8 +45,8 @@ import com.cloud.vm.VirtualMachineProfile; public class RandomAllocator implements HostAllocator { private static final Logger s_logger = Logger.getLogger(RandomAllocator.class); private String _name; - private HostDao _hostDao; - private ResourceManager _resourceMgr; + @Inject private HostDao _hostDao; + @Inject private ResourceManager _resourceMgr; @Override public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, @@ -119,13 +120,6 @@ public class RandomAllocator implements HostAllocator { @Override public boolean configure(String name, Map params) { - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - _hostDao = locator.getDao(HostDao.class); - _resourceMgr = locator.getManager(ResourceManager.class); - if (_hostDao == null) { - s_logger.error("Unable to get host dao."); - return false; - } _name=name; return true; diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java index 91ead4dc673..b5d58dc2619 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java @@ -348,13 +348,6 @@ public class VmwareServerDiscoverer extends DiscovererBase implements super.configure(name, params); - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException( - "Unable to get the configuration dao."); - } - createVmwareToolsIso(); if (s_logger.isInfoEnabled()) { diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java index bf5d2041c76..75e10c9f36a 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java @@ -114,8 +114,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis private String _instance; @Inject AgentManager _agentMgr; - @Inject - protected NetworkManager _netMgr; + @Inject NetworkManager _netMgr; @Inject HostDao _hostDao; @Inject ClusterDao _clusterDao; @Inject ClusterDetailsDao _clusterDetailsDao; @@ -125,8 +124,8 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis @Inject SecondaryStorageVmManager _ssvmMgr; @Inject CiscoNexusVSMDeviceDao _nexusDao; @Inject ClusterVSMMapDao _vsmMapDao; - - ConfigurationServer _configServer; + @Inject ConfigurationDao _configDao; + @Inject ConfigurationServer _configServer; String _mountParent; StorageLayer _storage; @@ -174,24 +173,18 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - - if(!configDao.isPremium()) { + if(!_configDao.isPremium()) { s_logger.error("Vmware component can only run under premium distribution"); throw new ConfigurationException("Vmware component can only run under premium distribution"); } - _instance = configDao.getValue(Config.InstanceName.key()); + _instance = _configDao.getValue(Config.InstanceName.key()); if (_instance == null) { _instance = "DEFAULT"; } s_logger.info("VmwareManagerImpl config - instance.name: " + _instance); - _mountParent = configDao.getValue(Config.MountParent.key()); + _mountParent = _configDao.getValue(Config.MountParent.key()); if (_mountParent == null) { _mountParent = File.separator + "mnt"; } @@ -220,7 +213,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis } } - value = configDao.getValue(Config.VmwareUseNexusVSwitch.key()); + value = _configDao.getValue(Config.VmwareUseNexusVSwitch.key()); if(value == null) { _nexusVSwitchActive = false; } @@ -229,7 +222,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis _nexusVSwitchActive = Boolean.parseBoolean(value); } - _privateNetworkVSwitchName = configDao.getValue(Config.VmwarePrivateNetworkVSwitch.key()); + _privateNetworkVSwitchName = _configDao.getValue(Config.VmwarePrivateNetworkVSwitch.key()); if (_privateNetworkVSwitchName == null) { if (_nexusVSwitchActive) { @@ -239,7 +232,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis } } - _publicNetworkVSwitchName = configDao.getValue(Config.VmwarePublicNetworkVSwitch.key()); + _publicNetworkVSwitchName = _configDao.getValue(Config.VmwarePublicNetworkVSwitch.key()); if (_publicNetworkVSwitchName == null) { if (_nexusVSwitchActive) { @@ -249,7 +242,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis } } - _guestNetworkVSwitchName = configDao.getValue(Config.VmwareGuestNetworkVSwitch.key()); + _guestNetworkVSwitchName = _configDao.getValue(Config.VmwareGuestNetworkVSwitch.key()); if (_guestNetworkVSwitchName == null) { if (_nexusVSwitchActive) { @@ -259,69 +252,66 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis } } - _serviceConsoleName = configDao.getValue(Config.VmwareServiceConsole.key()); + _serviceConsoleName = _configDao.getValue(Config.VmwareServiceConsole.key()); if(_serviceConsoleName == null) { _serviceConsoleName = "Service Console"; } - _managemetPortGroupName = configDao.getValue(Config.VmwareManagementPortGroup.key()); + _managemetPortGroupName = _configDao.getValue(Config.VmwareManagementPortGroup.key()); if(_managemetPortGroupName == null) { _managemetPortGroupName = "Management Network"; } - _defaultSystemVmNicAdapterType = configDao.getValue(Config.VmwareSystemVmNicDeviceType.key()); + _defaultSystemVmNicAdapterType = _configDao.getValue(Config.VmwareSystemVmNicDeviceType.key()); if(_defaultSystemVmNicAdapterType == null) _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString(); - _additionalPortRangeStart = NumbersUtil.parseInt(configDao.getValue(Config.VmwareAdditionalVncPortRangeStart.key()), 59000); + _additionalPortRangeStart = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareAdditionalVncPortRangeStart.key()), 59000); if(_additionalPortRangeStart > 65535) { s_logger.warn("Invalid port range start port (" + _additionalPortRangeStart + ") for additional VNC port allocation, reset it to default start port 59000"); _additionalPortRangeStart = 59000; } - _additionalPortRangeSize = NumbersUtil.parseInt(configDao.getValue(Config.VmwareAdditionalVncPortRangeSize.key()), 1000); + _additionalPortRangeSize = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareAdditionalVncPortRangeSize.key()), 1000); if(_additionalPortRangeSize < 0 || _additionalPortRangeStart + _additionalPortRangeSize > 65535) { s_logger.warn("Invalid port range size (" + _additionalPortRangeSize + " for range starts at " + _additionalPortRangeStart); _additionalPortRangeSize = Math.min(1000, 65535 - _additionalPortRangeStart); } - _routerExtraPublicNics = NumbersUtil.parseInt(configDao.getValue(Config.RouterExtraPublicNics.key()), 2); + _routerExtraPublicNics = NumbersUtil.parseInt(_configDao.getValue(Config.RouterExtraPublicNics.key()), 2); - _maxHostsPerCluster = NumbersUtil.parseInt(configDao.getValue(Config.VmwarePerClusterHostMax.key()), VmwareManager.MAX_HOSTS_PER_CLUSTER); - _cpuOverprovisioningFactor = configDao.getValue(Config.CPUOverprovisioningFactor.key()); + _maxHostsPerCluster = NumbersUtil.parseInt(_configDao.getValue(Config.VmwarePerClusterHostMax.key()), VmwareManager.MAX_HOSTS_PER_CLUSTER); + _cpuOverprovisioningFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key()); if(_cpuOverprovisioningFactor == null || _cpuOverprovisioningFactor.isEmpty()) _cpuOverprovisioningFactor = "1"; - _memOverprovisioningFactor = configDao.getValue(Config.MemOverprovisioningFactor.key()); + _memOverprovisioningFactor = _configDao.getValue(Config.MemOverprovisioningFactor.key()); if(_memOverprovisioningFactor == null || _memOverprovisioningFactor.isEmpty()) _memOverprovisioningFactor = "1"; - _reserveCpu = configDao.getValue(Config.VmwareReserveCpu.key()); + _reserveCpu = _configDao.getValue(Config.VmwareReserveCpu.key()); if(_reserveCpu == null || _reserveCpu.isEmpty()) _reserveCpu = "false"; - _reserveMem = configDao.getValue(Config.VmwareReserveMem.key()); + _reserveMem = _configDao.getValue(Config.VmwareReserveMem.key()); if(_reserveMem == null || _reserveMem.isEmpty()) _reserveMem = "false"; - _recycleHungWorker = configDao.getValue(Config.VmwareRecycleHungWorker.key()); + _recycleHungWorker = _configDao.getValue(Config.VmwareRecycleHungWorker.key()); if(_recycleHungWorker == null || _recycleHungWorker.isEmpty()) _recycleHungWorker = "false"; - _rootDiskController = configDao.getValue(Config.VmwareRootDiskControllerType.key()); + _rootDiskController = _configDao.getValue(Config.VmwareRootDiskControllerType.key()); if(_rootDiskController == null || _rootDiskController.isEmpty()) _rootDiskController = DiskControllerType.ide.toString(); s_logger.info("Additional VNC port allocation range is settled at " + _additionalPortRangeStart + " to " + (_additionalPortRangeStart + _additionalPortRangeSize)); - value = configDao.getValue("vmware.host.scan.interval"); + value = _configDao.getValue("vmware.host.scan.interval"); _hostScanInterval = NumbersUtil.parseLong(value, DEFAULT_HOST_SCAN_INTERVAL); s_logger.info("VmwareManagerImpl config - vmware.host.scan.interval: " + _hostScanInterval); ((VmwareStorageManagerImpl)_storageMgr).configure(params); - if(_configServer == null) - _configServer = (ConfigurationServer)ComponentLocator.getComponent(ConfigurationServer.Name); - _agentMgr.registerForHostEvents(this, true, true, true); s_logger.info("VmwareManagerImpl has been successfully configured"); diff --git a/plugins/user-authenticators/ldap/src/com/cloud/server/auth/LDAPUserAuthenticator.java b/plugins/user-authenticators/ldap/src/com/cloud/server/auth/LDAPUserAuthenticator.java index dba92d0e86f..23b7a855019 100644 --- a/plugins/user-authenticators/ldap/src/com/cloud/server/auth/LDAPUserAuthenticator.java +++ b/plugins/user-authenticators/ldap/src/com/cloud/server/auth/LDAPUserAuthenticator.java @@ -21,6 +21,7 @@ import java.util.Hashtable; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import javax.naming.Context; import javax.naming.NamingEnumeration; @@ -36,10 +37,8 @@ import org.bouncycastle.util.encoders.Base64; import org.springframework.stereotype.Component; import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.server.ManagementServer; import com.cloud.user.UserAccount; import com.cloud.user.dao.UserAccountDao; -import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.exception.CloudRuntimeException; @@ -48,8 +47,8 @@ import com.cloud.utils.exception.CloudRuntimeException; public class LDAPUserAuthenticator extends DefaultUserAuthenticator { public static final Logger s_logger = Logger.getLogger(LDAPUserAuthenticator.class); - private ConfigurationDao _configDao; - private UserAccountDao _userAccountDao; + @Inject private ConfigurationDao _configDao; + @Inject private UserAccountDao _userAccountDao; @Override public boolean authenticate(String username, String password, Long domainId, Map requestParameters ) { @@ -157,9 +156,6 @@ public class LDAPUserAuthenticator extends DefaultUserAuthenticator { public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); - _configDao = locator.getDao(ConfigurationDao.class); - _userAccountDao = locator.getDao(UserAccountDao.class); return true; } diff --git a/plugins/user-authenticators/md5/src/com/cloud/server/auth/MD5UserAuthenticator.java b/plugins/user-authenticators/md5/src/com/cloud/server/auth/MD5UserAuthenticator.java index ab89c92ea6b..9d217e6f2c9 100644 --- a/plugins/user-authenticators/md5/src/com/cloud/server/auth/MD5UserAuthenticator.java +++ b/plugins/user-authenticators/md5/src/com/cloud/server/auth/MD5UserAuthenticator.java @@ -21,6 +21,7 @@ import java.security.NoSuchAlgorithmException; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; @@ -42,7 +43,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class MD5UserAuthenticator extends DefaultUserAuthenticator { public static final Logger s_logger = Logger.getLogger(MD5UserAuthenticator.class); - private UserAccountDao _userAccountDao; + @Inject private UserAccountDao _userAccountDao; @Override public boolean authenticate(String username, String password, Long domainId, Map requestParameters ) { @@ -65,8 +66,6 @@ public class MD5UserAuthenticator extends DefaultUserAuthenticator { public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); - _userAccountDao = locator.getDao(UserAccountDao.class); return true; } diff --git a/plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java b/plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java index bc18e9f03c4..0bf650bfe53 100644 --- a/plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java +++ b/plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java @@ -21,6 +21,7 @@ import java.security.NoSuchAlgorithmException; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; @@ -38,7 +39,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class PlainTextUserAuthenticator extends DefaultUserAuthenticator { public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class); - private UserAccountDao _userAccountDao; + @Inject private UserAccountDao _userAccountDao; @Override public boolean authenticate(String username, String password, Long domainId, Map requestParameters ) { @@ -85,8 +86,6 @@ public class PlainTextUserAuthenticator extends DefaultUserAuthenticator { public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); - _userAccountDao = locator.getDao(UserAccountDao.class); return true; } diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 40bc1d1612e..ee5971f51c7 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -231,13 +231,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager { public boolean configure(final String name, final Map params) throws ConfigurationException { _name = name; - final ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - - final Map configs = configDao.getConfiguration("AgentManager", params); + final Map configs = _configDao.getConfiguration("AgentManager", params); _port = NumbersUtil.parseInt(configs.get("port"), 8250); final int workers = NumbersUtil.parseInt(configs.get("workers"), 5); diff --git a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index 8c6bae8cdce..6753b280961 100755 --- a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -122,6 +122,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Inject protected AgentManager _agentMgr; + @Inject ConfigurationDao _configDao; protected ClusteredAgentManagerImpl() { super(); @@ -135,8 +136,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust s_logger.info("Configuring ClusterAgentManagerImpl. management server node id(msid): " + _nodeId); - ConfigurationDao configDao = ComponentLocator.getCurrentLocator().getDao(ConfigurationDao.class); - Map params = configDao.getConfiguration(xmlParams); + Map params = _configDao.getConfiguration(xmlParams); String value = params.get(Config.DirectAgentLoadSize.key()); _loadSize = NumbersUtil.parseInt(value, 16); diff --git a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java index 52b93c41679..c43f8ea395b 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java @@ -40,8 +40,6 @@ import com.cloud.host.Host.Type; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDetailsDao; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao; import com.cloud.offering.ServiceOffering; import com.cloud.resource.ResourceManager; import com.cloud.service.dao.ServiceOfferingDao; @@ -52,7 +50,6 @@ import com.cloud.storage.dao.GuestOSCategoryDao; import com.cloud.storage.dao.GuestOSDao; import com.cloud.user.Account; import com.cloud.utils.NumbersUtil; -import com.cloud.utils.component.ComponentLocator; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.ConsoleProxyDao; @@ -396,7 +393,6 @@ public class FirstFitAllocator implements HostAllocator { @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); if (_configDao != null) { Map configs = _configDao.getConfiguration(params); String opFactor = configs.get("cpu.overprovisioning.factor"); diff --git a/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java index c80ab405c86..9951896ffd6 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java @@ -21,10 +21,12 @@ import java.util.List; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import org.springframework.stereotype.Component; import com.cloud.agent.manager.allocator.HostAllocator; +import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.host.Host; @@ -38,7 +40,7 @@ import com.cloud.vm.VirtualMachineProfile; @Component @Local(value={HostAllocator.class}) public class TestingAllocator implements HostAllocator { - HostDao _hostDao; + @Inject HostDao _hostDao; Long _computingHost; Long _storageHost; Long _routingHost; @@ -81,9 +83,6 @@ public class TestingAllocator implements HostAllocator { value = (String)params.get(Host.Type.Storage.toString()); _storageHost = (value != null) ? Long.parseLong(value) : null; - ComponentLocator _locator = ComponentLocator.getCurrentLocator(); - _hostDao = _locator.getDao(HostDao.class); - _name = name; return true; diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 4fbc69570ce..2ad21eda9c1 100755 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -106,7 +106,6 @@ public class AlertManagerImpl implements AlertManager { @Inject private ConfigurationDao _configDao; @Inject private ResourceManager _resourceMgr; @Inject private ConfigurationManager _configMgr; - private Timer _timer = null; private float _cpuOverProvisioningFactor = 1; private long _capacityCheckPeriod = 60L * 60L * 1000L; // one hour by default @@ -126,14 +125,7 @@ public class AlertManagerImpl implements AlertManager { public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - s_logger.error("Unable to get the configuration dao."); - return false; - } - - Map configs = configDao.getConfiguration("management-server", params); + Map configs = _configDao.getConfiguration("management-server", params); // set up the email system for alerts String emailAddressList = configs.get("alert.email.addresses"); diff --git a/server/src/com/cloud/alert/ClusterAlertAdapter.java b/server/src/com/cloud/alert/ClusterAlertAdapter.java index ed2a1eda89d..f8b782c2b99 100644 --- a/server/src/com/cloud/alert/ClusterAlertAdapter.java +++ b/server/src/com/cloud/alert/ClusterAlertAdapter.java @@ -19,6 +19,7 @@ package com.cloud.alert; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; @@ -29,8 +30,6 @@ import com.cloud.cluster.ClusterNodeJoinEventArgs; import com.cloud.cluster.ClusterNodeLeftEventArgs; import com.cloud.cluster.ManagementServerHostVO; import com.cloud.cluster.dao.ManagementServerHostDao; -import com.cloud.utils.component.ComponentLocator; -import com.cloud.utils.db.GlobalLock; import com.cloud.utils.events.EventArgs; import com.cloud.utils.events.SubscriptionMgr; @@ -40,10 +39,9 @@ public class ClusterAlertAdapter implements AlertAdapter { private static final Logger s_logger = Logger.getLogger(ClusterAlertAdapter.class); - private AlertManager _alertMgr; private String _name; - - private ManagementServerHostDao _mshostDao; + @Inject private AlertManager _alertMgr; + @Inject private ManagementServerHostDao _mshostDao; public void onClusterAlert(Object sender, EventArgs args) { if (s_logger.isDebugEnabled()) { @@ -109,19 +107,7 @@ public class ClusterAlertAdapter implements AlertAdapter { s_logger.info("Start configuring cluster alert manager : " + name); } - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - _mshostDao = locator.getDao(ManagementServerHostDao.class); - if (_mshostDao == null) { - throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName()); - } - - _alertMgr = locator.getManager(AlertManager.class); - if (_alertMgr == null) { - throw new ConfigurationException("Unable to get " + AlertManager.class.getName()); - } - - try { + try { SubscriptionMgr.getInstance().subscribe(ClusterManager.ALERT_SUBJECT, this, "onClusterAlert"); } catch (SecurityException e) { throw new ConfigurationException("Unable to register cluster event subscription"); diff --git a/server/src/com/cloud/alert/ConsoleProxyAlertAdapter.java b/server/src/com/cloud/alert/ConsoleProxyAlertAdapter.java index cd6225617ed..37e385021e1 100644 --- a/server/src/com/cloud/alert/ConsoleProxyAlertAdapter.java +++ b/server/src/com/cloud/alert/ConsoleProxyAlertAdapter.java @@ -19,6 +19,7 @@ package com.cloud.alert; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; @@ -41,11 +42,11 @@ public class ConsoleProxyAlertAdapter implements AlertAdapter { private static final Logger s_logger = Logger.getLogger(ConsoleProxyAlertAdapter.class); - private AlertManager _alertMgr; + @Inject private AlertManager _alertMgr; private String _name; - private DataCenterDao _dcDao; - private ConsoleProxyDao _consoleProxyDao; + @Inject private DataCenterDao _dcDao; + @Inject private ConsoleProxyDao _consoleProxyDao; public void onProxyAlert(Object sender, ConsoleProxyAlertEventArgs args) { if(s_logger.isDebugEnabled()) @@ -187,23 +188,6 @@ public class ConsoleProxyAlertAdapter implements AlertAdapter { if (s_logger.isInfoEnabled()) s_logger.info("Start configuring console proxy alert manager : " + name); - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - _dcDao = locator.getDao(DataCenterDao.class); - if (_dcDao == null) { - throw new ConfigurationException("Unable to get " + DataCenterDao.class.getName()); - } - - _consoleProxyDao = locator.getDao(ConsoleProxyDao.class); - if (_consoleProxyDao == null) { - throw new ConfigurationException("Unable to get " + ConsoleProxyDao.class.getName()); - } - - _alertMgr = locator.getManager(AlertManager.class); - if (_alertMgr == null) { - throw new ConfigurationException("Unable to get " + AlertManager.class.getName()); - } - try { SubscriptionMgr.getInstance().subscribe(ConsoleProxyManager.ALERT_SUBJECT, this, "onProxyAlert"); } catch (SecurityException e) { diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 6faaa4a067a..c5cee130e40 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -119,7 +119,6 @@ import com.cloud.event.EventUtils; import com.cloud.exception.CloudAuthenticationException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; -import com.cloud.server.ManagementServer; import com.cloud.user.Account; import com.cloud.user.AccountManager; import com.cloud.user.DomainManager; @@ -130,7 +129,7 @@ import com.cloud.user.UserVO; import com.cloud.utils.Pair; import com.cloud.utils.StringUtils; import com.cloud.utils.component.ComponentContext; -import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.component.PluggableService; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; @@ -151,6 +150,9 @@ public class ApiServer implements HttpRequestHandler { @Inject private ConfigurationDao _configDao; @Inject protected List _apiAccessCheckers; + @Inject List _pluggableServices; + @Inject IdentityDao _identityDao; + private Account _systemAccount = null; private User _systemUser = null; private static int _workerCount = 0; @@ -683,10 +685,8 @@ public class ApiServer implements HttpRequestHandler { } public Long fetchDomainId(String domainUUID){ - ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); - IdentityDao identityDao = locator.getDao(IdentityDao.class); try{ - Long domainId = identityDao.getIdentityId("domain", domainUUID); + Long domainId = _identityDao.getIdentityId("domain", domainUUID); return domainId; }catch(InvalidParameterValueException ex){ return null; diff --git a/server/src/com/cloud/async/AsyncJobExecutorContextImpl.java b/server/src/com/cloud/async/AsyncJobExecutorContextImpl.java index d2b22f42b5f..ed6441994eb 100644 --- a/server/src/com/cloud/async/AsyncJobExecutorContextImpl.java +++ b/server/src/com/cloud/async/AsyncJobExecutorContextImpl.java @@ -19,6 +19,7 @@ package com.cloud.async; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.springframework.stereotype.Component; @@ -46,23 +47,23 @@ import com.cloud.vm.dao.UserVmDao; public class AsyncJobExecutorContextImpl implements AsyncJobExecutorContext { private String _name; - private AgentManager _agentMgr; - private NetworkManager _networkMgr; - private UserVmManager _vmMgr; - private SnapshotManager _snapMgr; - private AccountManager _accountMgr; - private StorageManager _storageMgr; - private EventDao _eventDao; - private UserVmDao _vmDao; - private AccountDao _accountDao; - private VolumeDao _volumeDao; - private DomainRouterDao _routerDao; - private IPAddressDao _ipAddressDao; - private AsyncJobDao _jobDao; - private UserDao _userDao; - private VirtualMachineManager _itMgr; + @Inject private AgentManager _agentMgr; + @Inject private NetworkManager _networkMgr; + @Inject private UserVmManager _vmMgr; + @Inject private SnapshotManager _snapMgr; + @Inject private AccountManager _accountMgr; + @Inject private StorageManager _storageMgr; + @Inject private EventDao _eventDao; + @Inject private UserVmDao _vmDao; + @Inject private AccountDao _accountDao; + @Inject private VolumeDao _volumeDao; + @Inject private DomainRouterDao _routerDao; + @Inject private IPAddressDao _ipAddressDao; + @Inject private AsyncJobDao _jobDao; + @Inject private UserDao _userDao; + @Inject private VirtualMachineManager _itMgr; - private ManagementServer _managementServer; + @Inject private ManagementServer _managementServer; @Override public ManagementServer getManagementServer() { @@ -150,87 +151,6 @@ public class AsyncJobExecutorContextImpl implements AsyncJobExecutorContext { @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - _managementServer = (ManagementServer)ComponentLocator.getComponent("management-server"); - if (_managementServer == null) { - throw new ConfigurationException("unable to get " + ManagementServer.class.getName()); - } - - _agentMgr = locator.getManager(AgentManager.class); - if (_agentMgr == null) { - throw new ConfigurationException("unable to get " + AgentManager.class.getName()); - } - - _networkMgr = locator.getManager(NetworkManager.class); - if (_networkMgr == null) { - throw new ConfigurationException("unable to get " + NetworkManager.class.getName()); - } - - _vmMgr = locator.getManager(UserVmManager.class); - if (_vmMgr == null) { - throw new ConfigurationException("unable to get " + UserVmManager.class.getName()); - } - - _snapMgr = locator.getManager(SnapshotManager.class); - if (_snapMgr == null) { - throw new ConfigurationException("unable to get " + SnapshotManager.class.getName()); - } - - _accountMgr = locator.getManager(AccountManager.class); - if (_accountMgr == null) { - throw new ConfigurationException("unable to get " + AccountManager.class.getName()); - } - - _storageMgr = locator.getManager(StorageManager.class); - if (_storageMgr == null) { - throw new ConfigurationException("unable to get " + StorageManager.class.getName()); - } - - _eventDao = locator.getDao(EventDao.class); - if (_eventDao == null) { - throw new ConfigurationException("unable to get " + EventDao.class.getName()); - } - - _vmDao = locator.getDao(UserVmDao.class); - if (_vmDao == null) { - throw new ConfigurationException("unable to get " + UserVmDao.class.getName()); - } - - _accountDao = locator.getDao(AccountDao.class); - if (_accountDao == null) { - throw new ConfigurationException("unable to get " + AccountDao.class.getName()); - } - - _volumeDao = locator.getDao(VolumeDao.class); - if (_volumeDao == null) { - throw new ConfigurationException("unable to get " + VolumeDao.class.getName()); - } - - _routerDao = locator.getDao(DomainRouterDao.class); - if (_routerDao == null) { - throw new ConfigurationException("unable to get " + DomainRouterDao.class.getName()); - } - - _ipAddressDao = locator.getDao(IPAddressDao.class); - if (_ipAddressDao == null) { - throw new ConfigurationException("unable to get " + IPAddressDao.class.getName()); - } - - _jobDao = locator.getDao(AsyncJobDao.class); - if(_jobDao == null) { - throw new ConfigurationException("unable to get " + AsyncJobDao.class.getName()); - } - - _userDao = locator.getDao(UserDao.class); - if(_userDao == null) { - throw new ConfigurationException("unable to get " + UserDao.class.getName()); - } - - _itMgr = locator.getManager(VirtualMachineManager.class); - if (_itMgr == null) { - throw new ConfigurationException("unable to get " + VirtualMachineManager.class.getName()); - } return true; } diff --git a/server/src/com/cloud/async/AsyncJobManagerImpl.java b/server/src/com/cloud/async/AsyncJobManagerImpl.java index e4016f73096..25b7e6086fd 100644 --- a/server/src/com/cloud/async/AsyncJobManagerImpl.java +++ b/server/src/com/cloud/async/AsyncJobManagerImpl.java @@ -32,6 +32,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd; @@ -87,12 +88,13 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe private String _name; - private AsyncJobExecutorContext _context; - private SyncQueueManager _queueMgr; - private ClusterManager _clusterMgr; - private AccountManager _accountMgr; - private AccountDao _accountDao; - private AsyncJobDao _jobDao; + @Inject private AsyncJobExecutorContext _context; + @Inject private SyncQueueManager _queueMgr; + @Inject private ClusterManager _clusterMgr; + @Inject private AccountManager _accountMgr; + @Inject private AccountDao _accountDao; + @Inject private AsyncJobDao _jobDao; + @Inject private ConfigurationDao _configDao; private long _jobExpireSeconds = 86400; // 1 day private long _jobCancelThresholdSeconds = 3600; // 1 hour (for cancelling the jobs blocking other jobs) @@ -697,47 +699,14 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - int expireMinutes = NumbersUtil.parseInt( - configDao.getValue(Config.JobExpireMinutes.key()), 24*60); + _configDao.getValue(Config.JobExpireMinutes.key()), 24*60); _jobExpireSeconds = (long)expireMinutes*60; _jobCancelThresholdSeconds = NumbersUtil.parseInt( - configDao.getValue(Config.JobCancelThresholdMinutes.key()), 60); + _configDao.getValue(Config.JobCancelThresholdMinutes.key()), 60); _jobCancelThresholdSeconds *= 60; - _accountDao = locator.getDao(AccountDao.class); - if (_accountDao == null) { - throw new ConfigurationException("Unable to get " + AccountDao.class.getName()); - } - _jobDao = locator.getDao(AsyncJobDao.class); - if (_jobDao == null) { - throw new ConfigurationException("Unable to get " - + AsyncJobDao.class.getName()); - } - - _context = locator.getManager(AsyncJobExecutorContext.class); - if (_context == null) { - throw new ConfigurationException("Unable to get " - + AsyncJobExecutorContext.class.getName()); - } - - _queueMgr = locator.getManager(SyncQueueManager.class); - if(_queueMgr == null) { - throw new ConfigurationException("Unable to get " - + SyncQueueManager.class.getName()); - } - - _clusterMgr = locator.getManager(ClusterManager.class); - - _accountMgr = locator.getManager(AccountManager.class); - _dispatcher = ApiDispatcher.getInstance(); diff --git a/server/src/com/cloud/async/SyncQueueManagerImpl.java b/server/src/com/cloud/async/SyncQueueManagerImpl.java index 94fcf0bc4a5..5246e46c7b7 100644 --- a/server/src/com/cloud/async/SyncQueueManagerImpl.java +++ b/server/src/com/cloud/async/SyncQueueManagerImpl.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; @@ -42,8 +43,8 @@ public class SyncQueueManagerImpl implements SyncQueueManager { private String _name; - private SyncQueueDao _syncQueueDao; - private SyncQueueItemDao _syncQueueItemDao; + @Inject private SyncQueueDao _syncQueueDao; + @Inject private SyncQueueItemDao _syncQueueItemDao; @Override @DB @@ -243,20 +244,6 @@ public class SyncQueueManagerImpl implements SyncQueueManager { @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - _syncQueueDao = locator.getDao(SyncQueueDao.class); - if (_syncQueueDao == null) { - throw new ConfigurationException("Unable to get " - + SyncQueueDao.class.getName()); - } - - _syncQueueItemDao = locator.getDao(SyncQueueItemDao.class); - if (_syncQueueItemDao == null) { - throw new ConfigurationException("Unable to get " - + SyncQueueDao.class.getName()); - } - return true; } diff --git a/server/src/com/cloud/baremetal/BareMetalResourceBase.java b/server/src/com/cloud/baremetal/BareMetalResourceBase.java index 36afa8ba54b..a922db911ef 100755 --- a/server/src/com/cloud/baremetal/BareMetalResourceBase.java +++ b/server/src/com/cloud/baremetal/BareMetalResourceBase.java @@ -23,7 +23,6 @@ import javax.ejb.Local; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -66,7 +65,6 @@ import com.cloud.utils.script.Script2.ParamType; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; -@Component @Local(value = ServerResource.class) public class BareMetalResourceBase implements ServerResource { private static final Logger s_logger = Logger.getLogger(BareMetalResourceBase.class); diff --git a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java index c419f5ab89a..1ce9b33c009 100755 --- a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java +++ b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java @@ -33,8 +33,6 @@ import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd; import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd; import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd; import org.apache.log4j.Logger; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; import com.cloud.agent.api.Answer; import com.cloud.agent.api.StopAnswer; @@ -84,7 +82,6 @@ import com.cloud.uservm.UserVm; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.component.Adapters; -import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.Manager; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; @@ -105,13 +102,11 @@ import com.cloud.vm.VirtualMachineName; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile.Param; -@Component -@Primary @Local(value={BareMetalVmManager.class, BareMetalVmService.class}) public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMetalVmManager, BareMetalVmService, Manager, StateListener { private static final Logger s_logger = Logger.getLogger(BareMetalVmManagerImpl.class); - private ConfigurationDao _configDao; + @Inject ConfigurationDao _configDao; @Inject PxeServerManager _pxeMgr; @Inject ResourceManager _resourceMgr; @@ -444,12 +439,6 @@ public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMet public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - _configDao = locator.getDao(ConfigurationDao.class); - if (_configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - Map configs = _configDao.getConfiguration("AgentManager", params); _instance = configs.get("instance.name"); diff --git a/server/src/com/cloud/cluster/CheckPointManagerImpl.java b/server/src/com/cloud/cluster/CheckPointManagerImpl.java index 78d14d35c2c..e02a2f0dcc2 100644 --- a/server/src/com/cloud/cluster/CheckPointManagerImpl.java +++ b/server/src/com/cloud/cluster/CheckPointManagerImpl.java @@ -59,6 +59,8 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste @Inject private ClusterManager _clusterMgr; + @Inject ConfigurationDao _configDao; + long _msId; private final ScheduledExecutorService _cleanupScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Task-Cleanup")); @@ -79,10 +81,7 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste _clusterMgr.registerListener(this); - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - - Map params = configDao.getConfiguration(xmlParams); + Map params = _configDao.getConfiguration(xmlParams); _cleanupRetryInterval = NumbersUtil.parseInt(params.get(Config.TaskCleanupRetryInterval.key()), 600); _maidDao.takeover(_msId, _msId); diff --git a/server/src/com/cloud/cluster/ClusterManagerImpl.java b/server/src/com/cloud/cluster/ClusterManagerImpl.java index 9976bd7f7d0..013034f08a5 100755 --- a/server/src/com/cloud/cluster/ClusterManagerImpl.java +++ b/server/src/com/cloud/cluster/ClusterManagerImpl.java @@ -127,10 +127,11 @@ public class ClusterManagerImpl implements ClusterManager { @Inject private List _serviceAdapters; - private ManagementServerHostDao _mshostDao; - private ManagementServerHostPeerDao _mshostPeerDao; - private HostDao _hostDao; - private HostTransferMapDao _hostTransferDao; + @Inject private ManagementServerHostDao _mshostDao; + @Inject private ManagementServerHostPeerDao _mshostPeerDao; + @Inject private HostDao _hostDao; + @Inject private HostTransferMapDao _hostTransferDao; + @Inject private ConfigurationDao _configDao; // // pay attention to _mshostId and _msid @@ -1257,38 +1258,7 @@ public class ClusterManagerImpl implements ClusterManager { } _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - _agentMgr = locator.getManager(AgentManager.class); - if (_agentMgr == null) { - throw new ConfigurationException("Unable to get " + AgentManager.class.getName()); - } - - _mshostDao = locator.getDao(ManagementServerHostDao.class); - if (_mshostDao == null) { - throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName()); - } - - _mshostPeerDao = locator.getDao(ManagementServerHostPeerDao.class); - if (_mshostPeerDao == null) { - throw new ConfigurationException("Unable to get " + ManagementServerHostPeerDao.class.getName()); - } - - _hostDao = locator.getDao(HostDao.class); - if (_hostDao == null) { - throw new ConfigurationException("Unable to get " + HostDao.class.getName()); - } - - _hostTransferDao = locator.getDao(HostTransferMapDao.class); - if (_hostTransferDao == null) { - throw new ConfigurationException("Unable to get agent transfer map dao"); - } - - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - - Map configs = configDao.getConfiguration("management-server", params); + Map configs = _configDao.getConfiguration("management-server", params); String value = configs.get("cluster.heartbeat.interval"); if (value != null) { @@ -1338,7 +1308,7 @@ public class ClusterManagerImpl implements ClusterManager { throw new ConfigurationException("Unable to set current cluster service adapter"); } - _agentLBEnabled = Boolean.valueOf(configDao.getValue(Config.AgentLbEnable.key())); + _agentLBEnabled = Boolean.valueOf(_configDao.getValue(Config.AgentLbEnable.key())); String connectedAgentsThreshold = configs.get("agent.load.threshold"); diff --git a/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java b/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java index 89e3cc0e033..3d1e5edb6ce 100644 --- a/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java +++ b/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Properties; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; @@ -35,7 +36,6 @@ import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.utils.NumbersUtil; import com.cloud.utils.PropertiesUtil; -import com.cloud.utils.component.ComponentLocator; @Component @Local(value={ClusterServiceAdapter.class}) @@ -45,11 +45,11 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter { private static final int DEFAULT_SERVICE_PORT = 9090; private static final int DEFAULT_REQUEST_TIMEOUT = 300; // 300 seconds - private ClusterManager _manager; + @Inject private ClusterManager _manager; - private ManagementServerHostDao _mshostDao; + @Inject private ManagementServerHostDao _mshostDao; - private ConfigurationDao _configDao; + @Inject private ConfigurationDao _configDao; private ClusterServiceServletContainer _servletContainer; @@ -134,23 +134,6 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter { if(_mshostDao != null) return; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - _manager = locator.getManager(ClusterManager.class); - if(_manager == null) - throw new ConfigurationException("Unable to get " + ClusterManager.class.getName()); - - _mshostDao = locator.getDao(ManagementServerHostDao.class); - if(_mshostDao == null) - throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName()); - - if(_mshostDao == null) - throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName()); - - _configDao = locator.getDao(ConfigurationDao.class); - if(_configDao == null) - throw new ConfigurationException("Unable to get " + ConfigurationDao.class.getName()); - String value = _configDao.getValue(Config.ClusterMessageTimeOutSeconds.key()); _clusterRequestTimeoutSeconds = NumbersUtil.parseInt(value, DEFAULT_REQUEST_TIMEOUT); s_logger.info("Configure cluster request time out. timeout: " + _clusterRequestTimeoutSeconds + " seconds"); diff --git a/server/src/com/cloud/cluster/DummyClusterManagerImpl.java b/server/src/com/cloud/cluster/DummyClusterManagerImpl.java index 767692536fc..9c8aef4e825 100755 --- a/server/src/com/cloud/cluster/DummyClusterManagerImpl.java +++ b/server/src/com/cloud/cluster/DummyClusterManagerImpl.java @@ -24,7 +24,6 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; -import com.cloud.agent.Listener; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; import com.cloud.exception.AgentUnavailableException; diff --git a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java index aec8883b198..a3de9466dab 100755 --- a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java @@ -87,6 +87,9 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu VirtualMachineManager _itMgr; @Inject protected ConsoleProxyDao _cpDao; + + @Inject ConfigurationDao _configDao; + public int getVncPort(VMInstanceVO vm) { if (vm.getHostId() == null) { return -1; @@ -104,13 +107,7 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - - Map configs = configDao.getConfiguration("management-server", params); + Map configs = _configDao.getConfiguration("management-server", params); String value = configs.get("consoleproxy.url.port"); if (value != null) { _consoleProxyUrlPort = NumbersUtil.parseInt(value, ConsoleProxyManager.DEFAULT_PROXY_URL_PORT); diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyBalanceAllocator.java b/server/src/com/cloud/consoleproxy/ConsoleProxyBalanceAllocator.java index 20cf91a25a5..84f6faca7ab 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyBalanceAllocator.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyBalanceAllocator.java @@ -81,14 +81,6 @@ public class ConsoleProxyBalanceAllocator implements ConsoleProxyAllocator { @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - - Map configs = configDao.getConfiguration(); - return true; } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 63b3da84318..6ceeb5f5ebe 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -1452,13 +1452,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - - Map configs = configDao.getConfiguration("management-server", params); + Map configs = _configDao.getConfiguration("management-server", params); String value = configs.get(Config.ConsoleProxyCmdPort.key()); value = configs.get("consoleproxy.sslEnabled"); @@ -1505,7 +1499,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx prepareDefaultCertificate(); - Map agentMgrConfigs = configDao.getConfiguration("AgentManager", params); + Map agentMgrConfigs = _configDao.getConfiguration("AgentManager", params); _mgmt_host = agentMgrConfigs.get("host"); if (_mgmt_host == null) { s_logger.warn("Critical warning! Please configure your management server host address right after you have started your management server and then restart it, otherwise you won't be able to do console access"); diff --git a/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java index 295e5c93e5e..c28a2e498e3 100755 --- a/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java @@ -40,6 +40,7 @@ public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager imp String _ip = null; @Inject ConsoleProxyDao _proxyDao; @Inject ResourceManager _resourceMgr; + @Inject ConfigurationDao _configDao; @Override protected HostVO findHost(VMInstanceVO vm) { @@ -58,10 +59,7 @@ public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager imp public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - Map dbParams = configDao.getConfiguration("ManagementServer", params); + Map dbParams = _configDao.getConfiguration("ManagementServer", params); _ip = dbParams.get("public.ip"); if (_ip == null) { diff --git a/server/src/com/cloud/dao/EntityManagerImpl.java b/server/src/com/cloud/dao/EntityManagerImpl.java index 3c335beb28e..b4ea081fa1c 100644 --- a/server/src/com/cloud/dao/EntityManagerImpl.java +++ b/server/src/com/cloud/dao/EntityManagerImpl.java @@ -33,7 +33,6 @@ import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SearchCriteria2; @Component @Local(value=EntityManager.class) diff --git a/server/src/com/cloud/dc/dao/VlanDaoImpl.java b/server/src/com/cloud/dc/dao/VlanDaoImpl.java index 28793a8259f..8fc0580aaef 100644 --- a/server/src/com/cloud/dc/dao/VlanDaoImpl.java +++ b/server/src/com/cloud/dc/dao/VlanDaoImpl.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.springframework.stereotype.Component; @@ -59,9 +60,9 @@ public class VlanDaoImpl extends GenericDaoBase implements VlanDao protected SearchBuilder NetworkVlanSearch; protected SearchBuilder PhysicalNetworkVlanSearch; - protected PodVlanMapDaoImpl _podVlanMapDao = new PodVlanMapDaoImpl(); - protected AccountVlanMapDao _accountVlanMapDao = new AccountVlanMapDaoImpl(); - protected IPAddressDao _ipAddressDao = null; + @Inject protected PodVlanMapDao _podVlanMapDao; + @Inject protected AccountVlanMapDao _accountVlanMapDao; + @Inject protected IPAddressDao _ipAddressDao; @Override public VlanVO findByZoneAndVlanId(long zoneId, String vlanId) { @@ -177,13 +178,6 @@ public class VlanDaoImpl extends GenericDaoBase implements VlanDao public boolean configure(String name, Map params) throws ConfigurationException { boolean result = super.configure(name, params); - if (result) { - final ComponentLocator locator = ComponentLocator.getCurrentLocator(); - _ipAddressDao = locator.getDao(IPAddressDao.class); - if (_ipAddressDao == null) { - throw new ConfigurationException("Unable to get " + IPAddressDao.class.getName()); - } - } ZoneTypeAllPodsSearch = createSearchBuilder(); ZoneTypeAllPodsSearch.and("zoneId", ZoneTypeAllPodsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); ZoneTypeAllPodsSearch.and("vlanType", ZoneTypeAllPodsSearch.entity().getVlanType(), SearchCriteria.Op.EQ); diff --git a/server/src/com/cloud/event/EventUtils.java b/server/src/com/cloud/event/EventUtils.java index 3672ee72d4e..68317bf32d6 100755 --- a/server/src/com/cloud/event/EventUtils.java +++ b/server/src/com/cloud/event/EventUtils.java @@ -16,16 +16,27 @@ // under the License. package com.cloud.event; +import javax.inject.Inject; + +import org.springframework.stereotype.Component; + import com.cloud.event.dao.EventDao; -import com.cloud.server.ManagementServer; import com.cloud.user.AccountVO; import com.cloud.user.dao.AccountDao; -import com.cloud.utils.component.ComponentLocator; +@Component public class EventUtils { - private static EventDao _eventDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(EventDao.class); - private static AccountDao _accountDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(AccountDao.class); + private static EventDao _eventDao; + private static AccountDao _accountDao; + @Inject EventDao _placeHoderEventDao; + @Inject AccountDao _placeHoderAccountDao; + + public EventUtils() { + _eventDao = _placeHoderEventDao; + _accountDao = _placeHoderAccountDao; + } + public static Long saveEvent(Long userId, Long accountId, Long domainId, String type, String description) { EventVO event = new EventVO(); event.setUserId(userId); diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerExtImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerExtImpl.java index ec6d20c9e67..442cb911aa0 100644 --- a/server/src/com/cloud/ha/HighAvailabilityManagerExtImpl.java +++ b/server/src/com/cloud/ha/HighAvailabilityManagerExtImpl.java @@ -41,21 +41,12 @@ public class HighAvailabilityManagerExtImpl extends HighAvailabilityManagerImpl @Inject UsageJobDao _usageJobDao; - ConfigurationDao configDao; + + @Inject ConfigurationDao configDao; @Override public boolean configure(final String name, final Map xmlParams) throws ConfigurationException { super.configure(name, xmlParams); - - ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); - - configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) - { - s_logger.warn("Unable to get a configuration dao to check config value for enableUsageServer"); - return false; - } - return true; } diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java index 31f049f8bdc..072d23788d8 100755 --- a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java +++ b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java @@ -141,7 +141,11 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu AccountManager _accountMgr; @Inject ResourceManager _resourceMgr; - + @Inject + ManagementServer _msServer; + @Inject + ConfigurationDao _configDao; + String _instance; ScheduledExecutorService _executor; int _stopRetryInterval; @@ -690,15 +694,11 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu @Override public boolean configure(final String name, final Map xmlParams) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); - _serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId(); + _serverId = _msServer.getId(); Map params = new HashMap(); - final ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao != null) { - params = configDao.getConfiguration(Long.toHexString(_serverId), xmlParams); - } + params = _configDao.getConfiguration(Long.toHexString(_serverId), xmlParams); String value = params.get(Config.HAWorkers.key()); final int count = NumbersUtil.parseInt(value, 1); diff --git a/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java b/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java index 6fead23dad0..599222abba4 100644 --- a/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java +++ b/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java @@ -53,7 +53,6 @@ import com.cloud.host.Status; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.hypervisor.kvm.discoverer.KvmDummyResourceBase; import com.cloud.network.NetworkManager; import com.cloud.network.PhysicalNetworkSetupInfo; import com.cloud.resource.Discoverer; @@ -62,323 +61,321 @@ import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceStateAdapter; import com.cloud.resource.ServerResource; import com.cloud.resource.UnableDeleteHostException; -import com.cloud.utils.component.ComponentLocator; -import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; @Component @Local(value=Discoverer.class) public class KvmServerDiscoverer extends DiscovererBase implements Discoverer, - Listener, ResourceStateAdapter { - private static final Logger s_logger = Logger.getLogger(KvmServerDiscoverer.class); - private ConfigurationDao _configDao; - private String _hostIp; - private int _waitTime = 5; /*wait for 5 minutes*/ - private String _kvmPrivateNic; - private String _kvmPublicNic; - private String _kvmGuestNic; - @Inject HostDao _hostDao = null; - @Inject ClusterDao _clusterDao; - @Inject ResourceManager _resourceMgr; - @Inject AgentManager _agentMgr; - @Inject NetworkManager _networkMgr; - - @Override - public boolean processAnswers(long agentId, long seq, Answer[] answers) { - // TODO Auto-generated method stub - return false; - } +Listener, ResourceStateAdapter { + private static final Logger s_logger = Logger.getLogger(KvmServerDiscoverer.class); + private String _hostIp; + private final int _waitTime = 5; /*wait for 5 minutes*/ + private String _kvmPrivateNic; + private String _kvmPublicNic; + private String _kvmGuestNic; + @Inject HostDao _hostDao = null; + @Inject ClusterDao _clusterDao; + @Inject ResourceManager _resourceMgr; + @Inject AgentManager _agentMgr; + @Inject NetworkManager _networkMgr; + @Inject ConfigurationDao _configDao; - @Override - public boolean processCommands(long agentId, long seq, Command[] commands) { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean processAnswers(long agentId, long seq, Answer[] answers) { + // TODO Auto-generated method stub + return false; + } - @Override - public AgentControlAnswer processControlCommand(long agentId, - AgentControlCommand cmd) { - // TODO Auto-generated method stub - return null; - } + @Override + public boolean processCommands(long agentId, long seq, Command[] commands) { + // TODO Auto-generated method stub + return false; + } - @Override - public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) { - } + @Override + public AgentControlAnswer processControlCommand(long agentId, + AgentControlCommand cmd) { + // TODO Auto-generated method stub + return null; + } - @Override - public boolean processDisconnect(long agentId, Status state) { - // TODO Auto-generated method stub - return false; - } + @Override + public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) { + } - @Override - public boolean isRecurring() { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean processDisconnect(long agentId, Status state) { + // TODO Auto-generated method stub + return false; + } - @Override - public int getTimeout() { - // TODO Auto-generated method stub - return 0; - } + @Override + public boolean isRecurring() { + // TODO Auto-generated method stub + return false; + } - @Override - public boolean processTimeout(long agentId, long seq) { - // TODO Auto-generated method stub - return false; - } + @Override + public int getTimeout() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public boolean processTimeout(long agentId, long seq) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Map> find(long dcId, + Long podId, Long clusterId, URI uri, String username, + String password, List hostTags) throws DiscoveryException { - @Override - public Map> find(long dcId, - Long podId, Long clusterId, URI uri, String username, - String password, List hostTags) throws DiscoveryException { - ClusterVO cluster = _clusterDao.findById(clusterId); if(cluster == null || cluster.getHypervisorType() != HypervisorType.KVM) { - if(s_logger.isInfoEnabled()) - s_logger.info("invalid cluster id or cluster is not for KVM hypervisors"); - return null; + if(s_logger.isInfoEnabled()) + s_logger.info("invalid cluster id or cluster is not for KVM hypervisors"); + return null; } - - Map> resources = new HashMap>(); - Map details = new HashMap(); - if (!uri.getScheme().equals("http")) { + + Map> resources = new HashMap>(); + Map details = new HashMap(); + if (!uri.getScheme().equals("http")) { String msg = "urlString is not http so we're not taking care of the discovery for this: " + uri; s_logger.debug(msg); return null; - } - com.trilead.ssh2.Connection sshConnection = null; - String agentIp = null; - try { - - String hostname = uri.getHost(); - InetAddress ia = InetAddress.getByName(hostname); - agentIp = ia.getHostAddress(); - String guid = UUID.nameUUIDFromBytes(agentIp.getBytes()).toString(); - String guidWithTail = guid + "-LibvirtComputingResource";/*tail added by agent.java*/ - if (_resourceMgr.findHostByGuid(guidWithTail) != null) { - s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database."); - return null; - } - - sshConnection = new com.trilead.ssh2.Connection(agentIp, 22); + } + com.trilead.ssh2.Connection sshConnection = null; + String agentIp = null; + try { - sshConnection.connect(null, 60000, 60000); - if (!sshConnection.authenticateWithPassword(username, password)) { - s_logger.debug("Failed to authenticate"); - throw new DiscoveredWithErrorException("Authentication error"); - } - - if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "lsmod|grep kvm", 3)) { - s_logger.debug("It's not a KVM enabled machine"); - return null; - } - - List netInfos = _networkMgr.getPhysicalNetworkInfo(dcId, HypervisorType.KVM); - String kvmPrivateNic = null; - String kvmPublicNic = null; - String kvmGuestNic = null; + String hostname = uri.getHost(); + InetAddress ia = InetAddress.getByName(hostname); + agentIp = ia.getHostAddress(); + String guid = UUID.nameUUIDFromBytes(agentIp.getBytes()).toString(); + String guidWithTail = guid + "-LibvirtComputingResource";/*tail added by agent.java*/ + if (_resourceMgr.findHostByGuid(guidWithTail) != null) { + s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database."); + return null; + } - for (PhysicalNetworkSetupInfo info : netInfos) { - if (info.getPrivateNetworkName() != null) { - kvmPrivateNic = info.getPrivateNetworkName(); - } - if (info.getPublicNetworkName() != null) { - kvmPublicNic = info.getPublicNetworkName(); - } - if (info.getGuestNetworkName() != null) { - kvmGuestNic = info.getGuestNetworkName(); - } - } + sshConnection = new com.trilead.ssh2.Connection(agentIp, 22); + + sshConnection.connect(null, 60000, 60000); + if (!sshConnection.authenticateWithPassword(username, password)) { + s_logger.debug("Failed to authenticate"); + throw new DiscoveredWithErrorException("Authentication error"); + } + + if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "lsmod|grep kvm", 3)) { + s_logger.debug("It's not a KVM enabled machine"); + return null; + } + + List netInfos = _networkMgr.getPhysicalNetworkInfo(dcId, HypervisorType.KVM); + String kvmPrivateNic = null; + String kvmPublicNic = null; + String kvmGuestNic = null; + + for (PhysicalNetworkSetupInfo info : netInfos) { + if (info.getPrivateNetworkName() != null) { + kvmPrivateNic = info.getPrivateNetworkName(); + } + if (info.getPublicNetworkName() != null) { + kvmPublicNic = info.getPublicNetworkName(); + } + if (info.getGuestNetworkName() != null) { + kvmGuestNic = info.getGuestNetworkName(); + } + } + + if (kvmPrivateNic == null && kvmPublicNic == null && kvmGuestNic == null) { + kvmPrivateNic = _kvmPrivateNic; + kvmPublicNic = _kvmPublicNic; + kvmGuestNic = _kvmGuestNic; + } + + if (kvmPublicNic == null) { + kvmPublicNic = (kvmGuestNic != null) ? kvmGuestNic : kvmPrivateNic; + } + + if (kvmPrivateNic == null) { + kvmPrivateNic = (kvmPublicNic != null) ? kvmPublicNic : kvmGuestNic; + } + + if (kvmGuestNic == null) { + kvmGuestNic = (kvmPublicNic != null) ? kvmPublicNic : kvmPrivateNic; + } - if (kvmPrivateNic == null && kvmPublicNic == null && kvmGuestNic == null) { - kvmPrivateNic = _kvmPrivateNic; - kvmPublicNic = _kvmPublicNic; - kvmGuestNic = _kvmGuestNic; - } - - if (kvmPublicNic == null) { - kvmPublicNic = (kvmGuestNic != null) ? kvmGuestNic : kvmPrivateNic; - } - - if (kvmPrivateNic == null) { - kvmPrivateNic = (kvmPublicNic != null) ? kvmPublicNic : kvmGuestNic; - } - - if (kvmGuestNic == null) { - kvmGuestNic = (kvmPublicNic != null) ? kvmPublicNic : kvmPrivateNic; - } - String parameters = " -m " + _hostIp + " -z " + dcId + " -p " + podId + " -c " + clusterId + " -g " + guid + " -a"; parameters += " --pubNic=" + kvmPublicNic; parameters += " --prvNic=" + kvmPrivateNic; parameters += " --guestNic=" + kvmGuestNic; - SSHCmdHelper.sshExecuteCmd(sshConnection, "cloud-setup-agent " + parameters, 3); - - KvmDummyResourceBase kvmResource = new KvmDummyResourceBase(); - Map params = new HashMap(); - - 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 hostDetails = connectedHost.getDetails(); - hostDetails.put("password", password); - hostDetails.put("username", username); - _hostDao.saveDetails(connectedHost); - return resources; - } catch (DiscoveredWithErrorException e){ - throw e; - }catch (Exception e) { - String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage(); - s_logger.warn(msg); - } finally { - if (sshConnection != null) - sshConnection.close(); - } - - return null; - } + SSHCmdHelper.sshExecuteCmd(sshConnection, "cloud-setup-agent " + parameters, 3); - private HostVO waitForHostConnect(long dcId, long podId, long clusterId, String guid) { - for (int i = 0; i < _waitTime *2; i++) { - List 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 hosts = _resourceMgr.findHostByGuid(dcId, guid); - if (hosts.size() == 1) { - return hosts.get(0); - } else { - return null; - } - } - - @Override + KvmDummyResourceBase kvmResource = new KvmDummyResourceBase(); + Map params = new HashMap(); + + 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 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 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 hosts = _resourceMgr.findHostByGuid(dcId, guid); + if (hosts.size() == 1) { + return hosts.get(0); + } else { + return null; + } + } + + @Override public boolean configure(String name, Map params) throws ConfigurationException { - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - _configDao = locator.getDao(ConfigurationDao.class); - _kvmPrivateNic = _configDao.getValue(Config.KvmPrivateNetwork.key()); - if (_kvmPrivateNic == null) { - _kvmPrivateNic = "cloudbr0"; - } - - _kvmPublicNic = _configDao.getValue(Config.KvmPublicNetwork.key()); - if (_kvmPublicNic == null) { - _kvmPublicNic = _kvmPrivateNic; - } - - _kvmGuestNic = _configDao.getValue(Config.KvmGuestNetwork.key()); - if (_kvmGuestNic == null) { - _kvmGuestNic = _kvmPrivateNic; - } - - _hostIp = _configDao.getValue("host"); - if (_hostIp == null) { - throw new ConfigurationException("Can't get host IP"); - } - _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); - return true; - } - - protected String getPatchPath() { +// _setupAgentPath = Script.findScript(getPatchPath(), "setup_agent.sh"); + _kvmPrivateNic = _configDao.getValue(Config.KvmPrivateNetwork.key()); + if (_kvmPrivateNic == null) { + _kvmPrivateNic = "cloudbr0"; + } + + _kvmPublicNic = _configDao.getValue(Config.KvmPublicNetwork.key()); + if (_kvmPublicNic == null) { + _kvmPublicNic = _kvmPrivateNic; + } + + _kvmGuestNic = _configDao.getValue(Config.KvmGuestNetwork.key()); + if (_kvmGuestNic == null) { + _kvmGuestNic = _kvmPrivateNic; + } + + _hostIp = _configDao.getValue("host"); + if (_hostIp == null) { + throw new ConfigurationException("Can't get host IP"); + } + _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); + return true; + } + + protected String getPatchPath() { return "scripts/vm/hypervisor/kvm/"; } - @Override - public void postDiscovery(List hosts, long msId) - throws DiscoveryException { - // TODO Auto-generated method stub - } - - public Hypervisor.HypervisorType getHypervisorType() { - return Hypervisor.HypervisorType.KVM; - } - @Override - public boolean matchHypervisor(String hypervisor) { - // for backwards compatibility, if not supplied, always let to try it - if(hypervisor == null) - return true; - - return Hypervisor.HypervisorType.KVM.toString().equalsIgnoreCase(hypervisor); + public void postDiscovery(List hosts, long msId) + throws DiscoveryException { + // TODO Auto-generated method stub } - @Override + @Override + public Hypervisor.HypervisorType getHypervisorType() { + return Hypervisor.HypervisorType.KVM; + } + + @Override + public boolean matchHypervisor(String hypervisor) { + // for backwards compatibility, if not supplied, always let to try it + if(hypervisor == null) + return true; + + return Hypervisor.HypervisorType.KVM.toString().equalsIgnoreCase(hypervisor); + } + + @Override public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { - StartupCommand firstCmd = cmd[0]; - if (!(firstCmd instanceof StartupRoutingCommand)) { - return null; - } + StartupCommand firstCmd = cmd[0]; + if (!(firstCmd instanceof StartupRoutingCommand)) { + return null; + } - StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd); - if (ssCmd.getHypervisorType() != HypervisorType.KVM) { - return null; - } + StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd); + if (ssCmd.getHypervisorType() != HypervisorType.KVM) { + return null; + } - /* KVM requires host are the same in cluster */ - ClusterVO clusterVO = _clusterDao.findById(host.getClusterId()); - List hostsInCluster = _resourceMgr.listAllHostsInCluster(clusterVO.getId()); - if (!hostsInCluster.isEmpty()) { - HostVO oneHost = hostsInCluster.get(0); - _hostDao.loadDetails(oneHost); - String hostOsInCluster = oneHost.getDetail("Host.OS"); - String hostOs = ssCmd.getHostDetails().get("Host.OS"); - if (!hostOsInCluster.equalsIgnoreCase(hostOs)) { - throw new IllegalArgumentException("Can't add host: " + firstCmd.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster," - + "in which there are " + hostOsInCluster + " hosts added"); - } - } - - _hostDao.loadDetails(host); - - return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.KVM, host.getDetails(), null); + /* KVM requires host are the same in cluster */ + ClusterVO clusterVO = _clusterDao.findById(host.getClusterId()); + List hostsInCluster = _resourceMgr.listAllHostsInCluster(clusterVO.getId()); + if (!hostsInCluster.isEmpty()) { + HostVO oneHost = hostsInCluster.get(0); + _hostDao.loadDetails(oneHost); + String hostOsInCluster = oneHost.getDetail("Host.OS"); + String hostOs = ssCmd.getHostDetails().get("Host.OS"); + if (!hostOsInCluster.equalsIgnoreCase(hostOs)) { + throw new IllegalArgumentException("Can't add host: " + firstCmd.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster," + + "in which there are " + hostOsInCluster + " hosts added"); + } + } + + _hostDao.loadDetails(host); + + return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.KVM, host.getDetails(), null); } - @Override + @Override public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map details, List hostTags) { - // TODO Auto-generated method stub - return null; + // TODO Auto-generated method stub + return null; } - @Override + @Override public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { if (host.getType() != Host.Type.Routing || host.getHypervisorType() != HypervisorType.KVM) { return null; } - + _resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage); try { ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null); @@ -388,15 +385,15 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer, } catch (OperationTimedoutException e) { s_logger.warn("Sending ShutdownCommand failed: ", e); } - + return new DeleteHostAnswer(true); } - + @Override public boolean stop() { - _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); + _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); return super.stop(); } - - + + } diff --git a/server/src/com/cloud/maint/UpgradeManagerImpl.java b/server/src/com/cloud/maint/UpgradeManagerImpl.java index 463761477aa..2f50dffad71 100644 --- a/server/src/com/cloud/maint/UpgradeManagerImpl.java +++ b/server/src/com/cloud/maint/UpgradeManagerImpl.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Properties; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.commons.httpclient.HttpClient; @@ -66,7 +67,8 @@ public class UpgradeManagerImpl implements UpgradeManager { String _agentPath; long _checkInterval; - AgentUpgradeDao _upgradeDao; + @Inject AgentUpgradeDao _upgradeDao; + @Inject ConfigurationDao _configDao; @Override public State registerForUpgrade(long hostId, String version) { @@ -151,18 +153,7 @@ public class UpgradeManagerImpl implements UpgradeManager { public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - final ComponentLocator locator = ComponentLocator.getCurrentLocator(); - _upgradeDao = locator.getDao(AgentUpgradeDao.class); - if (_upgradeDao == null) { - throw new ConfigurationException("Unable to retrieve the storage layer."); - } - - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - - final Map configs = configDao.getConfiguration("UpgradeManager", params); + final Map configs = _configDao.getConfiguration("UpgradeManager", params); File agentUpgradeFile = PropertiesUtil.findConfigFile("agent-update.properties"); Properties agentUpgradeProps = new Properties(); diff --git a/server/src/com/cloud/network/ExteralIpAddressAllocator.java b/server/src/com/cloud/network/ExteralIpAddressAllocator.java index b559086f9d0..f8b5c152519 100644 --- a/server/src/com/cloud/network/ExteralIpAddressAllocator.java +++ b/server/src/com/cloud/network/ExteralIpAddressAllocator.java @@ -144,8 +144,6 @@ public class ExteralIpAddressAllocator implements IpAddrAllocator{ @Override public boolean configure(String name, Map params) throws ConfigurationException { - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - _configDao = locator.getDao(ConfigurationDao.class); _isExternalIpAllocatorEnabled = Boolean.parseBoolean(_configDao.getValue("direct.attach.network.externalIpAllocator.enabled")); _externalIpAllocatorUrl = _configDao.getValue("direct.attach.network.externalIpAllocator.url"); _name = name; diff --git a/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java b/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java index 180468c97b5..e5ee604a2dd 100644 --- a/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java +++ b/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java @@ -57,6 +57,7 @@ public class FirewallRulesDaoImpl extends GenericDaoBase i @Inject protected FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao; @Inject ResourceTagsDaoImpl _tagsDao; + @Inject IPAddressDao _ipDao; protected FirewallRulesDaoImpl() { super(); @@ -184,8 +185,6 @@ public class FirewallRulesDaoImpl extends GenericDaoBase i @Override public List listStaticNatByVmId(long vmId) { - IPAddressDao _ipDao = ComponentLocator.getLocator("management-server").getDao(IPAddressDao.class); - if (VmSearch == null) { SearchBuilder IpSearch = _ipDao.createSearchBuilder(); IpSearch.and("associatedWithVmId", IpSearch.entity().getAssociatedWithVmId(), SearchCriteria.Op.EQ); diff --git a/server/src/com/cloud/network/guru/ControlNetworkGuru.java b/server/src/com/cloud/network/guru/ControlNetworkGuru.java index 471261dbde0..1195f682819 100755 --- a/server/src/com/cloud/network/guru/ControlNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ControlNetworkGuru.java @@ -61,6 +61,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu private static final Logger s_logger = Logger.getLogger(ControlNetworkGuru.class); @Inject DataCenterDao _dcDao; @Inject NetworkManager _networkMgr; + @Inject ConfigurationDao _configDao; String _cidr; String _gateway; @@ -211,10 +212,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - Map dbParams = configDao.getConfiguration(params); + Map dbParams = _configDao.getConfiguration(params); _cidr = dbParams.get(Config.ControlCidr); if (_cidr == null) { diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 875303f0443..85e86f6dfd2 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -591,8 +591,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _checkExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterStatusMonitor")); _networkStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("NetworkStatsUpdater")); - final ComponentLocator locator = ComponentLocator.getCurrentLocator(); - final Map configs = _configDao.getConfiguration("AgentManager", params); _mgmt_host = configs.get("host"); @@ -643,11 +641,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.info("Router configurations: " + "ramsize=" + _routerRamSize); - final UserStatisticsDao statsDao = locator.getDao(UserStatisticsDao.class); - if (statsDao == null) { - throw new ConfigurationException("Unable to get " + UserStatisticsDao.class.getName()); - } - _agentMgr.registerForHostEvents(new SshKeysDistriMonitor(_agentMgr, _hostDao, _configDao), true, false, false); _itMgr.registerGuru(VirtualMachine.Type.DomainRouter, this); diff --git a/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java b/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java index 0b0a34773c5..0a0844fc3bc 100755 --- a/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java +++ b/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java @@ -162,6 +162,9 @@ public class SecurityGroupManagerImpl implements SecurityGroupManager, SecurityG @Inject ResourceTagDao _resourceTagDao; + @Inject + ManagementServer _msServer; + ScheduledExecutorService _executorPool; ScheduledExecutorService _cleanupExecutor; @@ -861,8 +864,7 @@ public class SecurityGroupManagerImpl implements SecurityGroupManager, SecurityG _answerListener = new SecurityGroupListener(this, _agentMgr, _workDao); _agentMgr.registerForHostEvents(_answerListener, true, true, true); - - _serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId(); + _serverId = _msServer.getId(); s_logger.info("SecurityGroupManager: num worker threads=" + _numWorkerThreads + ", time between cleanups=" + _timeBetweenCleanups + " global lock timeout=" + _globalWorkLockTimeout); diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 1412d08d706..58c497e7327 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -207,9 +207,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ txn.commit(); - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - Map configs = configDao.getConfiguration(params); + Map configs = _configDao.getConfiguration(params); String value = configs.get(Config.VpcCleanupInterval.key()); _cleanupInterval = NumbersUtil.parseInt(value, 60 * 60); // 1 hour diff --git a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java index 76bf057f4c7..ad75502db42 100755 --- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java @@ -99,6 +99,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag @Inject FirewallRulesDao _rulesDao; @Inject FirewallManager _firewallMgr; @Inject UsageEventDao _usageEventDao; + @Inject ConfigurationDao _configDao; int _userLimit; int _pskLength; @@ -585,9 +586,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - Map configs = configDao.getConfiguration(params); + Map configs = _configDao.getConfiguration(params); _userLimit = NumbersUtil.parseInt(configs.get(Config.RemoteAccessVpnUserLimit.key()), 8); diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java index 9b2c04946bd..d8371c44b17 100644 --- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java @@ -93,6 +93,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager { @Inject VpcDao _vpcDao; @Inject IPAddressDao _ipAddressDao; @Inject AccountDao _accountDao; + @Inject ConfigurationDao _configDao; @Inject VpcManager _vpcMgr; @Inject AccountManager _accountMgr; @@ -104,9 +105,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager { public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - Map configs = configDao.getConfiguration(params); + Map configs = _configDao.getConfiguration(params); _connLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnConnectionPerVpnGatewayLimit.key()), 4); _subnetsLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnSubnetsPerCustomerGatewayLimit.key()), 10); return true; diff --git a/server/src/com/cloud/resource/DiscovererBase.java b/server/src/com/cloud/resource/DiscovererBase.java index 01dd126dc09..6f6d1bace00 100644 --- a/server/src/com/cloud/resource/DiscovererBase.java +++ b/server/src/com/cloud/resource/DiscovererBase.java @@ -48,8 +48,7 @@ public abstract class DiscovererBase implements Discoverer { @Override public boolean configure(String name, Map params) throws ConfigurationException { - ConfigurationDao dao = ComponentLocator.getCurrentLocator().getDao(ConfigurationDao.class); - _params = dao.getConfiguration(params); + _params = _configDao.getConfiguration(params); _name = name; return true; diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 78c24692fe0..ef36a829ccb 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -329,6 +329,8 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag protected ResourceTagDao _resourceTagDao; @Inject protected List _storagePoolAllocators; + @Inject ConfigurationDao _configDao; + @Inject ManagementServer _msServer; // TODO : we don't have any instantiated pool discover, disable injection temporarily // @Inject @@ -941,15 +943,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - s_logger.error("Unable to get the configuration dao."); - return false; - } - - Map configs = configDao.getConfiguration("management-server", params); + Map configs = _configDao.getConfiguration("management-server", params); String overProvisioningFactorStr = configs.get("storage.overprovisioning.factor"); if (overProvisioningFactorStr != null) { @@ -967,27 +961,27 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag String storageCleanupEnabled = configs.get("storage.cleanup.enabled"); _storageCleanupEnabled = (storageCleanupEnabled == null) ? true : Boolean.parseBoolean(storageCleanupEnabled); - String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString()); + String value = _configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString()); _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue())); - value = configDao.getValue(Config.CopyVolumeWait.toString()); + value = _configDao.getValue(Config.CopyVolumeWait.toString()); _copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue())); - value = configDao.getValue(Config.RecreateSystemVmEnabled.key()); + value = _configDao.getValue(Config.RecreateSystemVmEnabled.key()); _recreateSystemVmEnabled = Boolean.parseBoolean(value); - value = configDao.getValue(Config.StorageTemplateCleanupEnabled.key()); + value = _configDao.getValue(Config.StorageTemplateCleanupEnabled.key()); _templateCleanupEnabled = (value == null ? true : Boolean.parseBoolean(value)); String time = configs.get("storage.cleanup.interval"); _storageCleanupInterval = NumbersUtil.parseInt(time, 86400); - String storageUsedThreshold = configDao.getValue(Config.StorageCapacityDisableThreshold.key()); + String storageUsedThreshold = _configDao.getValue(Config.StorageCapacityDisableThreshold.key()); if (storageUsedThreshold != null) { _storageUsedThreshold = Double.parseDouble(storageUsedThreshold); } - String storageAllocatedThreshold = configDao.getValue(Config.StorageAllocatedCapacityDisableThreshold.key()); + String storageAllocatedThreshold = _configDao.getValue(Config.StorageAllocatedCapacityDisableThreshold.key()); if (storageAllocatedThreshold != null) { _storageAllocatedThreshold = Double.parseDouble(storageAllocatedThreshold); } @@ -1003,13 +997,13 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag _agentMgr.registerForHostEvents(ComponentLocator.inject(LocalStoragePoolListener.class), true, false, false); - String maxVolumeSizeInGbString = configDao.getValue("storage.max.volume.size"); + String maxVolumeSizeInGbString = _configDao.getValue("storage.max.volume.size"); _maxVolumeSizeInGb = NumbersUtil.parseLong(maxVolumeSizeInGbString, 2000); - String _customDiskOfferingMinSizeStr = configDao.getValue(Config.CustomDiskOfferingMinSize.toString()); + String _customDiskOfferingMinSizeStr = _configDao.getValue(Config.CustomDiskOfferingMinSize.toString()); _customDiskOfferingMinSize = NumbersUtil.parseInt(_customDiskOfferingMinSizeStr, Integer.parseInt(Config.CustomDiskOfferingMinSize.getDefaultValue())); - String _customDiskOfferingMaxSizeStr = configDao.getValue(Config.CustomDiskOfferingMaxSize.toString()); + String _customDiskOfferingMaxSizeStr = _configDao.getValue(Config.CustomDiskOfferingMaxSize.toString()); _customDiskOfferingMaxSize = NumbersUtil.parseInt(_customDiskOfferingMaxSizeStr, Integer.parseInt(Config.CustomDiskOfferingMaxSize.getDefaultValue())); HostTemplateStatesSearch = _vmTemplateHostDao.createSearchBuilder(); @@ -1023,7 +1017,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag HostSearch.done(); HostTemplateStatesSearch.done(); - _serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId(); + _serverId = _msServer.getId(); UpHostsInPoolSearch = _storagePoolHostDao.createSearchBuilder(Long.class); UpHostsInPoolSearch.selectField(UpHostsInPoolSearch.entity().getHostId()); diff --git a/server/src/com/cloud/storage/allocator/GarbageCollectingStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/GarbageCollectingStoragePoolAllocator.java index a6d227bd312..3e1030d077c 100644 --- a/server/src/com/cloud/storage/allocator/GarbageCollectingStoragePoolAllocator.java +++ b/server/src/com/cloud/storage/allocator/GarbageCollectingStoragePoolAllocator.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; @@ -42,8 +43,8 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl StoragePoolAllocator _firstFitStoragePoolAllocator; StoragePoolAllocator _localStoragePoolAllocator; - StorageManager _storageMgr; - ConfigurationDao _configDao; + @Inject StorageManager _storageMgr; + @Inject ConfigurationDao _configDao; boolean _storagePoolCleanupEnabled; @Override @@ -94,16 +95,6 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl _localStoragePoolAllocator = ComponentLocator.inject(LocalStoragePoolAllocator.class); _localStoragePoolAllocator.configure("GCLocalStoragePoolAllocator", params); - _storageMgr = locator.getManager(StorageManager.class); - if (_storageMgr == null) { - throw new ConfigurationException("Unable to get " + StorageManager.class.getName()); - } - - _configDao = locator.getDao(ConfigurationDao.class); - if (_configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - String storagePoolCleanupEnabled = _configDao.getValue("storage.pool.cleanup.enabled"); _storagePoolCleanupEnabled = (storagePoolCleanupEnabled == null) ? true : Boolean.parseBoolean(storagePoolCleanupEnabled); diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 31beeafe90d..6afcf32d6ab 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -793,27 +793,21 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - - Map configs = configDao.getConfiguration("management-server", params); + Map configs = _configDao.getConfiguration("management-server", params); _secStorageVmMtuSize = NumbersUtil.parseInt(configs.get("secstorage.vm.mtu.size"), DEFAULT_SS_VM_MTUSIZE); - String useServiceVM = configDao.getValue("secondary.storage.vm"); + String useServiceVM = _configDao.getValue("secondary.storage.vm"); boolean _useServiceVM = false; if ("true".equalsIgnoreCase(useServiceVM)) { _useServiceVM = true; } - String sslcopy = configDao.getValue("secstorage.encrypt.copy"); + String sslcopy = _configDao.getValue("secstorage.encrypt.copy"); if ("true".equalsIgnoreCase(sslcopy)) { _useSSlCopy = true; } - _allowedInternalSites = configDao.getValue("secstorage.allowed.internal.sites"); + _allowedInternalSites = _configDao.getValue("secstorage.allowed.internal.sites"); String value = configs.get("secstorage.capacityscan.interval"); _capacityScanInterval = NumbersUtil.parseLong(value, DEFAULT_CAPACITY_SCAN_INTERVAL); @@ -823,7 +817,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V _instance = "DEFAULT"; } - Map agentMgrConfigs = configDao.getConfiguration("AgentManager", params); + Map agentMgrConfigs = _configDao.getConfiguration("AgentManager", params); _mgmt_host = agentMgrConfigs.get("host"); if (_mgmt_host == null) { s_logger.warn("Critical warning! Please configure your management server host address right after you have started your management server and then restart it, otherwise you won't have access to secondary storage"); diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index c4029ea8ffb..fb4ece5187c 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -189,6 +189,8 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma private VolumeDao _volumeDao; @Inject private ResourceTagDao _resourceTagDao; + @Inject + private ConfigurationDao _configDao; String _name; private int _totalRetries; @@ -1432,23 +1434,16 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - throw new ConfigurationException("Unable to get the configuration dao."); - } - - String value = configDao.getValue(Config.BackupSnapshotWait.toString()); + String value = _configDao.getValue(Config.BackupSnapshotWait.toString()); _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue())); - Type.HOURLY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.hourly"), HOURLYMAX)); - Type.DAILY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.daily"), DAILYMAX)); - Type.WEEKLY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.weekly"), WEEKLYMAX)); - Type.MONTHLY.setMax(NumbersUtil.parseInt(configDao.getValue("snapshot.max.monthly"), MONTHLYMAX)); - _deltaSnapshotMax = NumbersUtil.parseInt(configDao.getValue("snapshot.delta.max"), DELTAMAX); - _totalRetries = NumbersUtil.parseInt(configDao.getValue("total.retries"), 4); - _pauseInterval = 2 * NumbersUtil.parseInt(configDao.getValue("ping.interval"), 60); + Type.HOURLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.hourly"), HOURLYMAX)); + Type.DAILY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.daily"), DAILYMAX)); + Type.WEEKLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.weekly"), WEEKLYMAX)); + Type.MONTHLY.setMax(NumbersUtil.parseInt(_configDao.getValue("snapshot.max.monthly"), MONTHLYMAX)); + _deltaSnapshotMax = NumbersUtil.parseInt(_configDao.getValue("snapshot.delta.max"), DELTAMAX); + _totalRetries = NumbersUtil.parseInt(_configDao.getValue("total.retries"), 4); + _pauseInterval = 2 * NumbersUtil.parseInt(_configDao.getValue("ping.interval"), 60); s_logger.info("Snapshot Manager is configured."); diff --git a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java index c6fc5308070..190b054a1d0 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java @@ -74,7 +74,8 @@ public class SnapshotSchedulerImpl implements SnapshotScheduler { @Inject protected SnapshotPolicyDao _snapshotPolicyDao; @Inject protected AsyncJobManager _asyncMgr; @Inject protected VolumeDao _volsDao; - + @Inject protected ConfigurationDao _configDao; + private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 5; // 5 seconds private int _snapshotPollInterval; private Timer _testClockTimer; @@ -336,23 +337,16 @@ public class SnapshotSchedulerImpl implements SnapshotScheduler { throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - s_logger.error("Unable to get the configuration dao. " + ConfigurationDao.class.getName()); - return false; - } - _snapshotPollInterval = NumbersUtil.parseInt(configDao.getValue("snapshot.poll.interval"), 300); - boolean snapshotsRecurringTest = Boolean.parseBoolean(configDao.getValue("snapshot.recurring.test")); + _snapshotPollInterval = NumbersUtil.parseInt(_configDao.getValue("snapshot.poll.interval"), 300); + boolean snapshotsRecurringTest = Boolean.parseBoolean(_configDao.getValue("snapshot.recurring.test")); if (snapshotsRecurringTest) { // look for some test values in the configuration table so that snapshots can be taken more frequently (QA test code) - int minutesPerHour = NumbersUtil.parseInt(configDao.getValue("snapshot.test.minutes.per.hour"), 60); - int hoursPerDay = NumbersUtil.parseInt(configDao.getValue("snapshot.test.hours.per.day"), 24); - int daysPerWeek = NumbersUtil.parseInt(configDao.getValue("snapshot.test.days.per.week"), 7); - int daysPerMonth = NumbersUtil.parseInt(configDao.getValue("snapshot.test.days.per.month"), 30); - int weeksPerMonth = NumbersUtil.parseInt(configDao.getValue("snapshot.test.weeks.per.month"), 4); - int monthsPerYear = NumbersUtil.parseInt(configDao.getValue("snapshot.test.months.per.year"), 12); + int minutesPerHour = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.minutes.per.hour"), 60); + int hoursPerDay = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.hours.per.day"), 24); + int daysPerWeek = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.week"), 7); + int daysPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.month"), 30); + int weeksPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.weeks.per.month"), 4); + int monthsPerYear = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.months.per.year"), 12); _testTimerTask = new TestClock(this, minutesPerHour, hoursPerDay, daysPerWeek, daysPerMonth, weeksPerMonth, monthsPerYear); } diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 7cce9a764b7..0e914725e16 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -1066,8 +1066,6 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - final Map configs = _configDao.getConfiguration("AgentManager", params); _routerTemplateId = NumbersUtil.parseInt(configs.get("router.template.id"), 1); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index c238efb1953..b90413218de 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -248,9 +248,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag throw new ConfigurationException("Unable to find the system user using " + User.UID_SYSTEM); } - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - Map configs = configDao.getConfiguration(params); + Map configs = _configDao.getConfiguration(params); String loginAttempts = configs.get(Config.IncorrectLoginAttemptsAllowed.key()); _allowedLoginAttempts = NumbersUtil.parseInt(loginAttempts, 5); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 61526a69baa..d4fff18c847 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -54,7 +54,6 @@ import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity; import org.apache.cloudstack.engine.service.api.OrchestrationService; import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -237,7 +236,6 @@ import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; import com.cloud.vm.dao.VMInstanceDao; -@Component @Local(value = { UserVmManager.class, UserVmService.class }) public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager { private static final Logger s_logger = Logger @@ -4547,5 +4545,4 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager @Override public void prepareStop(VirtualMachineProfile profile) { } - } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 2eb49598cd8..2897a63afed 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; -import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -141,8 +140,6 @@ import com.cloud.utils.Journal; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.Ternary; -import com.cloud.utils.component.Adapters; -import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; import com.cloud.utils.db.GlobalLock; @@ -239,6 +236,9 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene @Inject protected ResourceManager _resourceMgr; + @Inject + protected ConfigurationDao _configDao; + Map> _vmGurus = new HashMap>(); protected StateMachine2 _stateMachine; @@ -428,9 +428,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene public boolean configure(String name, Map xmlParams) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - Map params = configDao.getConfiguration(xmlParams); + Map params = _configDao.getConfiguration(xmlParams); _retry = NumbersUtil.parseInt(params.get(Config.StartRetry.key()), 10); diff --git a/server/src/com/cloud/vm/dao/UserVmDaoImpl.java b/server/src/com/cloud/vm/dao/UserVmDaoImpl.java index 12844089bb0..8eda2e24ba1 100755 --- a/server/src/com/cloud/vm/dao/UserVmDaoImpl.java +++ b/server/src/com/cloud/vm/dao/UserVmDaoImpl.java @@ -284,7 +284,6 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use @Override public List listByNetworkIdAndStates(long networkId, State... states) { if (UserVmSearch == null) { - NicDao _nicDao = ComponentLocator.getLocator("management-server").getDao(NicDao.class); SearchBuilder nicSearch = _nicDao.createSearchBuilder(); nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); nicSearch.and("ip4Address", nicSearch.entity().getIp4Address(), SearchCriteria.Op.NNULL); diff --git a/usage/src/com/cloud/usage/UsageAlertManagerImpl.java b/usage/src/com/cloud/usage/UsageAlertManagerImpl.java index 6d46262eb2a..2b698c83708 100644 --- a/usage/src/com/cloud/usage/UsageAlertManagerImpl.java +++ b/usage/src/com/cloud/usage/UsageAlertManagerImpl.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Properties; import javax.ejb.Local; +import javax.inject.Inject; import javax.mail.Authenticator; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; @@ -32,6 +33,7 @@ import javax.mail.internet.InternetAddress; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; import com.cloud.alert.AlertManager; import com.cloud.alert.AlertVO; @@ -43,26 +45,21 @@ import com.sun.mail.smtp.SMTPMessage; import com.sun.mail.smtp.SMTPSSLTransport; import com.sun.mail.smtp.SMTPTransport; +@Component @Local(value={AlertManager.class}) public class UsageAlertManagerImpl implements AlertManager { private static final Logger s_logger = Logger.getLogger(UsageAlertManagerImpl.class.getName()); private String _name = null; private EmailAlert _emailAlert; - private AlertDao _alertDao; + @Inject private AlertDao _alertDao; + @Inject private ConfigurationDao _configDao; @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); - if (configDao == null) { - s_logger.error("Unable to get the configuration dao."); - return false; - } - - Map configs = configDao.getConfiguration("management-server", params); + Map configs = _configDao.getConfiguration("management-server", params); // set up the email system for alerts String emailAddressList = configs.get("alert.email.addresses"); @@ -85,14 +82,7 @@ public class UsageAlertManagerImpl implements AlertManager { } _emailAlert = new EmailAlert(emailAddresses, smtpHost, smtpPort, useAuth, smtpUsername, smtpPassword, emailSender, smtpDebug); - - _alertDao = locator.getDao(AlertDao.class); - if (_alertDao == null) { - s_logger.error("Unable to get the alert dao."); - return false; - } - - return true; + return true; } @Override diff --git a/usage/src/com/cloud/usage/UsageManagerImpl.java b/usage/src/com/cloud/usage/UsageManagerImpl.java index 53ebb143948..bbf2cd65ba8 100644 --- a/usage/src/com/cloud/usage/UsageManagerImpl.java +++ b/usage/src/com/cloud/usage/UsageManagerImpl.java @@ -124,7 +124,7 @@ public class UsageManagerImpl implements UsageManager, Runnable { private Future m_heartbeat = null; private Future m_sanity = null; - protected UsageManagerImpl() { + public UsageManagerImpl() { } private void mergeConfigs(Map dbParams, Map xmlParams) { diff --git a/utils/src/com/cloud/utils/component/ComponentContext.java b/utils/src/com/cloud/utils/component/ComponentContext.java index 5d3f8c67462..ce464232417 100644 --- a/utils/src/com/cloud/utils/component/ComponentContext.java +++ b/utils/src/com/cloud/utils/component/ComponentContext.java @@ -23,7 +23,6 @@ import org.apache.log4j.Logger; import org.springframework.aop.Advisor; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -85,9 +84,21 @@ public class ComponentContext implements ApplicationContextAware { } public static boolean isPrimary(Object instance, Class beanType) { - Map 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 matchedTypes = (Map)ComponentContext.getComponentsOfType(componentType); if(matchedTypes.size() > 1) { - Primary primary = getTargetClass(instance).getAnnotation(Primary.class); + Primary primary = targetClass.getAnnotation(Primary.class); if(primary != null) return true; @@ -96,7 +107,7 @@ public class ComponentContext implements ApplicationContextAware { return true; } - + public static Class getTargetClass(Object instance) { if(instance instanceof Advised) { try { diff --git a/utils/src/com/cloud/utils/component/ComponentLocator.java b/utils/src/com/cloud/utils/component/ComponentLocator.java index 90118b65520..d8d6e63b199 100644 --- a/utils/src/com/cloud/utils/component/ComponentLocator.java +++ b/utils/src/com/cloud/utils/component/ComponentLocator.java @@ -24,7 +24,6 @@ import com.cloud.utils.db.GenericDao; @Component public class ComponentLocator { - public static ComponentLocator getCurrentLocator() { return ComponentContext.getCompanent(ComponentLocator.class); }