cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [1/11] git commit: Replace Adapters and PluggableServices, use Spring to load them
Date Wed, 07 Nov 2012 23:03:46 GMT
Updated Branches:
  refs/heads/javelin 17c82b727 -> d79f1f6fd


Replace Adapters and PluggableServices, use Spring to load them


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/d79f1f6f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/d79f1f6f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/d79f1f6f

Branch: refs/heads/javelin
Commit: d79f1f6fdc8307aa4038bfb2c7607904b89eedbe
Parents: 453b31f
Author: Kelven Yang <kelveny@gmail.com>
Authored: Mon Nov 5 18:17:22 2012 -0800
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Wed Nov 7 15:03:24 2012 -0800

----------------------------------------------------------------------
 .../storage/template/DownloadManagerImpl.java      |    2 +-
 .../com/cloud/agent/manager/AgentManagerImpl.java  |    4 +-
 server/src/com/cloud/api/ApiServer.java            |    9 +++-
 .../src/com/cloud/cluster/ClusterManagerImpl.java  |   11 ++---
 .../configuration/DefaultComponentLibrary.java     |    2 +-
 .../consoleproxy/ConsoleProxyManagerImpl.java      |   17 +++-----
 .../com/cloud/ha/HighAvailabilityManagerImpl.java  |   28 +++++--------
 .../hypervisor/HypervisorGuruManagerImpl.java      |   20 +++++----
 .../com/cloud/migration/Db21to22MigrationUtil.java |   33 ++++++---------
 .../src/com/cloud/server/ManagementServerImpl.java |   14 ++----
 server/src/com/cloud/user/AccountManagerImpl.java  |   16 +++----
 .../com/cloud/utils/db/DbAnnotatedBaseDerived.java |    2 +-
 .../utils/db/TransactionContextBuilderTest.java    |   19 ++++++++-
 13 files changed, 87 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/core/src/com/cloud/storage/template/DownloadManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/template/DownloadManagerImpl.java b/core/src/com/cloud/storage/template/DownloadManagerImpl.java
index ab81bed..f8b075d 100755
--- a/core/src/com/cloud/storage/template/DownloadManagerImpl.java
+++ b/core/src/com/cloud/storage/template/DownloadManagerImpl.java
@@ -63,7 +63,7 @@ import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.component.Adapter;
 import com.cloud.utils.component.Adapters;
 import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.component.ComponentLocator.ComponentInfo;
+import com.cloud.utils.component.LegacyComponentLocator.ComponentInfo;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.OutputInterpreter;
 import com.cloud.utils.script.Script;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/agent/manager/AgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java
index 1ce99fb..d37bd15 100755
--- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java
+++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java
@@ -218,7 +218,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory,
Manager {
 
     protected int _pingInterval;
     protected long _pingTimeout;
-    protected AgentMonitor _monitor = null;
+    @Inject protected AgentMonitor _monitor = null;
 
     protected ExecutorService _executor;
     
@@ -272,7 +272,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory,
Manager {
         long lastPing = (System.currentTimeMillis() >> 10) - _pingTimeout;
         _hostDao.markHostsAsDisconnected(_nodeId, lastPing);
 
-        _monitor = ComponentLocator.inject(AgentMonitor.class, _nodeId, _hostDao, _vmDao,
_dcDao, _podDao, this, _alertMgr, _pingTimeout);
+        // _monitor = ComponentLocator.inject(AgentMonitor.class, _nodeId, _hostDao, _vmDao,
_dcDao, _podDao, this, _alertMgr, _pingTimeout);
         registerForHostEvents(_monitor, true, true, false);
 
         _executor = new ThreadPoolExecutor(threads, threads, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
new NamedThreadFactory("AgentTaskPool"));

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index eb5e770..f7786f4 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -50,6 +50,7 @@ import java.util.concurrent.TimeUnit;
 
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
+import javax.inject.Inject;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
@@ -80,6 +81,7 @@ import org.apache.http.protocol.ResponseContent;
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.api.response.ApiResponseSerializer;
 import com.cloud.api.response.ExceptionResponse;
@@ -116,6 +118,7 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CSExceptionErrorCode;
 import com.cloud.uuididentity.dao.IdentityDao;
 
+@Component
 public class ApiServer implements HttpRequestHandler {
     private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
     private static final Logger s_accessLogger = Logger.getLogger("apiserver." + ApiServer.class.getName());
@@ -133,6 +136,8 @@ public class ApiServer implements HttpRequestHandler {
     private AsyncJobManager _asyncMgr = null;
     private Account _systemAccount = null;
     private User _systemUser = null;
+    
+    @Inject List<PluggableService> _pluggableServices;
 
     private static int _workerCount = 0;
 
@@ -187,9 +192,7 @@ public class ApiServer implements HttpRequestHandler {
     private String[] getPluggableServicesApiConfigs() {
         List<String> pluggableServicesApiConfigs = new ArrayList<String>();
 
-        ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
-        List<PluggableService> services = locator.getAllPluggableServices();
-        for (PluggableService service : services) {
+        for (PluggableService service : _pluggableServices) {
             pluggableServicesApiConfigs.add(service.getPropertiesFile());
         }
         return pluggableServicesApiConfigs.toArray(new String[0]);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/cluster/ClusterManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/ClusterManagerImpl.java b/server/src/com/cloud/cluster/ClusterManagerImpl.java
index ff7d6b5..9cb7891 100755
--- a/server/src/com/cloud/cluster/ClusterManagerImpl.java
+++ b/server/src/com/cloud/cluster/ClusterManagerImpl.java
@@ -121,6 +121,9 @@ public class ClusterManagerImpl implements ClusterManager {
     private final ExecutorService _executor;
 
     private ClusterServiceAdapter _currentServiceAdapter;
+   
+    @Inject
+    private List<ClusterServiceAdapter> _serviceAdapters;
 
     private ManagementServerHostDao _mshostDao;
     private ManagementServerHostPeerDao _mshostPeerDao;
@@ -1306,14 +1309,10 @@ public class ClusterManagerImpl implements ClusterManager {
         // notification task itself in turn works as a task dispatcher
         _executor.execute(getClusterPduNotificationTask());
 
-        Adapters<ClusterServiceAdapter> adapters = locator.getAdapters(ClusterServiceAdapter.class);
-        if (adapters == null || !adapters.isSet()) {
+        if (_serviceAdapters == null) {
             throw new ConfigurationException("Unable to get cluster service adapters");
         }
-        Enumeration<ClusterServiceAdapter> it = adapters.enumeration();
-        if(it.hasMoreElements()) {
-            _currentServiceAdapter = it.nextElement();
-        }
+        _currentServiceAdapter = _serviceAdapters.get(0);
 
         if(_currentServiceAdapter == null) {
             throw new ConfigurationException("Unable to set current cluster service adapter");

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/configuration/DefaultComponentLibrary.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java
index 4edd402..e5482d2 100755
--- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java
+++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java
@@ -179,7 +179,7 @@ import com.cloud.user.dao.UserStatsLogDaoImpl;
 import com.cloud.utils.component.Adapter;
 import com.cloud.utils.component.ComponentLibrary;
 import com.cloud.utils.component.ComponentLibraryBase;
-import com.cloud.utils.component.ComponentLocator.ComponentInfo;
+import com.cloud.utils.component.LegacyComponentLocator.ComponentInfo;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.PluggableService;
 import com.cloud.utils.db.GenericDao;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index 0bf2c96..154204b 100755
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -187,7 +187,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
     private int _mgmt_port = 8250;
 
     private String _name;
-    private Adapters<ConsoleProxyAllocator> _consoleProxyAllocators;
+    @Inject
+    private List<ConsoleProxyAllocator> _consoleProxyAllocators;
 
     @Inject
     private ConsoleProxyDao _consoleProxyDao;
@@ -806,11 +807,10 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager,
ConsoleProx
 
     private ConsoleProxyAllocator getCurrentAllocator() {
         // for now, only one adapter is supported
-        Enumeration<ConsoleProxyAllocator> it = _consoleProxyAllocators.enumeration();
-        if (it.hasMoreElements()) {
-            return it.nextElement();
-        }
-
+    	for(ConsoleProxyAllocator allocator : _consoleProxyAllocators) {
+    		return allocator;
+    	}
+    	
         return null;
     }
 
@@ -1512,11 +1512,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager,
ConsoleProx
         value = agentMgrConfigs.get("port");
         _mgmt_port = NumbersUtil.parseInt(value, 8250);
 
-        _consoleProxyAllocators = locator.getAdapters(ConsoleProxyAllocator.class);
-        if (_consoleProxyAllocators == null || !_consoleProxyAllocators.isSet()) {
-            throw new ConfigurationException("Unable to get proxy allocators");
-        }
-
         _listener = new ConsoleProxyListener(this);
         _agentMgr.registerForHostEvents(_listener, true, true, false);
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
index a4ca2cf..31f049f 100755
--- a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
+++ b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
@@ -120,10 +120,11 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager,
Clu
     @Inject
     ClusterDetailsDao _clusterDetailsDao;
     long _serverId;
-    @com.cloud.utils.component.Inject(adapter = Investigator.class)
-    Adapters<Investigator> _investigators;
-    @com.cloud.utils.component.Inject(adapter = FenceBuilder.class)
-    Adapters<FenceBuilder> _fenceBuilders;
+
+    @Inject
+    List<Investigator> _investigators;
+    @Inject
+    List<FenceBuilder> _fenceBuilders;
     @Inject
     AgentManager _agentMgr;
     @Inject
@@ -164,11 +165,8 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager,
Clu
             return null;
         }
 
-        final Enumeration<Investigator> en = _investigators.enumeration();
         Status hostState = null;
-        Investigator investigator = null;
-        while (en.hasMoreElements()) {
-            investigator = en.nextElement();
+        for(Investigator investigator : _investigators) {
             hostState = investigator.isAgentAlive(host);
             if (hostState != null) {
                 if (s_logger.isDebugEnabled()) {
@@ -419,22 +417,20 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager,
Clu
                     return null;
                 }
 
-                Enumeration<Investigator> en = _investigators.enumeration();
                 Investigator investigator = null;
-                while (en.hasMoreElements()) {
-                    investigator = en.nextElement();
+                for(Investigator it : _investigators) {
+                	investigator = it;
                     alive = investigator.isVmAlive(vm, host);
                     s_logger.info(investigator.getName() + " found " + vm + "to be alive?
" + alive);
                     if (alive != null) {
                         break;
                     }
                 }
+                
                 boolean fenced = false;
                 if (alive == null) {
                     s_logger.debug("Fencing off VM that we don't know the state of");
-                    Enumeration<FenceBuilder> enfb = _fenceBuilders.enumeration();
-                    while (enfb.hasMoreElements()) {
-                        FenceBuilder fb = enfb.nextElement();
+                    for(FenceBuilder fb : _fenceBuilders) {
                         Boolean result = fb.fenceOff(vm, host);
                         s_logger.info("Fencer " + fb.getName() + " returned " + result);
                         if (result != null && result) {
@@ -442,6 +438,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager,
Clu
                             break;
                         }
                     }
+                    
                 } else if (!alive) {
                     fenced = true;
                 } else {
@@ -697,9 +694,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager,
Clu
 
         _serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId();
 
-        _investigators = locator.getAdapters(Investigator.class);
-        _fenceBuilders = locator.getAdapters(FenceBuilder.class);
-
         Map<String, String> params = new HashMap<String, String>();
         final ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
         if (configDao != null) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/hypervisor/HypervisorGuruManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruManagerImpl.java b/server/src/com/cloud/hypervisor/HypervisorGuruManagerImpl.java
index 9d7eb3b..5a32de7 100644
--- a/server/src/com/cloud/hypervisor/HypervisorGuruManagerImpl.java
+++ b/server/src/com/cloud/hypervisor/HypervisorGuruManagerImpl.java
@@ -17,8 +17,10 @@
 package com.cloud.hypervisor;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
+import javax.annotation.PostConstruct;
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
@@ -42,19 +44,21 @@ public class HypervisorGuruManagerImpl implements HypervisorGuruManager
{
     @Inject HostDao _hostDao;
     
 	String _name;
+	
+	@Inject List<HypervisorGuru> _hvGuruList;
     Map<HypervisorType, HypervisorGuru> _hvGurus = new HashMap<HypervisorType, HypervisorGuru>();
 	
 	@Override
 	public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{
 		_name = name;
-        ComponentLocator locator = ComponentLocator.getCurrentLocator();
-
-        Adapters<HypervisorGuru> hvGurus = locator.getAdapters(HypervisorGuru.class);
-        for (HypervisorGuru guru : hvGurus) {
-            _hvGurus.put(guru.getHypervisorType(), guru);
-        }
-		
-		return true;
+ 		return true;
+	}
+	
+	@PostConstruct
+	public void init() {
+		for(HypervisorGuru guru : _hvGuruList) {
+			_hvGurus.put(guru.getHypervisorType(), guru);
+		}
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/migration/Db21to22MigrationUtil.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/migration/Db21to22MigrationUtil.java b/server/src/com/cloud/migration/Db21to22MigrationUtil.java
index 7cd6d7e..b6ff906 100755
--- a/server/src/com/cloud/migration/Db21to22MigrationUtil.java
+++ b/server/src/com/cloud/migration/Db21to22MigrationUtil.java
@@ -23,6 +23,8 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
 
+import javax.inject.Inject;
+
 import org.apache.log4j.xml.DOMConfigurator;
 
 import com.cloud.configuration.Resource;
@@ -54,16 +56,17 @@ import com.cloud.vm.dao.InstanceGroupDao;
 import com.cloud.vm.dao.InstanceGroupVMMapDao;
 
 public class Db21to22MigrationUtil {
-    private ClusterDao _clusterDao;
-    private HostDao _hostDao;
-    private AccountDao _accountDao;
-    private DomainDao _domainDao;
-    private ResourceCountDao _resourceCountDao;
-    private InstanceGroupDao _vmGroupDao;
-    private InstanceGroupVMMapDao _groupVMMapDao;
-    private ConfigurationDao _configurationDao;
-    private DataCenterDao _zoneDao;
-    private ResourceManager _resourceMgr;
+	
+	@Inject private ClusterDao _clusterDao;
+	@Inject private HostDao _hostDao;
+	@Inject private AccountDao _accountDao;
+	@Inject private DomainDao _domainDao;
+	@Inject private ResourceCountDao _resourceCountDao;
+	@Inject private InstanceGroupDao _vmGroupDao;
+	@Inject private InstanceGroupVMMapDao _groupVMMapDao;
+	@Inject private ConfigurationDao _configurationDao;
+	@Inject private DataCenterDao _zoneDao;
+	@Inject private ResourceManager _resourceMgr;
     
     private void doMigration() {
         setupComponents();
@@ -171,16 +174,6 @@ public class Db21to22MigrationUtil {
     }
 
     private void setupComponents() {
-    	ComponentLocator locator = ComponentLocator.getLocator("migration", "migration-components.xml",
"log4j-cloud.xml");
-
-        _accountDao = locator.getDao(AccountDao.class);
-        _domainDao = locator.getDao(DomainDao.class);
-        _resourceCountDao = locator.getDao(ResourceCountDao.class);
-        _vmGroupDao = locator.getDao(InstanceGroupDao.class);
-        _groupVMMapDao = locator.getDao(InstanceGroupVMMapDao.class);
-        _configurationDao = locator.getDao(ConfigurationDao.class);
-        _zoneDao = locator.getDao(DataCenterDao.class);
-        _resourceMgr = locator.getManager(ResourceManager.class);
     }
     
     private void setupInstanceGroups() {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index e0e1536..5b6c56f 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -305,7 +305,9 @@ public class ManagementServerImpl implements ManagementServer {
     private final SSHKeyPairDao _sshKeyPairDao;
     private final LoadBalancerDao _loadbalancerDao;
     private final HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
-    private final Adapters<HostAllocator> _hostAllocators;
+    
+    @Inject
+    private List<HostAllocator> _hostAllocators;
     private final ConfigurationManager _configMgr;
     private final ResourceTagDao _resourceTagDao;
     
@@ -387,11 +389,6 @@ public class ManagementServerImpl implements ManagementServer {
 
         _hypervisorCapabilitiesDao = locator.getDao(HypervisorCapabilitiesDao.class);
 
-        _hostAllocators = locator.getAdapters(HostAllocator.class);
-        if (_hostAllocators == null || !_hostAllocators.isSet()) {
-            s_logger.error("Unable to find HostAllocators");
-        }
-
         String value = _configs.get("event.purge.interval");
         int cleanup = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 day.
 
@@ -961,15 +958,14 @@ public class ManagementServerImpl implements ManagementServer {
         }
 
         List<Host> suitableHosts = new ArrayList<Host>();
-        Enumeration<HostAllocator> enHost = _hostAllocators.enumeration();
 
         VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
 
         DataCenterDeployment plan = new DataCenterDeployment(srcHost.getDataCenterId(), srcHost.getPodId(),
srcHost.getClusterId(), null, null, null);
         ExcludeList excludes = new ExcludeList();
         excludes.addHost(srcHostId);
-        while (enHost.hasMoreElements()) {
-            final HostAllocator allocator = enHost.nextElement();
+        
+        for(HostAllocator allocator : _hostAllocators) {
             suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, excludes,
HostAllocator.RETURN_UPTO_ALL, false);
             if (suitableHosts != null && !suitableHosts.isEmpty()) {
                 break;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java
index 022eb1b..d0ae748 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -222,7 +222,8 @@ public class AccountManagerImpl implements AccountManager, AccountService,
Manag
     @Inject
     Site2SiteVpnManager _vpnMgr;
 
-    private Adapters<UserAuthenticator> _userAuthenticators;
+    @Inject
+    private List<UserAuthenticator> _userAuthenticators;
 
     private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1,
new NamedThreadFactory("AccountChecker"));
 
@@ -230,8 +231,9 @@ public class AccountManagerImpl implements AccountManager, AccountService,
Manag
 
     UserVO _systemUser;
     AccountVO _systemAccount;
-    @com.cloud.utils.component.Inject(adapter = SecurityChecker.class)
-    Adapters<SecurityChecker> _securityCheckers;
+    
+    @Inject
+    List<SecurityChecker> _securityCheckers;
     int _cleanupInterval;
 
     @Override
@@ -258,11 +260,6 @@ public class AccountManagerImpl implements AccountManager, AccountService,
Manag
         String value = configs.get(Config.AccountCleanupInterval.key());
         _cleanupInterval = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 day.
 
-        _userAuthenticators = locator.getAdapters(UserAuthenticator.class);
-        if (_userAuthenticators == null || !_userAuthenticators.isSet()) {
-            s_logger.error("Unable to find an user authenticator.");
-        }
-
         return true;
     }
 
@@ -1825,8 +1822,7 @@ public class AccountManagerImpl implements AccountManager, AccountService,
Manag
         }
 
         boolean authenticated = false;
-        for (Enumeration<UserAuthenticator> en = _userAuthenticators.enumeration();
en.hasMoreElements();) {
-            UserAuthenticator authenticator = en.nextElement();
+        for(UserAuthenticator authenticator : _userAuthenticators) {
             if (authenticator.authenticate(username, password, domainId, requestParameters))
{
                 authenticated = true;
                 break;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/utils/test/com/cloud/utils/db/DbAnnotatedBaseDerived.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/db/DbAnnotatedBaseDerived.java b/utils/test/com/cloud/utils/db/DbAnnotatedBaseDerived.java
index 2b845bc..38e045c 100644
--- a/utils/test/com/cloud/utils/db/DbAnnotatedBaseDerived.java
+++ b/utils/test/com/cloud/utils/db/DbAnnotatedBaseDerived.java
@@ -19,7 +19,7 @@ package com.cloud.utils.db;
 import org.springframework.stereotype.Component;
 
 @Component
-public class DbAnnotatedBaseDerived {
+public class DbAnnotatedBaseDerived extends DbAnnotatedBase {
 
 	@DB
 	public void DbAnnotatedMethod() {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d79f1f6f/utils/test/com/cloud/utils/db/TransactionContextBuilderTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/db/TransactionContextBuilderTest.java b/utils/test/com/cloud/utils/db/TransactionContextBuilderTest.java
index bf1fbeb..33e7aa0 100644
--- a/utils/test/com/cloud/utils/db/TransactionContextBuilderTest.java
+++ b/utils/test/com/cloud/utils/db/TransactionContextBuilderTest.java
@@ -16,6 +16,9 @@
 // under the License.
 package com.cloud.utils.db;
 
+import java.util.List;
+import java.util.Map;
+
 import javax.inject.Inject;
 
 import org.junit.Test;
@@ -28,12 +31,15 @@ import com.cloud.utils.component.ComponentContext;
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations="classpath:/com/cloud/utils/db/transactioncontextBuilderTest.xml")
 public class TransactionContextBuilderTest {
+
 	@Inject
 	DbAnnotatedBaseDerived _derived; 
 	
-	@Inject
 	DbAnnotatedBase _base;
 	
+	@Inject
+	List<DbAnnotatedBase> _list;
+	
 	@Test
 	public void test() {
 		// _derived.DbAnnotatedMethod();
@@ -42,5 +48,16 @@ public class TransactionContextBuilderTest {
 		// test @DB injection on dynamically constructed objects
 		DbAnnotatedBase base = ComponentContext.inject(new DbAnnotatedBase());
 		base.MethodWithClassDbAnnotated();
+
+/*		
+		Map<String, DbAnnotatedBase> components = ComponentContext.getApplicationContext().getBeansOfType(DbAnnotatedBase.class);
+		for(Map.Entry<String, DbAnnotatedBase> entry : components.entrySet()) {
+			System.out.println(entry.getKey());
+			entry.getValue().MethodWithClassDbAnnotated();
+		}
+*/
+		for(DbAnnotatedBase entry : _list) {
+			entry.MethodWithClassDbAnnotated();
+		}
 	}
 }


Mime
View raw message