Skip to content

Commit 6977cb3

Browse files
Sateesh ChodapuneediRohit Yadav
authored andcommitted
CLOUDSTACK-9684 Invalid zone id error while listing vmware zone
Issue ===== While listing datacenters associated with a zone, only zone Id validation is required. There is no need to have additional checks like zone is a legacy zone or not. Fix === Removed unnecessary checks over zone ID and just checking if zone with specified ID exists or not. Signed-off-by: Sateesh Chodapuneedi <sateesh.chodapuneedi@accelerite.com> (cherry picked from commit 0ef1c17) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent f8f71a5 commit 6977cb3

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
189189

190190
private String _rootDiskController = DiskControllerType.ide.toString();
191191

192-
private String _dataDiskController = DiskControllerType.osdefault.toString();
192+
private final String _dataDiskController = DiskControllerType.osdefault.toString();
193193

194194
private final Map<String, String> _storageMounts = new HashMap<String, String>();
195195

@@ -1111,8 +1111,8 @@ public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws Resourc
11111111
@Override
11121112
public boolean removeVmwareDatacenter(RemoveVmwareDcCmd cmd) throws ResourceInUseException {
11131113
Long zoneId = cmd.getZoneId();
1114-
// Validate zone
1115-
validateZone(zoneId);
1114+
// Validate Id of zone
1115+
doesZoneExist(zoneId);
11161116
// Zone validation to check if the zone already has resources.
11171117
// Association of VMware DC to zone is not allowed if zone already has resources added.
11181118
validateZoneWithResources(zoneId, "remove VMware datacenter to zone");
@@ -1180,10 +1180,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
11801180

11811181
private void validateZone(Long zoneId) throws InvalidParameterValueException {
11821182
// Check if zone with specified id exists
1183-
DataCenterVO zone = _dcDao.findById(zoneId);
1184-
if (zone == null) {
1185-
throw new InvalidParameterValueException("Can't find zone by the id specified.");
1186-
}
1183+
doesZoneExist(zoneId);
11871184
// Check if zone is legacy zone
11881185
if (isLegacyZone(zoneId)) {
11891186
throw new InvalidParameterValueException("The specified zone is legacy zone. Adding VMware datacenter to legacy zone is not supported.");
@@ -1226,7 +1223,7 @@ public List<? extends VmwareDatacenter> listVmwareDatacenters(ListVmwareDcsCmd c
12261223
long vmwareDcId;
12271224

12281225
// Validate if zone id parameter passed to API is valid
1229-
validateZone(zoneId);
1226+
doesZoneExist(zoneId);
12301227

12311228
// Check if zone is associated with VMware DC
12321229
vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId);
@@ -1243,6 +1240,17 @@ public List<? extends VmwareDatacenter> listVmwareDatacenters(ListVmwareDcsCmd c
12431240
return vmwareDcList;
12441241
}
12451242

1243+
private void doesZoneExist(Long zoneId) throws InvalidParameterValueException {
1244+
// Check if zone with specified id exists
1245+
DataCenterVO zone = _dcDao.findById(zoneId);
1246+
if (zone == null) {
1247+
throw new InvalidParameterValueException("Can't find zone by the id specified.");
1248+
}
1249+
if (s_logger.isTraceEnabled()) {
1250+
s_logger.trace("Zone with id:[" + zoneId + "] exists.");
1251+
}
1252+
}
1253+
12461254
@Override
12471255
public boolean hasNexusVSM(Long clusterId) {
12481256
ClusterVSMMapVO vsmMapVo = null;

0 commit comments

Comments
 (0)