Skip to content

Commit 25d1441

Browse files
committed
Replace Adapters<T> with standard List<T> to work with Spring injection
1 parent 8a9cf04 commit 25d1441

17 files changed

Lines changed: 103 additions & 85 deletions

File tree

client/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
<maxIdleTime>60000</maxIdleTime>
200200
</connector>
201201
</connectors>
202+
<jvmArgs>-XX:MaxPermSize=256m -Xmx2g</jvmArgs>
202203
<contextPath>/client</contextPath>
203204
<webXml>${basedir}/target/${project.artifactId}-${project.version}/WEB-INF/web.xml</webXml>
204205
<webAppSourceDirectory>${basedir}/target/${project.artifactId}-${project.version}</webAppSourceDirectory>

client/tomcatconf/applicationContext.xml.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
<!--
2020
@DB support
2121
-->
22+
23+
<!--
2224
<aop:config proxy-target-class="true">
2325
<aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
2426
<aop:pointcut id="captureAnyMethod"
2527
expression="execution(* *(..))" />
2628
<aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod"/>
2729
</aop:aspect>
2830
</aop:config>
31+
-->
2932

3033
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
3134

framework/ipc/test/org/apache/cloudstack/framework/codestyle/AsyncSampleEventDrivenStyleCaller.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public class AsyncSampleEventDrivenStyleCaller {
2828
@SuppressWarnings("unchecked")
2929
public void MethodThatWillCallAsyncMethod() {
3030
String vol = new String("Hello");
31-
AsyncCallbackDispatcher<AsyncSampleEventDrivenStyleCaller> caller = AsyncCallbackDispatcher.create(this);
31+
AsyncCallbackDispatcher<AsyncSampleEventDrivenStyleCaller, Object> caller = AsyncCallbackDispatcher.create(this);
3232
_ds.createVolume(vol, caller
3333
.setCallback(caller.getTarget().HandleVolumeCreateAsyncCallback(null, null))
3434
.setContext(vol)
3535
);
3636
}
3737

38-
public Void HandleVolumeCreateAsyncCallback(AsyncCallbackDispatcher<AsyncSampleEventDrivenStyleCaller> callback, String context) {
38+
public Void HandleVolumeCreateAsyncCallback(AsyncCallbackDispatcher<AsyncSampleEventDrivenStyleCaller, Object> callback, String context) {
3939
Object resultVol = callback.getResult();
4040

4141
return null;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
116116
@Inject
117117
protected HostTransferMapDao _hostTransferDao;
118118

119-
@com.cloud.utils.component.Inject(adapter = AgentLoadBalancerPlanner.class)
120-
protected Adapters<AgentLoadBalancerPlanner> _lbPlanners;
119+
// @com.cloud.utils.component.Inject(adapter = AgentLoadBalancerPlanner.class)
120+
@Inject protected List<AgentLoadBalancerPlanner> _lbPlanners;
121121

122122
@Inject
123123
protected AgentManager _agentMgr;

server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Map;
2323
import java.util.concurrent.Executors;
2424

25+
import javax.annotation.PostConstruct;
2526
import javax.ejb.Local;
2627
import javax.inject.Inject;
2728
import javax.naming.ConfigurationException;
@@ -112,9 +113,13 @@ public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMet
112113
@Inject PxeServerManager _pxeMgr;
113114
@Inject ResourceManager _resourceMgr;
114115

115-
@com.cloud.utils.component.Inject (adapter=TemplateAdapter.class)
116-
protected Adapters<TemplateAdapter> _adapters;
116+
// @com.cloud.utils.component.Inject (adapter=TemplateAdapter.class)
117+
@Inject protected List<TemplateAdapter> _adapters;
117118

119+
@PostConstruct
120+
public void init() {
121+
}
122+
118123
@Override
119124
public boolean attachISOToVM(long vmId, long isoId, boolean attach) {
120125
s_logger.warn("attachISOToVM is not supported by Bare Metal, just fake a true");

server/src/com/cloud/baremetal/PxeServerManagerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdap
5858
@Inject AgentManager _agentMgr;
5959
@Inject ExternalDhcpManager exDhcpMgr;
6060
@Inject ResourceManager _resourceMgr;
61-
@com.cloud.utils.component.Inject(adapter=PxeServerService.class)
62-
protected Adapters<PxeServerService> _services;
61+
62+
// @com.cloud.utils.component.Inject(adapter=PxeServerService.class)
63+
@Inject protected List<PxeServerService> _services;
6364

6465
@Override
6566
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
211211
ClusterDao _clusterDao;
212212
@Inject
213213
AlertManager _alertMgr;
214-
@com.cloud.utils.component.Inject(adapter = SecurityChecker.class)
215-
Adapters<SecurityChecker> _secChecker;
214+
// @com.cloud.utils.component.Inject(adapter = SecurityChecker.class)
215+
@Inject
216+
List<SecurityChecker> _secChecker;
217+
216218
@Inject
217219
CapacityDao _capacityDao;
218220
@Inject

server/src/com/cloud/deploy/FirstFitPlanner.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
106106
@Inject protected AccountManager _accountMgr;
107107
@Inject protected StorageManager _storageMgr;
108108

109-
@com.cloud.utils.component.Inject(adapter=StoragePoolAllocator.class)
110-
protected Adapters<StoragePoolAllocator> _storagePoolAllocators;
111-
@com.cloud.utils.component.Inject(adapter=HostAllocator.class)
112-
protected Adapters<HostAllocator> _hostAllocators;
109+
//@com.cloud.utils.component.Inject(adapter=StoragePoolAllocator.class)
110+
@Inject protected List<StoragePoolAllocator> _storagePoolAllocators;
111+
112+
//@com.cloud.utils.component.Inject(adapter=HostAllocator.class)
113+
@Inject protected List<HostAllocator> _hostAllocators;
113114
protected String _allocationAlgorithm = "random";
114115

115116

@@ -714,17 +715,13 @@ protected boolean hostCanAccessSPool(Host host, StoragePool pool){
714715

715716
protected List<Host> findSuitableHosts(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo){
716717
List<Host> suitableHosts = new ArrayList<Host>();
717-
Enumeration<HostAllocator> enHost = _hostAllocators.enumeration();
718-
s_logger.debug("Calling HostAllocators to find suitable hosts");
719-
720-
while (enHost.hasMoreElements()) {
721-
final HostAllocator allocator = enHost.nextElement();
718+
for(HostAllocator allocator : _hostAllocators) {
722719
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, avoid, returnUpTo);
723720
if (suitableHosts != null && !suitableHosts.isEmpty()) {
724721
break;
725722
}
726723
}
727-
724+
728725
if(suitableHosts.isEmpty()){
729726
s_logger.debug("No suitable hosts found");
730727
}
@@ -812,20 +809,16 @@ protected Pair<Map<Volume, List<StoragePool>>, List<Volume>> findSuitablePoolsFo
812809
}
813810
diskProfile.setUseLocalStorage(useLocalStorage);
814811

815-
816812
boolean foundPotentialPools = false;
817-
818-
Enumeration<StoragePoolAllocator> enPool = _storagePoolAllocators.enumeration();
819-
while (enPool.hasMoreElements()) {
820-
final StoragePoolAllocator allocator = enPool.nextElement();
813+
for(StoragePoolAllocator allocator : _storagePoolAllocators) {
821814
final List<StoragePool> suitablePools = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, returnUpTo);
822815
if (suitablePools != null && !suitablePools.isEmpty()) {
823816
suitableVolumeStoragePools.put(toBeCreated, suitablePools);
824817
foundPotentialPools = true;
825818
break;
826819
}
827820
}
828-
821+
829822
if(!foundPotentialPools){
830823
s_logger.debug("No suitable pools found for volume: "+toBeCreated +" under cluster: "+plan.getClusterId());
831824
//No suitable storage pools found under this cluster for this volume. - remove any suitable pools found for other volumes.

server/src/com/cloud/network/NetworkManagerImpl.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
272272
RemoteAccessVpnService _vpnMgr;
273273
@Inject
274274
PodVlanMapDao _podVlanMapDao;
275-
@com.cloud.utils.component.Inject(adapter = NetworkGuru.class)
276-
Adapters<NetworkGuru> _networkGurus;
277-
@com.cloud.utils.component.Inject(adapter = NetworkElement.class)
278-
Adapters<NetworkElement> _networkElements;
275+
276+
//@com.cloud.utils.component.Inject(adapter = NetworkGuru.class)
277+
@Inject
278+
List<NetworkGuru> _networkGurus;
279+
280+
// @com.cloud.utils.component.Inject(adapter = NetworkElement.class)
281+
@Inject
282+
List<NetworkElement> _networkElements;
283+
279284
@Inject
280285
NetworkDomainDao _networkDomainDao;
281286
@Inject
@@ -351,7 +356,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
351356
@Override
352357
public NetworkElement getElementImplementingProvider(String providerName) {
353358
String elementName = s_providerToNetworkElementMap.get(providerName);
354-
NetworkElement element = _networkElements.get(elementName);
359+
NetworkElement element = Adapters.getAdapterByName(_networkElements, elementName);
355360
return element;
356361
}
357362

@@ -1791,7 +1796,7 @@ public Pair<NicProfile,Integer> allocateNic(NicProfile requested, Network networ
17911796

17921797
NetworkVO ntwkVO = _networksDao.findById(network.getId());
17931798
s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested);
1794-
NetworkGuru guru = _networkGurus.get(ntwkVO.getGuruName());
1799+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, ntwkVO.getGuruName());
17951800

17961801
if (requested != null && requested.getMode() == null) {
17971802
requested.setMode(network.getMode());
@@ -1936,7 +1941,7 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDesti
19361941
}
19371942

19381943
try {
1939-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
1944+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
19401945
Network.State state = network.getState();
19411946
if (state == Network.State.Implemented || state == Network.State.Setup || state == Network.State.Implementing) {
19421947
s_logger.debug("Network id=" + networkId + " is already implemented");
@@ -2124,7 +2129,7 @@ public NicProfile prepareNic(VirtualMachineProfile<? extends VMInstanceVO> vmPro
21242129
ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
21252130

21262131
Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId());
2127-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
2132+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
21282133
NicVO nic = _nicDao.findById(nicId);
21292134

21302135
NicProfile profile = null;
@@ -2186,7 +2191,7 @@ public <T extends VMInstanceVO> void prepareNicForMigration(VirtualMachineProfil
21862191
NetworkVO network = _networksDao.findById(nic.getNetworkId());
21872192
Integer networkRate = getNetworkRate(network.getId(), vm.getId());
21882193

2189-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
2194+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
21902195
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate,
21912196
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
21922197
guru.updateNicProfile(profile, network);
@@ -2216,7 +2221,7 @@ protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfil
22162221
if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) {
22172222
Nic.State originalState = nic.getState();
22182223
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
2219-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
2224+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
22202225
nic.setState(Nic.State.Releasing);
22212226
_nicDao.update(nic.getId(), nic);
22222227
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null,
@@ -2262,7 +2267,7 @@ public List<NicProfile> getNicProfiles(VirtualMachine vm) {
22622267
NetworkVO network = _networksDao.findById(nic.getNetworkId());
22632268
Integer networkRate = getNetworkRate(network.getId(), vm.getId());
22642269

2265-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
2270+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
22662271
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
22672272
networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
22682273
guru.updateNicProfile(profile, network);
@@ -2283,7 +2288,7 @@ public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadc
22832288
NetworkVO network = _networksDao.findById(networkId);
22842289
Integer networkRate = getNetworkRate(network.getId(), vm.getId());
22852290

2286-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
2291+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
22872292
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
22882293
networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
22892294
guru.updateNicProfile(profile, network);
@@ -2438,7 +2443,7 @@ protected void removeNic(VirtualMachineProfile<? extends VMInstanceVO> vm, NicVO
24382443
NetworkVO network = _networksDao.findById(nic.getNetworkId());
24392444
NicProfile profile = new NicProfile(nic, network, null, null, null,
24402445
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
2441-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
2446+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
24422447
guru.deallocate(network, profile, vm);
24432448
_nicDao.remove(nic.getId());
24442449
s_logger.debug("Removed nic id=" + nic.getId());
@@ -3414,7 +3419,7 @@ public boolean shutdownNetwork(long networkId, ReservationContext context, boole
34143419
if (s_logger.isDebugEnabled()) {
34153420
s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now.");
34163421
}
3417-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
3422+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
34183423
NetworkProfile profile = convertNetworkToNetworkProfile(network.getId());
34193424
guru.shutdown(profile, _networkOfferingDao.findById(network.getNetworkOfferingId()));
34203425

@@ -3574,7 +3579,7 @@ public boolean destroyNetwork(long networkId, ReservationContext context) {
35743579
if (s_logger.isDebugEnabled()) {
35753580
s_logger.debug("Network id=" + networkId + " is destroyed successfully, cleaning up corresponding resources now.");
35763581
}
3577-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
3582+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
35783583
Account owner = _accountMgr.getAccount(network.getAccountId());
35793584

35803585
Transaction txn = Transaction.currentTxn();
@@ -4258,7 +4263,7 @@ public IpAddress getIp(long ipAddressId) {
42584263
@Override
42594264
public NetworkProfile convertNetworkToNetworkProfile(long networkId) {
42604265
NetworkVO network = _networksDao.findById(networkId);
4261-
NetworkGuru guru = _networkGurus.get(network.getGuruName());
4266+
NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
42624267
NetworkProfile profile = new NetworkProfile(network);
42634268
guru.updateNetworkProfile(profile);
42644269

server/src/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Map;
2828
import java.util.Set;
2929

30+
import javax.annotation.PostConstruct;
3031
import javax.ejb.Local;
3132
import javax.inject.Inject;
3233
import javax.naming.ConfigurationException;
@@ -204,14 +205,18 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
204205
protected HighAvailabilityManager _haMgr;
205206
@Inject
206207
protected StorageService _storageSvr;
207-
@com.cloud.utils.component.Inject(adapter = Discoverer.class)
208-
protected Adapters<? extends Discoverer> _discoverers;
208+
//@com.cloud.utils.component.Inject(adapter = Discoverer.class)
209+
@Inject
210+
protected List<? extends Discoverer> _discoverers;
209211
@Inject
210212
protected ClusterManager _clusterMgr;
211213
@Inject
212214
protected StoragePoolHostDao _storagePoolHostDao;
213-
@com.cloud.utils.component.Inject(adapter = PodAllocator.class)
214-
protected Adapters<PodAllocator> _podAllocators = null;
215+
216+
// @com.cloud.utils.component.Inject(adapter = PodAllocator.class)
217+
@Inject
218+
protected List<PodAllocator> _podAllocators = null;
219+
215220
@Inject
216221
protected VMTemplateDao _templateDao;
217222
@Inject
@@ -226,6 +231,11 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
226231
protected HashMap<Integer, List<ResourceListener>> _lifeCycleListeners = new HashMap<Integer, List<ResourceListener>>();
227232
private HypervisorType _defaultSystemVMHypervisor;
228233

234+
@PostConstruct
235+
public void init() {
236+
// TODO initialize pod allocators here instead
237+
}
238+
229239
private void insertListener(Integer event, ResourceListener listener) {
230240
List<ResourceListener> lst = _lifeCycleListeners.get(event);
231241
if (lst == null) {
@@ -497,13 +507,10 @@ public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws Illegal
497507

498508
@Override
499509
public Discoverer getMatchingDiscover(Hypervisor.HypervisorType hypervisorType) {
500-
Enumeration<? extends Discoverer> en = _discoverers.enumeration();
501-
while (en.hasMoreElements()) {
502-
Discoverer discoverer = en.nextElement();
503-
if (discoverer.getHypervisorType() == hypervisorType) {
510+
for(Discoverer discoverer : _discoverers) {
511+
if (discoverer.getHypervisorType() == hypervisorType)
504512
return discoverer;
505-
}
506-
}
513+
}
507514
return null;
508515
}
509516

@@ -670,10 +677,8 @@ private List<HostVO> discoverHostsFull(Long dcId, Long podId, Long clusterId, St
670677

671678
List<HostVO> hosts = new ArrayList<HostVO>();
672679
s_logger.info("Trying to add a new host at " + url + " in data center " + dcId);
673-
Enumeration<? extends Discoverer> en = _discoverers.enumeration();
674680
boolean isHypervisorTypeSupported = false;
675-
while (en.hasMoreElements()) {
676-
Discoverer discoverer = en.nextElement();
681+
for ( Discoverer discoverer : _discoverers) {
677682
if (params != null) {
678683
discoverer.putParam(params);
679684
}
@@ -2161,9 +2166,7 @@ public List<HostVO> listHostsByNameLike(String name) {
21612166

21622167
@Override
21632168
public Pair<HostPodVO, Long> findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set<Long> avoids) {
2164-
final Enumeration en = _podAllocators.enumeration();
2165-
while (en.hasMoreElements()) {
2166-
final PodAllocator allocator = (PodAllocator) en.nextElement();
2169+
for(PodAllocator allocator : _podAllocators) {
21672170
final Pair<HostPodVO, Long> pod = allocator.allocateTo(template, offering, dc, accountId, avoids);
21682171
if (pod != null) {
21692172
return pod;

0 commit comments

Comments
 (0)