Switch to setter injection for extensibility

Various classes are using member injection to inject extensible objects.
Really those object should come from an AdapterList that is injected in.
This patch switches the code to use setter injection that will later allow
spring to inject an AdapterList or something similar to allow
extensibility.
This commit is contained in:
Darren Shepherd 2013-09-30 09:45:07 -07:00
parent 692535f928
commit efbfae723e
12 changed files with 139 additions and 15 deletions

View File

@ -257,7 +257,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
this._hostAllocators = _hostAllocators; this._hostAllocators = _hostAllocators;
} }
@Inject
protected List<StoragePoolAllocator> _storagePoolAllocators; protected List<StoragePoolAllocator> _storagePoolAllocators;
@Inject @Inject
@ -3271,4 +3270,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VmOpWaitInterval}; VmOpWaitInterval};
} }
public List<StoragePoolAllocator> getStoragePoolAllocators() {
return _storagePoolAllocators;
}
@Inject
public void setStoragePoolAllocators(List<StoragePoolAllocator> storagePoolAllocators) {
this._storagePoolAllocators = storagePoolAllocators;
}
} }

View File

@ -99,7 +99,6 @@ public class VMEntityManagerImpl implements VMEntityManager {
@Inject @Inject
protected VirtualMachineManager _itMgr; protected VirtualMachineManager _itMgr;
@Inject
protected List<DeploymentPlanner> _planners; protected List<DeploymentPlanner> _planners;
@Inject @Inject
@ -257,4 +256,13 @@ public class VMEntityManagerImpl implements VMEntityManager {
return true; return true;
} }
public List<DeploymentPlanner> getPlanners() {
return _planners;
}
@Inject
public void setPlanners(List<DeploymentPlanner> planners) {
this._planners = planners;
}
} }

View File

@ -46,7 +46,7 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC
private static Map<RoleType, Set<String>> s_roleBasedApisMap = private static Map<RoleType, Set<String>> s_roleBasedApisMap =
new HashMap<RoleType, Set<String>>(); new HashMap<RoleType, Set<String>>();
@Inject List<PluggableService> _services; List<PluggableService> _services;
@Inject AccountService _accountService; @Inject AccountService _accountService;
protected StaticRoleBasedAPIAccessChecker() { protected StaticRoleBasedAPIAccessChecker() {
@ -95,4 +95,13 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC
} }
} }
} }
public List<PluggableService> getServices() {
return _services;
}
@Inject
public void setServices(List<PluggableService> _services) {
this._services = _services;
}
} }

View File

@ -169,8 +169,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
@Inject @Inject
private EntityManager _entityMgr; private EntityManager _entityMgr;
@Inject List<PluggableService> _pluggableServices; List<PluggableService> _pluggableServices;
@Inject List<APIChecker> _apiAccessCheckers; List<APIChecker> _apiAccessCheckers;
@Inject @Inject
protected ApiAsyncJobDispatcher _asyncDispatcher; protected ApiAsyncJobDispatcher _asyncDispatcher;
@ -1096,4 +1096,22 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
} }
return responseText; return responseText;
} }
public List<PluggableService> getPluggableServices() {
return _pluggableServices;
}
@Inject
public void setPluggableServices(List<PluggableService> _pluggableServices) {
this._pluggableServices = _pluggableServices;
}
public List<APIChecker> getApiAccessCheckers() {
return _apiAccessCheckers;
}
@Inject
public void setApiAccessCheckers(List<APIChecker> _apiAccessCheckers) {
this._apiAccessCheckers = _apiAccessCheckers;
}
} }

View File

@ -250,7 +250,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Inject @Inject
AlertManager _alertMgr; AlertManager _alertMgr;
// @com.cloud.utils.component.Inject(adapter = SecurityChecker.class) // @com.cloud.utils.component.Inject(adapter = SecurityChecker.class)
@Inject
List<SecurityChecker> _secChecker; List<SecurityChecker> _secChecker;
@Inject @Inject
@ -4934,5 +4933,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
return false; return false;
} }
public List<SecurityChecker> getSecChecker() {
return _secChecker;
}
@Inject
public void setSecChecker(List<SecurityChecker> secChecker) {
this._secChecker = secChecker;
}
} }

View File

@ -166,7 +166,6 @@ VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
private int _mgmt_port = 8250; private int _mgmt_port = 8250;
@Inject
private List<ConsoleProxyAllocator> _consoleProxyAllocators; private List<ConsoleProxyAllocator> _consoleProxyAllocators;
@Inject @Inject
@ -1702,4 +1701,13 @@ VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
public void prepareStop(VirtualMachineProfile profile) { public void prepareStop(VirtualMachineProfile profile) {
} }
public List<ConsoleProxyAllocator> getConsoleProxyAllocators() {
return _consoleProxyAllocators;
}
@Inject
public void setConsoleProxyAllocators(List<ConsoleProxyAllocator> consoleProxyAllocators) {
this._consoleProxyAllocators = consoleProxyAllocators;
}
} }

View File

@ -19,6 +19,7 @@ package com.cloud.hypervisor;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.ejb.Local; import javax.ejb.Local;
@ -26,6 +27,7 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -43,8 +45,8 @@ public class HypervisorGuruManagerImpl extends ManagerBase implements Hypervisor
@Inject HostDao _hostDao; @Inject HostDao _hostDao;
@Inject List<HypervisorGuru> _hvGuruList; List<HypervisorGuru> _hvGuruList;
Map<HypervisorType, HypervisorGuru> _hvGurus = new HashMap<HypervisorType, HypervisorGuru>(); Map<HypervisorType, HypervisorGuru> _hvGurus = new ConcurrentHashMap<HypervisorType, HypervisorGuru>();
@PostConstruct @PostConstruct
public void init() { public void init() {
@ -55,7 +57,19 @@ public class HypervisorGuruManagerImpl extends ManagerBase implements Hypervisor
@Override @Override
public HypervisorGuru getGuru(HypervisorType hypervisorType) { public HypervisorGuru getGuru(HypervisorType hypervisorType) {
return _hvGurus.get(hypervisorType); HypervisorGuru result = _hvGurus.get(hypervisorType);
if ( result == null ) {
for ( HypervisorGuru guru : _hvGuruList ) {
if ( guru.getHypervisorType() == hypervisorType ) {
_hvGurus.put(hypervisorType, guru);
result = guru;
break;
}
}
}
return result;
} }
@Override @Override
@ -68,4 +82,14 @@ public class HypervisorGuruManagerImpl extends ManagerBase implements Hypervisor
} }
return hostId; return hostId;
} }
public List<HypervisorGuru> getHvGuruList() {
return _hvGuruList;
}
@Inject
public void setHvGuruList(List<HypervisorGuru> hvGuruList) {
this._hvGuruList = hvGuruList;
}
} }

View File

@ -230,7 +230,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
@Inject @Inject
UsageEventDao _usageEventDao; UsageEventDao _usageEventDao;
@Inject List<NetworkGuru> _networkGurus; List<NetworkGuru> _networkGurus;
@Inject @Inject
NetworkDomainDao _networkDomainDao; NetworkDomainDao _networkDomainDao;
@ -3944,4 +3944,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return _networkMgr.listVmNics(vmId, nicId); return _networkMgr.listVmNics(vmId, nicId);
} }
public List<NetworkGuru> getNetworkGurus() {
return _networkGurus;
}
@Inject
public void setNetworkGurus(List<NetworkGuru> networkGurus) {
this._networkGurus = networkGurus;
}
} }

View File

@ -675,7 +675,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Inject @Inject
private HypervisorCapabilitiesDao _hypervisorCapabilitiesDao; private HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
private List<HostAllocator> _hostAllocators; private List<HostAllocator> _hostAllocators;
@Inject
private List<StoragePoolAllocator> _storagePoolAllocators; private List<StoragePoolAllocator> _storagePoolAllocators;
@Inject @Inject
private ResourceTagDao _resourceTagDao; private ResourceTagDao _resourceTagDao;
@ -3870,4 +3869,13 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
_dpMgr.cleanupVMReservations(); _dpMgr.cleanupVMReservations();
} }
public List<StoragePoolAllocator> getStoragePoolAllocators() {
return _storagePoolAllocators;
}
@Inject
public void setStoragePoolAllocators(List<StoragePoolAllocator> storagePoolAllocators) {
this._storagePoolAllocators = storagePoolAllocators;
}
} }

View File

@ -273,7 +273,6 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
protected VmDiskStatisticsDao _vmDiskStatsDao; protected VmDiskStatisticsDao _vmDiskStatsDao;
@Inject @Inject
protected VMSnapshotDao _vmSnapshotDao; protected VMSnapshotDao _vmSnapshotDao;
@Inject
protected List<StoragePoolAllocator> _storagePoolAllocators; protected List<StoragePoolAllocator> _storagePoolAllocators;
@Inject @Inject
ConfigurationDao _configDao; ConfigurationDao _configDao;
@ -1693,4 +1692,13 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
return true; return true;
} }
public List<StoragePoolAllocator> getStoragePoolAllocators() {
return _storagePoolAllocators;
}
@Inject
public void setStoragePoolAllocators(List<StoragePoolAllocator> storagePoolAllocators) {
this._storagePoolAllocators = storagePoolAllocators;
}
} }

View File

@ -169,7 +169,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
private int _mgmt_port = 8250; private int _mgmt_port = 8250;
@Inject
private List<SecondaryStorageVmAllocator> _ssVmAllocators; private List<SecondaryStorageVmAllocator> _ssVmAllocators;
@Inject @Inject
@ -1374,4 +1373,13 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
public void prepareStop(VirtualMachineProfile profile) { public void prepareStop(VirtualMachineProfile profile) {
} }
public List<SecondaryStorageVmAllocator> getSecondaryStorageVmAllocators() {
return _ssVmAllocators;
}
@Inject
public void setSecondaryStorageVmAllocators(List<SecondaryStorageVmAllocator> ssVmAllocators) {
this._ssVmAllocators = ssVmAllocators;
}
} }

View File

@ -291,7 +291,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
boolean _disableExtraction = false; boolean _disableExtraction = false;
ExecutorService _preloadExecutor; ExecutorService _preloadExecutor;
@Inject
protected List<TemplateAdapter> _adapters; protected List<TemplateAdapter> _adapters;
@Inject @Inject
@ -1823,4 +1822,13 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
public ConfigKey<?>[] getConfigKeys() { public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {AllowPublicUserTemplates}; return new ConfigKey<?>[] {AllowPublicUserTemplates};
} }
public List<TemplateAdapter> getTemplateAdapters() {
return _adapters;
}
@Inject
public void setTemplateAdapters(List<TemplateAdapter> adapters) {
this._adapters = adapters;
}
} }