Skip to content

Commit d79f1f6

Browse files
committed
Replace Adapters and PluggableServices, use Spring to load them
1 parent 453b31f commit d79f1f6

13 files changed

Lines changed: 87 additions & 90 deletions

File tree

core/src/com/cloud/storage/template/DownloadManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
import com.cloud.utils.component.Adapter;
6464
import com.cloud.utils.component.Adapters;
6565
import com.cloud.utils.component.ComponentLocator;
66-
import com.cloud.utils.component.ComponentLocator.ComponentInfo;
66+
import com.cloud.utils.component.LegacyComponentLocator.ComponentInfo;
6767
import com.cloud.utils.exception.CloudRuntimeException;
6868
import com.cloud.utils.script.OutputInterpreter;
6969
import com.cloud.utils.script.Script;

server/src/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
218218

219219
protected int _pingInterval;
220220
protected long _pingTimeout;
221-
protected AgentMonitor _monitor = null;
221+
@Inject protected AgentMonitor _monitor = null;
222222

223223
protected ExecutorService _executor;
224224

@@ -272,7 +272,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
272272
long lastPing = (System.currentTimeMillis() >> 10) - _pingTimeout;
273273
_hostDao.markHostsAsDisconnected(_nodeId, lastPing);
274274

275-
_monitor = ComponentLocator.inject(AgentMonitor.class, _nodeId, _hostDao, _vmDao, _dcDao, _podDao, this, _alertMgr, _pingTimeout);
275+
// _monitor = ComponentLocator.inject(AgentMonitor.class, _nodeId, _hostDao, _vmDao, _dcDao, _podDao, this, _alertMgr, _pingTimeout);
276276
registerForHostEvents(_monitor, true, true, false);
277277

278278
_executor = new ThreadPoolExecutor(threads, threads, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentTaskPool"));

server/src/com/cloud/api/ApiServer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
import javax.crypto.Mac;
5252
import javax.crypto.spec.SecretKeySpec;
53+
import javax.inject.Inject;
5354
import javax.servlet.http.HttpServletResponse;
5455
import javax.servlet.http.HttpSession;
5556

@@ -80,6 +81,7 @@
8081
import org.apache.http.protocol.ResponseDate;
8182
import org.apache.http.protocol.ResponseServer;
8283
import org.apache.log4j.Logger;
84+
import org.springframework.stereotype.Component;
8385

8486
import com.cloud.api.response.ApiResponseSerializer;
8587
import com.cloud.api.response.ExceptionResponse;
@@ -116,6 +118,7 @@
116118
import com.cloud.utils.exception.CSExceptionErrorCode;
117119
import com.cloud.uuididentity.dao.IdentityDao;
118120

121+
@Component
119122
public class ApiServer implements HttpRequestHandler {
120123
private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
121124
private static final Logger s_accessLogger = Logger.getLogger("apiserver." + ApiServer.class.getName());
@@ -133,6 +136,8 @@ public class ApiServer implements HttpRequestHandler {
133136
private AsyncJobManager _asyncMgr = null;
134137
private Account _systemAccount = null;
135138
private User _systemUser = null;
139+
140+
@Inject List<PluggableService> _pluggableServices;
136141

137142
private static int _workerCount = 0;
138143

@@ -187,9 +192,7 @@ public static boolean isPluggableServiceCommand(String cmdClassName) {
187192
private String[] getPluggableServicesApiConfigs() {
188193
List<String> pluggableServicesApiConfigs = new ArrayList<String>();
189194

190-
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
191-
List<PluggableService> services = locator.getAllPluggableServices();
192-
for (PluggableService service : services) {
195+
for (PluggableService service : _pluggableServices) {
193196
pluggableServicesApiConfigs.add(service.getPropertiesFile());
194197
}
195198
return pluggableServicesApiConfigs.toArray(new String[0]);

server/src/com/cloud/cluster/ClusterManagerImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ public class ClusterManagerImpl implements ClusterManager {
121121
private final ExecutorService _executor;
122122

123123
private ClusterServiceAdapter _currentServiceAdapter;
124+
125+
@Inject
126+
private List<ClusterServiceAdapter> _serviceAdapters;
124127

125128
private ManagementServerHostDao _mshostDao;
126129
private ManagementServerHostPeerDao _mshostPeerDao;
@@ -1306,14 +1309,10 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
13061309
// notification task itself in turn works as a task dispatcher
13071310
_executor.execute(getClusterPduNotificationTask());
13081311

1309-
Adapters<ClusterServiceAdapter> adapters = locator.getAdapters(ClusterServiceAdapter.class);
1310-
if (adapters == null || !adapters.isSet()) {
1312+
if (_serviceAdapters == null) {
13111313
throw new ConfigurationException("Unable to get cluster service adapters");
13121314
}
1313-
Enumeration<ClusterServiceAdapter> it = adapters.enumeration();
1314-
if(it.hasMoreElements()) {
1315-
_currentServiceAdapter = it.nextElement();
1316-
}
1315+
_currentServiceAdapter = _serviceAdapters.get(0);
13171316

13181317
if(_currentServiceAdapter == null) {
13191318
throw new ConfigurationException("Unable to set current cluster service adapter");

server/src/com/cloud/configuration/DefaultComponentLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
import com.cloud.utils.component.Adapter;
180180
import com.cloud.utils.component.ComponentLibrary;
181181
import com.cloud.utils.component.ComponentLibraryBase;
182-
import com.cloud.utils.component.ComponentLocator.ComponentInfo;
182+
import com.cloud.utils.component.LegacyComponentLocator.ComponentInfo;
183183
import com.cloud.utils.component.Manager;
184184
import com.cloud.utils.component.PluggableService;
185185
import com.cloud.utils.db.GenericDao;

server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
187187
private int _mgmt_port = 8250;
188188

189189
private String _name;
190-
private Adapters<ConsoleProxyAllocator> _consoleProxyAllocators;
190+
@Inject
191+
private List<ConsoleProxyAllocator> _consoleProxyAllocators;
191192

192193
@Inject
193194
private ConsoleProxyDao _consoleProxyDao;
@@ -806,11 +807,10 @@ protected Map<String, Object> createProxyInstance(long dataCenterId, HypervisorT
806807

807808
private ConsoleProxyAllocator getCurrentAllocator() {
808809
// for now, only one adapter is supported
809-
Enumeration<ConsoleProxyAllocator> it = _consoleProxyAllocators.enumeration();
810-
if (it.hasMoreElements()) {
811-
return it.nextElement();
812-
}
813-
810+
for(ConsoleProxyAllocator allocator : _consoleProxyAllocators) {
811+
return allocator;
812+
}
813+
814814
return null;
815815
}
816816

@@ -1512,11 +1512,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
15121512
value = agentMgrConfigs.get("port");
15131513
_mgmt_port = NumbersUtil.parseInt(value, 8250);
15141514

1515-
_consoleProxyAllocators = locator.getAdapters(ConsoleProxyAllocator.class);
1516-
if (_consoleProxyAllocators == null || !_consoleProxyAllocators.isSet()) {
1517-
throw new ConfigurationException("Unable to get proxy allocators");
1518-
}
1519-
15201515
_listener = new ConsoleProxyListener(this);
15211516
_agentMgr.registerForHostEvents(_listener, true, true, false);
15221517

server/src/com/cloud/ha/HighAvailabilityManagerImpl.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
120120
@Inject
121121
ClusterDetailsDao _clusterDetailsDao;
122122
long _serverId;
123-
@com.cloud.utils.component.Inject(adapter = Investigator.class)
124-
Adapters<Investigator> _investigators;
125-
@com.cloud.utils.component.Inject(adapter = FenceBuilder.class)
126-
Adapters<FenceBuilder> _fenceBuilders;
123+
124+
@Inject
125+
List<Investigator> _investigators;
126+
@Inject
127+
List<FenceBuilder> _fenceBuilders;
127128
@Inject
128129
AgentManager _agentMgr;
129130
@Inject
@@ -164,11 +165,8 @@ public Status investigate(final long hostId) {
164165
return null;
165166
}
166167

167-
final Enumeration<Investigator> en = _investigators.enumeration();
168168
Status hostState = null;
169-
Investigator investigator = null;
170-
while (en.hasMoreElements()) {
171-
investigator = en.nextElement();
169+
for(Investigator investigator : _investigators) {
172170
hostState = investigator.isAgentAlive(host);
173171
if (hostState != null) {
174172
if (s_logger.isDebugEnabled()) {
@@ -419,29 +417,28 @@ protected Long restart(HaWorkVO work) {
419417
return null;
420418
}
421419

422-
Enumeration<Investigator> en = _investigators.enumeration();
423420
Investigator investigator = null;
424-
while (en.hasMoreElements()) {
425-
investigator = en.nextElement();
421+
for(Investigator it : _investigators) {
422+
investigator = it;
426423
alive = investigator.isVmAlive(vm, host);
427424
s_logger.info(investigator.getName() + " found " + vm + "to be alive? " + alive);
428425
if (alive != null) {
429426
break;
430427
}
431428
}
429+
432430
boolean fenced = false;
433431
if (alive == null) {
434432
s_logger.debug("Fencing off VM that we don't know the state of");
435-
Enumeration<FenceBuilder> enfb = _fenceBuilders.enumeration();
436-
while (enfb.hasMoreElements()) {
437-
FenceBuilder fb = enfb.nextElement();
433+
for(FenceBuilder fb : _fenceBuilders) {
438434
Boolean result = fb.fenceOff(vm, host);
439435
s_logger.info("Fencer " + fb.getName() + " returned " + result);
440436
if (result != null && result) {
441437
fenced = true;
442438
break;
443439
}
444440
}
441+
445442
} else if (!alive) {
446443
fenced = true;
447444
} else {
@@ -697,9 +694,6 @@ public boolean configure(final String name, final Map<String, Object> xmlParams)
697694

698695
_serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId();
699696

700-
_investigators = locator.getAdapters(Investigator.class);
701-
_fenceBuilders = locator.getAdapters(FenceBuilder.class);
702-
703697
Map<String, String> params = new HashMap<String, String>();
704698
final ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
705699
if (configDao != null) {

server/src/com/cloud/hypervisor/HypervisorGuruManagerImpl.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package com.cloud.hypervisor;
1818

1919
import java.util.HashMap;
20+
import java.util.List;
2021
import java.util.Map;
2122

23+
import javax.annotation.PostConstruct;
2224
import javax.ejb.Local;
2325
import javax.inject.Inject;
2426
import javax.naming.ConfigurationException;
@@ -42,19 +44,21 @@ public class HypervisorGuruManagerImpl implements HypervisorGuruManager {
4244
@Inject HostDao _hostDao;
4345

4446
String _name;
47+
48+
@Inject List<HypervisorGuru> _hvGuruList;
4549
Map<HypervisorType, HypervisorGuru> _hvGurus = new HashMap<HypervisorType, HypervisorGuru>();
4650

4751
@Override
4852
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
4953
_name = name;
50-
ComponentLocator locator = ComponentLocator.getCurrentLocator();
51-
52-
Adapters<HypervisorGuru> hvGurus = locator.getAdapters(HypervisorGuru.class);
53-
for (HypervisorGuru guru : hvGurus) {
54-
_hvGurus.put(guru.getHypervisorType(), guru);
55-
}
56-
57-
return true;
54+
return true;
55+
}
56+
57+
@PostConstruct
58+
public void init() {
59+
for(HypervisorGuru guru : _hvGuruList) {
60+
_hvGurus.put(guru.getHypervisorType(), guru);
61+
}
5862
}
5963

6064
@Override

server/src/com/cloud/migration/Db21to22MigrationUtil.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.List;
2424
import java.util.Queue;
2525

26+
import javax.inject.Inject;
27+
2628
import org.apache.log4j.xml.DOMConfigurator;
2729

2830
import com.cloud.configuration.Resource;
@@ -54,16 +56,17 @@
5456
import com.cloud.vm.dao.InstanceGroupVMMapDao;
5557

5658
public class Db21to22MigrationUtil {
57-
private ClusterDao _clusterDao;
58-
private HostDao _hostDao;
59-
private AccountDao _accountDao;
60-
private DomainDao _domainDao;
61-
private ResourceCountDao _resourceCountDao;
62-
private InstanceGroupDao _vmGroupDao;
63-
private InstanceGroupVMMapDao _groupVMMapDao;
64-
private ConfigurationDao _configurationDao;
65-
private DataCenterDao _zoneDao;
66-
private ResourceManager _resourceMgr;
59+
60+
@Inject private ClusterDao _clusterDao;
61+
@Inject private HostDao _hostDao;
62+
@Inject private AccountDao _accountDao;
63+
@Inject private DomainDao _domainDao;
64+
@Inject private ResourceCountDao _resourceCountDao;
65+
@Inject private InstanceGroupDao _vmGroupDao;
66+
@Inject private InstanceGroupVMMapDao _groupVMMapDao;
67+
@Inject private ConfigurationDao _configurationDao;
68+
@Inject private DataCenterDao _zoneDao;
69+
@Inject private ResourceManager _resourceMgr;
6770

6871
private void doMigration() {
6972
setupComponents();
@@ -171,16 +174,6 @@ private void migrateResourceCounts() {
171174
}
172175

173176
private void setupComponents() {
174-
ComponentLocator locator = ComponentLocator.getLocator("migration", "migration-components.xml", "log4j-cloud.xml");
175-
176-
_accountDao = locator.getDao(AccountDao.class);
177-
_domainDao = locator.getDao(DomainDao.class);
178-
_resourceCountDao = locator.getDao(ResourceCountDao.class);
179-
_vmGroupDao = locator.getDao(InstanceGroupDao.class);
180-
_groupVMMapDao = locator.getDao(InstanceGroupVMMapDao.class);
181-
_configurationDao = locator.getDao(ConfigurationDao.class);
182-
_zoneDao = locator.getDao(DataCenterDao.class);
183-
_resourceMgr = locator.getManager(ResourceManager.class);
184177
}
185178

186179
private void setupInstanceGroups() {

server/src/com/cloud/server/ManagementServerImpl.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ public class ManagementServerImpl implements ManagementServer {
305305
private final SSHKeyPairDao _sshKeyPairDao;
306306
private final LoadBalancerDao _loadbalancerDao;
307307
private final HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
308-
private final Adapters<HostAllocator> _hostAllocators;
308+
309+
@Inject
310+
private List<HostAllocator> _hostAllocators;
309311
private final ConfigurationManager _configMgr;
310312
private final ResourceTagDao _resourceTagDao;
311313

@@ -387,11 +389,6 @@ protected ManagementServerImpl() {
387389

388390
_hypervisorCapabilitiesDao = locator.getDao(HypervisorCapabilitiesDao.class);
389391

390-
_hostAllocators = locator.getAdapters(HostAllocator.class);
391-
if (_hostAllocators == null || !_hostAllocators.isSet()) {
392-
s_logger.error("Unable to find HostAllocators");
393-
}
394-
395392
String value = _configs.get("event.purge.interval");
396393
int cleanup = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 day.
397394

@@ -961,15 +958,14 @@ public Pair<List<? extends Host>, List<? extends Host>> listHostsForMigrationOfV
961958
}
962959

963960
List<Host> suitableHosts = new ArrayList<Host>();
964-
Enumeration<HostAllocator> enHost = _hostAllocators.enumeration();
965961

966962
VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
967963

968964
DataCenterDeployment plan = new DataCenterDeployment(srcHost.getDataCenterId(), srcHost.getPodId(), srcHost.getClusterId(), null, null, null);
969965
ExcludeList excludes = new ExcludeList();
970966
excludes.addHost(srcHostId);
971-
while (enHost.hasMoreElements()) {
972-
final HostAllocator allocator = enHost.nextElement();
967+
968+
for(HostAllocator allocator : _hostAllocators) {
973969
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, excludes, HostAllocator.RETURN_UPTO_ALL, false);
974970
if (suitableHosts != null && !suitableHosts.isEmpty()) {
975971
break;

0 commit comments

Comments
 (0)