Replace Adapters<T> with standard List<T> to work with Spring injection

This commit is contained in:
Kelven Yang 2013-01-03 11:49:12 -08:00
parent 8a9cf04008
commit 25d14418b9
17 changed files with 103 additions and 85 deletions

View File

@ -199,6 +199,7 @@
<maxIdleTime>60000</maxIdleTime> <maxIdleTime>60000</maxIdleTime>
</connector> </connector>
</connectors> </connectors>
<jvmArgs>-XX:MaxPermSize=256m -Xmx2g</jvmArgs>
<contextPath>/client</contextPath> <contextPath>/client</contextPath>
<webXml>${basedir}/target/${project.artifactId}-${project.version}/WEB-INF/web.xml</webXml> <webXml>${basedir}/target/${project.artifactId}-${project.version}/WEB-INF/web.xml</webXml>
<webAppSourceDirectory>${basedir}/target/${project.artifactId}-${project.version}</webAppSourceDirectory> <webAppSourceDirectory>${basedir}/target/${project.artifactId}-${project.version}</webAppSourceDirectory>

View File

@ -19,6 +19,8 @@
<!-- <!--
@DB support @DB support
--> -->
<!--
<aop:config proxy-target-class="true"> <aop:config proxy-target-class="true">
<aop:aspect id="dbContextBuilder" ref="transactionContextBuilder"> <aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
<aop:pointcut id="captureAnyMethod" <aop:pointcut id="captureAnyMethod"
@ -26,6 +28,7 @@
<aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod"/> <aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod"/>
</aop:aspect> </aop:aspect>
</aop:config> </aop:config>
-->
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" /> <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />

View File

@ -28,14 +28,14 @@ public class AsyncSampleEventDrivenStyleCaller {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void MethodThatWillCallAsyncMethod() { public void MethodThatWillCallAsyncMethod() {
String vol = new String("Hello"); String vol = new String("Hello");
AsyncCallbackDispatcher<AsyncSampleEventDrivenStyleCaller> caller = AsyncCallbackDispatcher.create(this); AsyncCallbackDispatcher<AsyncSampleEventDrivenStyleCaller, Object> caller = AsyncCallbackDispatcher.create(this);
_ds.createVolume(vol, caller _ds.createVolume(vol, caller
.setCallback(caller.getTarget().HandleVolumeCreateAsyncCallback(null, null)) .setCallback(caller.getTarget().HandleVolumeCreateAsyncCallback(null, null))
.setContext(vol) .setContext(vol)
); );
} }
public Void HandleVolumeCreateAsyncCallback(AsyncCallbackDispatcher<AsyncSampleEventDrivenStyleCaller> callback, String context) { public Void HandleVolumeCreateAsyncCallback(AsyncCallbackDispatcher<AsyncSampleEventDrivenStyleCaller, Object> callback, String context) {
Object resultVol = callback.getResult(); Object resultVol = callback.getResult();
return null; return null;

View File

@ -116,8 +116,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
@Inject @Inject
protected HostTransferMapDao _hostTransferDao; protected HostTransferMapDao _hostTransferDao;
@com.cloud.utils.component.Inject(adapter = AgentLoadBalancerPlanner.class) // @com.cloud.utils.component.Inject(adapter = AgentLoadBalancerPlanner.class)
protected Adapters<AgentLoadBalancerPlanner> _lbPlanners; @Inject protected List<AgentLoadBalancerPlanner> _lbPlanners;
@Inject @Inject
protected AgentManager _agentMgr; protected AgentManager _agentMgr;

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import javax.annotation.PostConstruct;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
@ -112,9 +113,13 @@ public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMet
@Inject PxeServerManager _pxeMgr; @Inject PxeServerManager _pxeMgr;
@Inject ResourceManager _resourceMgr; @Inject ResourceManager _resourceMgr;
@com.cloud.utils.component.Inject (adapter=TemplateAdapter.class) // @com.cloud.utils.component.Inject (adapter=TemplateAdapter.class)
protected Adapters<TemplateAdapter> _adapters; @Inject protected List<TemplateAdapter> _adapters;
@PostConstruct
public void init() {
}
@Override @Override
public boolean attachISOToVM(long vmId, long isoId, boolean attach) { public boolean attachISOToVM(long vmId, long isoId, boolean attach) {
s_logger.warn("attachISOToVM is not supported by Bare Metal, just fake a true"); s_logger.warn("attachISOToVM is not supported by Bare Metal, just fake a true");

View File

@ -58,8 +58,9 @@ public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdap
@Inject AgentManager _agentMgr; @Inject AgentManager _agentMgr;
@Inject ExternalDhcpManager exDhcpMgr; @Inject ExternalDhcpManager exDhcpMgr;
@Inject ResourceManager _resourceMgr; @Inject ResourceManager _resourceMgr;
@com.cloud.utils.component.Inject(adapter=PxeServerService.class)
protected Adapters<PxeServerService> _services; // @com.cloud.utils.component.Inject(adapter=PxeServerService.class)
@Inject protected List<PxeServerService> _services;
@Override @Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {

View File

@ -211,8 +211,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
ClusterDao _clusterDao; ClusterDao _clusterDao;
@Inject @Inject
AlertManager _alertMgr; AlertManager _alertMgr;
@com.cloud.utils.component.Inject(adapter = SecurityChecker.class) // @com.cloud.utils.component.Inject(adapter = SecurityChecker.class)
Adapters<SecurityChecker> _secChecker; @Inject
List<SecurityChecker> _secChecker;
@Inject @Inject
CapacityDao _capacityDao; CapacityDao _capacityDao;
@Inject @Inject

View File

@ -106,10 +106,11 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
@Inject protected AccountManager _accountMgr; @Inject protected AccountManager _accountMgr;
@Inject protected StorageManager _storageMgr; @Inject protected StorageManager _storageMgr;
@com.cloud.utils.component.Inject(adapter=StoragePoolAllocator.class) //@com.cloud.utils.component.Inject(adapter=StoragePoolAllocator.class)
protected Adapters<StoragePoolAllocator> _storagePoolAllocators; @Inject protected List<StoragePoolAllocator> _storagePoolAllocators;
@com.cloud.utils.component.Inject(adapter=HostAllocator.class)
protected Adapters<HostAllocator> _hostAllocators; //@com.cloud.utils.component.Inject(adapter=HostAllocator.class)
@Inject protected List<HostAllocator> _hostAllocators;
protected String _allocationAlgorithm = "random"; protected String _allocationAlgorithm = "random";
@ -714,17 +715,13 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
protected List<Host> findSuitableHosts(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo){ protected List<Host> findSuitableHosts(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo){
List<Host> suitableHosts = new ArrayList<Host>(); List<Host> suitableHosts = new ArrayList<Host>();
Enumeration<HostAllocator> enHost = _hostAllocators.enumeration(); for(HostAllocator allocator : _hostAllocators) {
s_logger.debug("Calling HostAllocators to find suitable hosts");
while (enHost.hasMoreElements()) {
final HostAllocator allocator = enHost.nextElement();
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, avoid, returnUpTo); suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, avoid, returnUpTo);
if (suitableHosts != null && !suitableHosts.isEmpty()) { if (suitableHosts != null && !suitableHosts.isEmpty()) {
break; break;
} }
} }
if(suitableHosts.isEmpty()){ if(suitableHosts.isEmpty()){
s_logger.debug("No suitable hosts found"); s_logger.debug("No suitable hosts found");
} }
@ -812,12 +809,8 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
} }
diskProfile.setUseLocalStorage(useLocalStorage); diskProfile.setUseLocalStorage(useLocalStorage);
boolean foundPotentialPools = false; boolean foundPotentialPools = false;
for(StoragePoolAllocator allocator : _storagePoolAllocators) {
Enumeration<StoragePoolAllocator> enPool = _storagePoolAllocators.enumeration();
while (enPool.hasMoreElements()) {
final StoragePoolAllocator allocator = enPool.nextElement();
final List<StoragePool> suitablePools = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, returnUpTo); final List<StoragePool> suitablePools = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, returnUpTo);
if (suitablePools != null && !suitablePools.isEmpty()) { if (suitablePools != null && !suitablePools.isEmpty()) {
suitableVolumeStoragePools.put(toBeCreated, suitablePools); suitableVolumeStoragePools.put(toBeCreated, suitablePools);
@ -825,7 +818,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
break; break;
} }
} }
if(!foundPotentialPools){ if(!foundPotentialPools){
s_logger.debug("No suitable pools found for volume: "+toBeCreated +" under cluster: "+plan.getClusterId()); s_logger.debug("No suitable pools found for volume: "+toBeCreated +" under cluster: "+plan.getClusterId());
//No suitable storage pools found under this cluster for this volume. - remove any suitable pools found for other volumes. //No suitable storage pools found under this cluster for this volume. - remove any suitable pools found for other volumes.

View File

@ -272,10 +272,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
RemoteAccessVpnService _vpnMgr; RemoteAccessVpnService _vpnMgr;
@Inject @Inject
PodVlanMapDao _podVlanMapDao; PodVlanMapDao _podVlanMapDao;
@com.cloud.utils.component.Inject(adapter = NetworkGuru.class)
Adapters<NetworkGuru> _networkGurus; //@com.cloud.utils.component.Inject(adapter = NetworkGuru.class)
@com.cloud.utils.component.Inject(adapter = NetworkElement.class) @Inject
Adapters<NetworkElement> _networkElements; List<NetworkGuru> _networkGurus;
// @com.cloud.utils.component.Inject(adapter = NetworkElement.class)
@Inject
List<NetworkElement> _networkElements;
@Inject @Inject
NetworkDomainDao _networkDomainDao; NetworkDomainDao _networkDomainDao;
@Inject @Inject
@ -351,7 +356,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override @Override
public NetworkElement getElementImplementingProvider(String providerName) { public NetworkElement getElementImplementingProvider(String providerName) {
String elementName = s_providerToNetworkElementMap.get(providerName); String elementName = s_providerToNetworkElementMap.get(providerName);
NetworkElement element = _networkElements.get(elementName); NetworkElement element = Adapters.getAdapterByName(_networkElements, elementName);
return element; return element;
} }
@ -1791,7 +1796,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkVO ntwkVO = _networksDao.findById(network.getId()); NetworkVO ntwkVO = _networksDao.findById(network.getId());
s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested); s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested);
NetworkGuru guru = _networkGurus.get(ntwkVO.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, ntwkVO.getGuruName());
if (requested != null && requested.getMode() == null) { if (requested != null && requested.getMode() == null) {
requested.setMode(network.getMode()); requested.setMode(network.getMode());
@ -1936,7 +1941,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
} }
try { try {
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
Network.State state = network.getState(); Network.State state = network.getState();
if (state == Network.State.Implemented || state == Network.State.Setup || state == Network.State.Implementing) { if (state == Network.State.Implemented || state == Network.State.Setup || state == Network.State.Implementing) {
s_logger.debug("Network id=" + networkId + " is already implemented"); s_logger.debug("Network id=" + networkId + " is already implemented");
@ -2124,7 +2129,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId()); Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId());
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
NicVO nic = _nicDao.findById(nicId); NicVO nic = _nicDao.findById(nicId);
NicProfile profile = null; NicProfile profile = null;
@ -2186,7 +2191,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkVO network = _networksDao.findById(nic.getNetworkId()); NetworkVO network = _networksDao.findById(nic.getNetworkId());
Integer networkRate = getNetworkRate(network.getId(), vm.getId()); Integer networkRate = getNetworkRate(network.getId(), vm.getId());
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate,
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
guru.updateNicProfile(profile, network); guru.updateNicProfile(profile, network);
@ -2216,7 +2221,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) { if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) {
Nic.State originalState = nic.getState(); Nic.State originalState = nic.getState();
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
nic.setState(Nic.State.Releasing); nic.setState(Nic.State.Releasing);
_nicDao.update(nic.getId(), nic); _nicDao.update(nic.getId(), nic);
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null,
@ -2262,7 +2267,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkVO network = _networksDao.findById(nic.getNetworkId()); NetworkVO network = _networksDao.findById(nic.getNetworkId());
Integer networkRate = getNetworkRate(network.getId(), vm.getId()); Integer networkRate = getNetworkRate(network.getId(), vm.getId());
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
guru.updateNicProfile(profile, network); guru.updateNicProfile(profile, network);
@ -2283,7 +2288,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkVO network = _networksDao.findById(networkId); NetworkVO network = _networksDao.findById(networkId);
Integer networkRate = getNetworkRate(network.getId(), vm.getId()); Integer networkRate = getNetworkRate(network.getId(), vm.getId());
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
guru.updateNicProfile(profile, network); guru.updateNicProfile(profile, network);
@ -2438,7 +2443,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkVO network = _networksDao.findById(nic.getNetworkId()); NetworkVO network = _networksDao.findById(nic.getNetworkId());
NicProfile profile = new NicProfile(nic, network, null, null, null, NicProfile profile = new NicProfile(nic, network, null, null, null,
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
guru.deallocate(network, profile, vm); guru.deallocate(network, profile, vm);
_nicDao.remove(nic.getId()); _nicDao.remove(nic.getId());
s_logger.debug("Removed nic id=" + nic.getId()); s_logger.debug("Removed nic id=" + nic.getId());
@ -3414,7 +3419,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now."); s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now.");
} }
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
NetworkProfile profile = convertNetworkToNetworkProfile(network.getId()); NetworkProfile profile = convertNetworkToNetworkProfile(network.getId());
guru.shutdown(profile, _networkOfferingDao.findById(network.getNetworkOfferingId())); guru.shutdown(profile, _networkOfferingDao.findById(network.getNetworkOfferingId()));
@ -3574,7 +3579,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Network id=" + networkId + " is destroyed successfully, cleaning up corresponding resources now."); s_logger.debug("Network id=" + networkId + " is destroyed successfully, cleaning up corresponding resources now.");
} }
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
Account owner = _accountMgr.getAccount(network.getAccountId()); Account owner = _accountMgr.getAccount(network.getAccountId());
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
@ -4258,7 +4263,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override @Override
public NetworkProfile convertNetworkToNetworkProfile(long networkId) { public NetworkProfile convertNetworkToNetworkProfile(long networkId) {
NetworkVO network = _networksDao.findById(networkId); NetworkVO network = _networksDao.findById(networkId);
NetworkGuru guru = _networkGurus.get(network.getGuruName()); NetworkGuru guru = Adapters.getAdapterByName(_networkGurus, network.getGuruName());
NetworkProfile profile = new NetworkProfile(network); NetworkProfile profile = new NetworkProfile(network);
guru.updateNetworkProfile(profile); guru.updateNetworkProfile(profile);

View File

@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.PostConstruct;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
@ -204,14 +205,18 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
protected HighAvailabilityManager _haMgr; protected HighAvailabilityManager _haMgr;
@Inject @Inject
protected StorageService _storageSvr; protected StorageService _storageSvr;
@com.cloud.utils.component.Inject(adapter = Discoverer.class) //@com.cloud.utils.component.Inject(adapter = Discoverer.class)
protected Adapters<? extends Discoverer> _discoverers; @Inject
protected List<? extends Discoverer> _discoverers;
@Inject @Inject
protected ClusterManager _clusterMgr; protected ClusterManager _clusterMgr;
@Inject @Inject
protected StoragePoolHostDao _storagePoolHostDao; protected StoragePoolHostDao _storagePoolHostDao;
@com.cloud.utils.component.Inject(adapter = PodAllocator.class)
protected Adapters<PodAllocator> _podAllocators = null; // @com.cloud.utils.component.Inject(adapter = PodAllocator.class)
@Inject
protected List<PodAllocator> _podAllocators = null;
@Inject @Inject
protected VMTemplateDao _templateDao; protected VMTemplateDao _templateDao;
@Inject @Inject
@ -226,6 +231,11 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
protected HashMap<Integer, List<ResourceListener>> _lifeCycleListeners = new HashMap<Integer, List<ResourceListener>>(); protected HashMap<Integer, List<ResourceListener>> _lifeCycleListeners = new HashMap<Integer, List<ResourceListener>>();
private HypervisorType _defaultSystemVMHypervisor; private HypervisorType _defaultSystemVMHypervisor;
@PostConstruct
public void init() {
// TODO initialize pod allocators here instead
}
private void insertListener(Integer event, ResourceListener listener) { private void insertListener(Integer event, ResourceListener listener) {
List<ResourceListener> lst = _lifeCycleListeners.get(event); List<ResourceListener> lst = _lifeCycleListeners.get(event);
if (lst == null) { if (lst == null) {
@ -497,13 +507,10 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
@Override @Override
public Discoverer getMatchingDiscover(Hypervisor.HypervisorType hypervisorType) { public Discoverer getMatchingDiscover(Hypervisor.HypervisorType hypervisorType) {
Enumeration<? extends Discoverer> en = _discoverers.enumeration(); for(Discoverer discoverer : _discoverers) {
while (en.hasMoreElements()) { if (discoverer.getHypervisorType() == hypervisorType)
Discoverer discoverer = en.nextElement();
if (discoverer.getHypervisorType() == hypervisorType) {
return discoverer; return discoverer;
} }
}
return null; return null;
} }
@ -670,10 +677,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
List<HostVO> hosts = new ArrayList<HostVO>(); List<HostVO> hosts = new ArrayList<HostVO>();
s_logger.info("Trying to add a new host at " + url + " in data center " + dcId); s_logger.info("Trying to add a new host at " + url + " in data center " + dcId);
Enumeration<? extends Discoverer> en = _discoverers.enumeration();
boolean isHypervisorTypeSupported = false; boolean isHypervisorTypeSupported = false;
while (en.hasMoreElements()) { for ( Discoverer discoverer : _discoverers) {
Discoverer discoverer = en.nextElement();
if (params != null) { if (params != null) {
discoverer.putParam(params); discoverer.putParam(params);
} }
@ -2161,9 +2166,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
@Override @Override
public Pair<HostPodVO, Long> findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set<Long> avoids) { public Pair<HostPodVO, Long> findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set<Long> avoids) {
final Enumeration en = _podAllocators.enumeration(); for(PodAllocator allocator : _podAllocators) {
while (en.hasMoreElements()) {
final PodAllocator allocator = (PodAllocator) en.nextElement();
final Pair<HostPodVO, Long> pod = allocator.allocateTo(template, offering, dc, accountId, avoids); final Pair<HostPodVO, Long> pod = allocator.allocateTo(template, offering, dc, accountId, avoids);
if (pod != null) { if (pod != null) {
return pod; return pod;

View File

@ -25,6 +25,7 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.cloud.agent.api.Command; import com.cloud.agent.api.Command;
@ -49,6 +50,7 @@ import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.dao.SecondaryStorageVmDao; import com.cloud.vm.dao.SecondaryStorageVmDao;
@Component @Component
@Primary
@Local(value = { SecondaryStorageVmManager.class }) @Local(value = { SecondaryStorageVmManager.class })
public class PremiumSecondaryStorageManagerImpl extends SecondaryStorageManagerImpl { public class PremiumSecondaryStorageManagerImpl extends SecondaryStorageManagerImpl {
private static final Logger s_logger = Logger.getLogger(PremiumSecondaryStorageManagerImpl.class); private static final Logger s_logger = Logger.getLogger(PremiumSecondaryStorageManagerImpl.class);

View File

@ -329,11 +329,11 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
protected DownloadMonitor _downloadMonitor; protected DownloadMonitor _downloadMonitor;
@Inject @Inject
protected ResourceTagDao _resourceTagDao; protected ResourceTagDao _resourceTagDao;
@Inject
protected List<StoragePoolAllocator> _storagePoolAllocators;
@com.cloud.utils.component.Inject(adapter = StoragePoolAllocator.class) @Inject
protected Adapters<StoragePoolAllocator> _storagePoolAllocators; protected List<StoragePoolDiscoverer> _discoverers;
@com.cloud.utils.component.Inject(adapter = StoragePoolDiscoverer.class)
protected Adapters<StoragePoolDiscoverer> _discoverers;
protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch; protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch;
@ -463,9 +463,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
protected StoragePoolVO findStoragePool(DiskProfile dskCh, final DataCenterVO dc, HostPodVO pod, Long clusterId, Long hostId, VMInstanceVO vm, final Set<StoragePool> avoid) { protected StoragePoolVO findStoragePool(DiskProfile dskCh, final DataCenterVO dc, HostPodVO pod, Long clusterId, Long hostId, VMInstanceVO vm, final Set<StoragePool> avoid) {
VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm); VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
Enumeration<StoragePoolAllocator> en = _storagePoolAllocators.enumeration(); for (StoragePoolAllocator allocator : _storagePoolAllocators) {
while (en.hasMoreElements()) {
final StoragePoolAllocator allocator = en.nextElement();
final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, dc.getId(), pod.getId(), clusterId, hostId, avoid, 1); final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, dc.getId(), pod.getId(), clusterId, hostId, avoid, 1);
if (poolList != null && !poolList.isEmpty()) { if (poolList != null && !poolList.isEmpty()) {
return (StoragePoolVO) poolList.get(0); return (StoragePoolVO) poolList.get(0);
@ -1354,11 +1352,10 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
hostPath.replaceFirst("/", ""); hostPath.replaceFirst("/", "");
pool = new StoragePoolVO(StoragePoolType.IscsiLUN, storageHost, port, hostPath); pool = new StoragePoolVO(StoragePoolType.IscsiLUN, storageHost, port, hostPath);
} else { } else {
Enumeration<StoragePoolDiscoverer> en = _discoverers.enumeration(); for (StoragePoolDiscoverer discoverer : _discoverers) {
while (en.hasMoreElements()) {
Map<StoragePoolVO, Map<String, String>> pools; Map<StoragePoolVO, Map<String, String>> pools;
try { try {
pools = en.nextElement().find(cmd.getZoneId(), podId, uri, details); pools = discoverer.find(cmd.getZoneId(), podId, uri, details);
} catch (DiscoveryException e) { } catch (DiscoveryException e) {
throw new IllegalArgumentException("Not enough information for discovery " + uri, e); throw new IllegalArgumentException("Not enough information for discovery " + uri, e);
} }

View File

@ -173,8 +173,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
private int _mgmt_port = 8250; private int _mgmt_port = 8250;
private String _name; private String _name;
@com.cloud.utils.component.Inject(adapter = SecondaryStorageVmAllocator.class) @Inject
private Adapters<SecondaryStorageVmAllocator> _ssVmAllocators; private List<SecondaryStorageVmAllocator> _ssVmAllocators;
@Inject @Inject
protected SecondaryStorageVmDao _secStorageVmDao; protected SecondaryStorageVmDao _secStorageVmDao;
@ -589,11 +589,9 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
private SecondaryStorageVmAllocator getCurrentAllocator() { private SecondaryStorageVmAllocator getCurrentAllocator() {
// for now, only one adapter is supported // for now, only one adapter is supported
Enumeration<SecondaryStorageVmAllocator> it = _ssVmAllocators.enumeration(); if(_ssVmAllocators.size() > 0)
if (it.hasMoreElements()) { return _ssVmAllocators.get(0);
return it.nextElement();
}
return null; return null;
} }

View File

@ -210,16 +210,16 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
ScheduledExecutorService _swiftTemplateSyncExecutor; ScheduledExecutorService _swiftTemplateSyncExecutor;
@com.cloud.utils.component.Inject (adapter=TemplateAdapter.class) @Inject
protected Adapters<TemplateAdapter> _adapters; protected List<TemplateAdapter> _adapters;
private TemplateAdapter getAdapter(HypervisorType type) { private TemplateAdapter getAdapter(HypervisorType type) {
TemplateAdapter adapter = null; TemplateAdapter adapter = null;
if (type == HypervisorType.BareMetal) { if (type == HypervisorType.BareMetal) {
adapter = _adapters.get(TemplateAdapterType.BareMetal.getName()); adapter = Adapters.getAdapterByName(_adapters, TemplateAdapterType.BareMetal.getName());
} else { } else {
// see HyervisorTemplateAdapter // see HyervisorTemplateAdapter
adapter = _adapters.get(TemplateAdapterType.Hypervisor.getName()); adapter = Adapters.getAdapterByName(_adapters, TemplateAdapterType.Hypervisor.getName());
} }
if (adapter == null) { if (adapter == null) {

View File

@ -230,10 +230,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
@Inject @Inject
protected NetworkDao _networkDao; protected NetworkDao _networkDao;
@com.cloud.utils.component.Inject(adapter = DeploymentPlanner.class) @Inject
protected Adapters<DeploymentPlanner> _planners; protected List<DeploymentPlanner> _planners;
@com.cloud.utils.component.Inject(adapter = HostAllocator.class) @Inject
protected Adapters<HostAllocator> _hostAllocators; protected Adapters<HostAllocator> _hostAllocators;
@Inject @Inject

View File

@ -95,9 +95,9 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager{
NetworkServiceMapDao _ntwkSrvcDao; NetworkServiceMapDao _ntwkSrvcDao;
@Inject @Inject
NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao; NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
@com.cloud.utils.component.Inject(adapter = NetworkElement.class) @Inject
Adapters<NetworkElement> _networkElements; List<NetworkElement> _networkElements;
private static HashMap<String, String> s_providerToNetworkElementMap = new HashMap<String, String>(); private static HashMap<String, String> s_providerToNetworkElementMap = new HashMap<String, String>();
private static final Logger s_logger = Logger.getLogger(MockNetworkManagerImpl.class); private static final Logger s_logger = Logger.getLogger(MockNetworkManagerImpl.class);

View File

@ -82,4 +82,12 @@ public class Adapters<T> implements Iterable<T> {
public boolean isSet() { public boolean isSet() {
return _map.size() != 0; return _map.size() != 0;
} }
public static <T extends Adapter> T getAdapterByName(List<T> adapters, String name) {
for(T adapter : adapters) {
if(adapter.getName().equals(name))
return adapter;
}
return null;
}
} }