Skip to content

Commit efbfae7

Browse files
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.
1 parent 692535f commit efbfae7

12 files changed

Lines changed: 139 additions & 15 deletions

File tree

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ public void setHostAllocators(List<HostAllocator> _hostAllocators) {
257257
this._hostAllocators = _hostAllocators;
258258
}
259259

260-
@Inject
261260
protected List<StoragePoolAllocator> _storagePoolAllocators;
262261

263262
@Inject
@@ -3271,4 +3270,13 @@ public ConfigKey<?>[] getConfigKeys() {
32713270
VmOpWaitInterval};
32723271
}
32733272

3273+
public List<StoragePoolAllocator> getStoragePoolAllocators() {
3274+
return _storagePoolAllocators;
3275+
}
3276+
3277+
@Inject
3278+
public void setStoragePoolAllocators(List<StoragePoolAllocator> storagePoolAllocators) {
3279+
this._storagePoolAllocators = storagePoolAllocators;
3280+
}
3281+
32743282
}

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public class VMEntityManagerImpl implements VMEntityManager {
9999
@Inject
100100
protected VirtualMachineManager _itMgr;
101101

102-
@Inject
103102
protected List<DeploymentPlanner> _planners;
104103

105104
@Inject
@@ -257,4 +256,13 @@ public boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller) throw
257256
return true;
258257
}
259258

259+
public List<DeploymentPlanner> getPlanners() {
260+
return _planners;
261+
}
262+
263+
@Inject
264+
public void setPlanners(List<DeploymentPlanner> planners) {
265+
this._planners = planners;
266+
}
267+
260268
}

plugins/acl/static-role-based/src/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC
4646
private static Map<RoleType, Set<String>> s_roleBasedApisMap =
4747
new HashMap<RoleType, Set<String>>();
4848

49-
@Inject List<PluggableService> _services;
49+
List<PluggableService> _services;
5050
@Inject AccountService _accountService;
5151

5252
protected StaticRoleBasedAPIAccessChecker() {
@@ -95,4 +95,13 @@ private void processMapping(Map<String, String> configMap) {
9595
}
9696
}
9797
}
98+
99+
public List<PluggableService> getServices() {
100+
return _services;
101+
}
102+
103+
@Inject
104+
public void setServices(List<PluggableService> _services) {
105+
this._services = _services;
106+
}
98107
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
169169
@Inject
170170
private EntityManager _entityMgr;
171171

172-
@Inject List<PluggableService> _pluggableServices;
173-
@Inject List<APIChecker> _apiAccessCheckers;
172+
List<PluggableService> _pluggableServices;
173+
List<APIChecker> _apiAccessCheckers;
174174

175175
@Inject
176176
protected ApiAsyncJobDispatcher _asyncDispatcher;
@@ -1096,4 +1096,22 @@ public String getSerializedApiError(ServerApiException ex, Map<String, Object[]>
10961096
}
10971097
return responseText;
10981098
}
1099+
1100+
public List<PluggableService> getPluggableServices() {
1101+
return _pluggableServices;
1102+
}
1103+
1104+
@Inject
1105+
public void setPluggableServices(List<PluggableService> _pluggableServices) {
1106+
this._pluggableServices = _pluggableServices;
1107+
}
1108+
1109+
public List<APIChecker> getApiAccessCheckers() {
1110+
return _apiAccessCheckers;
1111+
}
1112+
1113+
@Inject
1114+
public void setApiAccessCheckers(List<APIChecker> _apiAccessCheckers) {
1115+
this._apiAccessCheckers = _apiAccessCheckers;
1116+
}
10991117
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
250250
@Inject
251251
AlertManager _alertMgr;
252252
// @com.cloud.utils.component.Inject(adapter = SecurityChecker.class)
253-
@Inject
254253
List<SecurityChecker> _secChecker;
255254

256255
@Inject
@@ -4934,5 +4933,14 @@ private boolean checkOverlapPortableIpRange(int regionId, String newStartIpStr,
49344933
return false;
49354934
}
49364935

4936+
public List<SecurityChecker> getSecChecker() {
4937+
return _secChecker;
4938+
}
4939+
4940+
@Inject
4941+
public void setSecChecker(List<SecurityChecker> secChecker) {
4942+
this._secChecker = secChecker;
4943+
}
4944+
49374945

49384946
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
166166

167167
private int _mgmt_port = 8250;
168168

169-
@Inject
170169
private List<ConsoleProxyAllocator> _consoleProxyAllocators;
171170

172171
@Inject
@@ -1702,4 +1701,13 @@ protected HostVO findConsoleProxyHostByName(String name) {
17021701
public void prepareStop(VirtualMachineProfile profile) {
17031702
}
17041703

1704+
public List<ConsoleProxyAllocator> getConsoleProxyAllocators() {
1705+
return _consoleProxyAllocators;
1706+
}
1707+
1708+
@Inject
1709+
public void setConsoleProxyAllocators(List<ConsoleProxyAllocator> consoleProxyAllocators) {
1710+
this._consoleProxyAllocators = consoleProxyAllocators;
1711+
}
1712+
17051713
}

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
import java.util.HashMap;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.concurrent.ConcurrentHashMap;
2223

2324
import javax.annotation.PostConstruct;
2425
import javax.ejb.Local;
2526
import javax.inject.Inject;
2627
import javax.naming.ConfigurationException;
2728

2829
import com.cloud.utils.Pair;
30+
2931
import org.apache.log4j.Logger;
3032
import org.springframework.stereotype.Component;
3133

@@ -43,8 +45,8 @@ public class HypervisorGuruManagerImpl extends ManagerBase implements Hypervisor
4345

4446
@Inject HostDao _hostDao;
4547

46-
@Inject List<HypervisorGuru> _hvGuruList;
47-
Map<HypervisorType, HypervisorGuru> _hvGurus = new HashMap<HypervisorType, HypervisorGuru>();
48+
List<HypervisorGuru> _hvGuruList;
49+
Map<HypervisorType, HypervisorGuru> _hvGurus = new ConcurrentHashMap<HypervisorType, HypervisorGuru>();
4850

4951
@PostConstruct
5052
public void init() {
@@ -55,7 +57,19 @@ public void init() {
5557

5658
@Override
5759
public HypervisorGuru getGuru(HypervisorType hypervisorType) {
58-
return _hvGurus.get(hypervisorType);
60+
HypervisorGuru result = _hvGurus.get(hypervisorType);
61+
62+
if ( result == null ) {
63+
for ( HypervisorGuru guru : _hvGuruList ) {
64+
if ( guru.getHypervisorType() == hypervisorType ) {
65+
_hvGurus.put(hypervisorType, guru);
66+
result = guru;
67+
break;
68+
}
69+
}
70+
}
71+
72+
return result;
5973
}
6074

6175
@Override
@@ -68,4 +82,14 @@ public long getGuruProcessedCommandTargetHost(long hostId, Command cmd) {
6882
}
6983
return hostId;
7084
}
85+
86+
public List<HypervisorGuru> getHvGuruList() {
87+
return _hvGuruList;
88+
}
89+
90+
@Inject
91+
public void setHvGuruList(List<HypervisorGuru> hvGuruList) {
92+
this._hvGuruList = hvGuruList;
93+
}
94+
7195
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
230230
@Inject
231231
UsageEventDao _usageEventDao;
232232

233-
@Inject List<NetworkGuru> _networkGurus;
233+
List<NetworkGuru> _networkGurus;
234234

235235
@Inject
236236
NetworkDomainDao _networkDomainDao;
@@ -3944,4 +3944,13 @@ public List<? extends Nic> listNics(ListNicsCmd cmd) {
39443944
return _networkMgr.listVmNics(vmId, nicId);
39453945
}
39463946

3947+
public List<NetworkGuru> getNetworkGurus() {
3948+
return _networkGurus;
3949+
}
3950+
3951+
@Inject
3952+
public void setNetworkGurus(List<NetworkGuru> networkGurus) {
3953+
this._networkGurus = networkGurus;
3954+
}
3955+
39473956
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
675675
@Inject
676676
private HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
677677
private List<HostAllocator> _hostAllocators;
678-
@Inject
679678
private List<StoragePoolAllocator> _storagePoolAllocators;
680679
@Inject
681680
private ResourceTagDao _resourceTagDao;
@@ -3870,4 +3869,13 @@ public void cleanupVMReservations() {
38703869

38713870
_dpMgr.cleanupVMReservations();
38723871
}
3872+
3873+
public List<StoragePoolAllocator> getStoragePoolAllocators() {
3874+
return _storagePoolAllocators;
3875+
}
3876+
3877+
@Inject
3878+
public void setStoragePoolAllocators(List<StoragePoolAllocator> storagePoolAllocators) {
3879+
this._storagePoolAllocators = storagePoolAllocators;
3880+
}
38733881
}

server/src/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
273273
protected VmDiskStatisticsDao _vmDiskStatsDao;
274274
@Inject
275275
protected VMSnapshotDao _vmSnapshotDao;
276-
@Inject
277276
protected List<StoragePoolAllocator> _storagePoolAllocators;
278277
@Inject
279278
ConfigurationDao _configDao;
@@ -1693,4 +1692,13 @@ public boolean configure(String name, Map<String, Object> params) {
16931692
return true;
16941693
}
16951694

1695+
public List<StoragePoolAllocator> getStoragePoolAllocators() {
1696+
return _storagePoolAllocators;
1697+
}
1698+
1699+
@Inject
1700+
public void setStoragePoolAllocators(List<StoragePoolAllocator> storagePoolAllocators) {
1701+
this._storagePoolAllocators = storagePoolAllocators;
1702+
}
1703+
16961704
}

0 commit comments

Comments
 (0)