Skip to content

Commit ff6b3fd

Browse files
author
Alex Huang
committed
Removed getzone
1 parent 89b5459 commit ff6b3fd

21 files changed

Lines changed: 194 additions & 180 deletions

File tree

api/src/com/cloud/configuration/ConfigurationService.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020

2121
import javax.naming.NamingException;
2222

23-
import com.cloud.exception.InvalidParameterValueException;
24-
import com.cloud.exception.InsufficientCapacityException;
25-
import com.cloud.exception.ConcurrentOperationException;
26-
import com.cloud.exception.ResourceUnavailableException;
27-
import com.cloud.exception.ResourceAllocationException;
28-
2923
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
3024
import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd;
3125
import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd;
@@ -52,19 +46,23 @@
5246
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
5347
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
5448
import org.apache.cloudstack.config.Configuration;
49+
import org.apache.cloudstack.region.PortableIp;
50+
import org.apache.cloudstack.region.PortableIpRange;
5551

5652
import com.cloud.dc.DataCenter;
5753
import com.cloud.dc.Pod;
5854
import com.cloud.dc.Vlan;
55+
import com.cloud.exception.ConcurrentOperationException;
56+
import com.cloud.exception.InsufficientCapacityException;
57+
import com.cloud.exception.InvalidParameterValueException;
58+
import com.cloud.exception.ResourceAllocationException;
59+
import com.cloud.exception.ResourceUnavailableException;
5960
import com.cloud.network.Networks.TrafficType;
6061
import com.cloud.offering.DiskOffering;
6162
import com.cloud.offering.NetworkOffering;
6263
import com.cloud.offering.ServiceOffering;
6364
import com.cloud.user.Account;
6465

65-
import org.apache.cloudstack.region.PortableIp;
66-
import org.apache.cloudstack.region.PortableIpRange;
67-
6866
public interface ConfigurationService {
6967

7068
/**
@@ -265,8 +263,6 @@ public interface ConfigurationService {
265263

266264
List<? extends NetworkOffering> listNetworkOfferings(TrafficType trafficType, boolean systemOnly);
267265

268-
DataCenter getZone(long id);
269-
270266
ServiceOffering getServiceOffering(long serviceOfferingId);
271267

272268
Long getDefaultPageSize();

api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public Long getNetworkId() {
164164
return null;
165165
}
166166

167-
DataCenter zone = _configService.getZone(zoneId);
167+
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
168168
if (zone.getNetworkType() == NetworkType.Advanced) {
169169
List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(),
170170
_accountService.getAccount(getEntityOwnerId()));
@@ -218,7 +218,7 @@ public long getEntityOwnerId() {
218218

219219
NetworkOffering offering = _configService.getNetworkOffering(network.getNetworkOfferingId());
220220

221-
DataCenter zone = _configService.getZone(network.getDataCenterId());
221+
DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
222222
if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) {
223223
// Since the basic zone network is owned by 'Root' domain, domain access checkers will fail for the
224224
// accounts in non-root domains while acquiring public IP. So add an exception for the 'Basic' zone

api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public long getNetworkId() {
164164
}
165165

166166
if (zoneId != null) {
167-
DataCenter zone = _configService.getZone(zoneId);
167+
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
168168
if (zone.getNetworkType() == NetworkType.Advanced) {
169169
List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId()));
170170
if (networks.size() == 0) {

api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public void create() throws ResourceAllocationException{
455455
//Verify that all objects exist before passing them to the service
456456
Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
457457

458-
DataCenter zone = _configService.getZone(zoneId);
458+
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
459459
if (zone == null) {
460460
throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
461461
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ public void advanceReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object
19021902
ResourceUnavailableException {
19031903
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
19041904

1905-
DataCenter dc = _configMgr.getZone(vm.getDataCenterId());
1905+
DataCenter dc = _entityMgr.findById(DataCenter.class, vm.getDataCenterId());
19061906
Host host = _hostDao.findById(vm.getHostId());
19071907
Cluster cluster = null;
19081908
if (host != null) {
@@ -2771,7 +2771,7 @@ public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile
27712771

27722772
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null);
27732773

2774-
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
2774+
DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
27752775
Host host = _hostDao.findById(vm.getHostId());
27762776
DeployDestination dest = new DeployDestination(dc, null, null, host);
27772777

@@ -2840,7 +2840,7 @@ public boolean removeNicFromVm(VirtualMachine vm, Nic nic) throws ConcurrentOper
28402840
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null,
28412841
null, null, null);
28422842

2843-
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
2843+
DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
28442844
Host host = _hostDao.findById(vm.getHostId());
28452845
DeployDestination dest = new DeployDestination(dc, null, null, host);
28462846
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
@@ -2904,7 +2904,7 @@ public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broad
29042904
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null,
29052905
null, null, null);
29062906

2907-
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
2907+
DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
29082908
Host host = _hostDao.findById(vm.getHostId());
29092909
DeployDestination dest = new DeployDestination(dc, null, null, host);
29102910
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());

plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
import com.cloud.resource.UnableDeleteHostException;
122122
import com.cloud.user.Account;
123123
import com.cloud.utils.component.AdapterBase;
124+
import com.cloud.utils.db.EntityManager;
124125
import com.cloud.utils.db.Transaction;
125126
import com.cloud.utils.exception.CloudRuntimeException;
126127
import com.cloud.utils.net.NetUtils;
@@ -136,6 +137,8 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
136137
private static final Logger s_logger = Logger.getLogger(CiscoVnmcElement.class);
137138
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
138139

140+
@Inject
141+
EntityManager _entityMgr;
139142
@Inject
140143
AgentManager _agentMgr;
141144
@Inject
@@ -275,7 +278,7 @@ public boolean implement(Network network, NetworkOffering offering,
275278
DeployDestination dest, ReservationContext context)
276279
throws ConcurrentOperationException, ResourceUnavailableException,
277280
InsufficientCapacityException {
278-
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
281+
DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
279282

280283
if (zone.getNetworkType() == NetworkType.Basic) {
281284
s_logger.debug("Not handling network implement in zone of type " + NetworkType.Basic);

plugins/network-elements/cisco-vnmc/test/com/cloud/network/element/CiscoVnmcElementTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import com.cloud.offering.NetworkOffering;
8484
import com.cloud.resource.ResourceManager;
8585
import com.cloud.user.Account;
86+
import com.cloud.utils.db.EntityManager;
8687
import com.cloud.utils.net.Ip;
8788
import com.cloud.vm.ReservationContext;
8889

@@ -102,6 +103,7 @@ public class CiscoVnmcElementTest {
102103
CiscoNexusVSMDeviceDao _vsmDeviceDao = mock(CiscoNexusVSMDeviceDao.class);
103104
VlanDao _vlanDao = mock(VlanDao.class);
104105
IpAddressManager _ipAddrMgr = mock(IpAddressManager.class);
106+
EntityManager _entityMgr = mock(EntityManager.class);
105107

106108
@Before
107109
public void setUp() throws ConfigurationException {
@@ -117,6 +119,7 @@ public void setUp() throws ConfigurationException {
117119
_element._clusterVsmMapDao = _clusterVsmMapDao;
118120
_element._vsmDeviceDao = _vsmDeviceDao;
119121
_element._vlanDao = _vlanDao;
122+
_element._entityMgr = _entityMgr;
120123

121124
// Standard responses
122125
when(_networkModel.isProviderForNetwork(Provider.CiscoVnmc, 1L)).thenReturn(true);
@@ -164,7 +167,7 @@ public void implementTest() throws ConcurrentOperationException, ResourceUnavail
164167

165168
DataCenter dc = mock(DataCenter.class);
166169
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
167-
when(_configMgr.getZone(network.getDataCenterId())).thenReturn(dc);
170+
when(_entityMgr.findById(DataCenter.class, network.getDataCenterId())).thenReturn(dc);
168171

169172
List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
170173
devices.add(mock(CiscoVnmcControllerVO.class));

0 commit comments

Comments
 (0)