Skip to content

Commit 012afce

Browse files
author
Prachi Damle
committed
CLOUDSTACK-4276 Dedicated Resources: Private Zone functionality issues
Changes: createZone API: - This API takes in domainid, set it to the zone record in the data_center table updateZone API: - This API uses 'isPublic' flag to set a private zone to public - if this flag is set and the zone is dedicated, release the dedication and remove the domainid from the data_center table listZone API: - This API already has 'domainid' parameter. We should allow list zones by domain for Root admin. DedicateZone API: - set domainid in the data_center table ReleaseDedicatedZone API: - remove zoneid from the data_center table
1 parent 96ca70e commit 012afce

3 files changed

Lines changed: 62 additions & 13 deletions

File tree

plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ public List<DedicatedResourceVO> dedicateZone(Long zoneId, Long domainId, String
237237
dedicatedResource.setAccountId(accountId);
238238
}
239239
dedicatedResource = _dedicatedDao.persist(dedicatedResource);
240+
241+
// save the domainId in the zone
242+
dc.setDomainId(domainId);
243+
if (!_zoneDao.update(zoneId, dc)) {
244+
throw new CloudRuntimeException(
245+
"Failed to dedicate zone, could not set domainId. Please contact Cloud Support.");
246+
}
247+
240248
} catch (Exception e) {
241249
s_logger.error("Unable to dedicate zone due to " + e.getMessage(), e);
242250
throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support.");
@@ -905,6 +913,19 @@ public boolean releaseDedicatedResource(Long zoneId, Long podId, Long clusterId,
905913
if (!_dedicatedDao.remove(resourceId)) {
906914
throw new CloudRuntimeException("Failed to delete Resource " + resourceId);
907915
}
916+
if (zoneId != null) {
917+
// remove the domainId set in zone
918+
DataCenterVO dc = _zoneDao.findById(zoneId);
919+
if (dc != null) {
920+
dc.setDomainId(null);
921+
dc.setDomain(null);
922+
if (!_zoneDao.update(zoneId, dc)) {
923+
throw new CloudRuntimeException(
924+
"Failed to release dedicated zone, could not clear domainId. Please contact Cloud Support.");
925+
}
926+
}
927+
}
928+
908929
txn.commit();
909930

910931
// find the group associated and check if there are any more

server/src/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,12 +2497,14 @@ private Pair<List<DataCenterJoinVO>, Integer> listDataCentersInternal(ListZonesB
24972497

24982498
/*
24992499
* List all resources due to Explicit Dedication except the
2500-
* dedicated resources of other account if (domainId != null) { //
2501-
* for domainId != null // right now, we made the decision to only
2502-
* list zones associated // with this domain, private zone
2503-
* sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); } else
2500+
* dedicated resources of other account
25042501
*/
2505-
if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) {
2502+
if (domainId != null && account.getType() == Account.ACCOUNT_TYPE_ADMIN) { //
2503+
// for domainId != null // right now, we made the decision to
2504+
// only
2505+
// / list zones associated // with this domain, private zone
2506+
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
2507+
} else if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) {
25062508
// it was decided to return all zones for the user's domain, and
25072509
// everything above till root
25082510
// list all zones belonging to this domain, and all of its

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,14 @@ public boolean deleteZone(DeleteZoneCmd cmd) {
15431543
DedicatedResourceVO dr = _dedicatedDao.findByZoneId(zoneId);
15441544
if (dr != null) {
15451545
_dedicatedDao.remove(dr.getId());
1546+
// find the group associated and check if there are any more
1547+
// resources under that group
1548+
List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(dr
1549+
.getAffinityGroupId());
1550+
if (resourcesInGroup.isEmpty()) {
1551+
// delete the group
1552+
_affinityGroupService.deleteAffinityGroup(dr.getAffinityGroupId(), null, null, null);
1553+
}
15461554
}
15471555
}
15481556

@@ -1695,12 +1703,6 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
16951703
}
16961704
}
16971705

1698-
// update a private zone to public; not vice versa
1699-
if (isPublic != null && isPublic) {
1700-
zone.setDomainId(null);
1701-
zone.setDomain(null);
1702-
}
1703-
17041706
Transaction txn = Transaction.currentTxn();
17051707
txn.start();
17061708

@@ -1752,6 +1754,29 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
17521754
if (dhcpProvider != null) {
17531755
zone.setDhcpProvider(dhcpProvider);
17541756
}
1757+
1758+
// update a private zone to public; not vice versa
1759+
if (isPublic != null && isPublic) {
1760+
zone.setDomainId(null);
1761+
zone.setDomain(null);
1762+
1763+
// release the dedication for this zone
1764+
DedicatedResourceVO resource = _dedicatedDao.findByZoneId(zoneId);
1765+
Long resourceId = null;
1766+
if (resource != null) {
1767+
resourceId = resource.getId();
1768+
if (!_dedicatedDao.remove(resourceId)) {
1769+
throw new CloudRuntimeException("Failed to delete dedicated Zone Resource " + resourceId);
1770+
}
1771+
// find the group associated and check if there are any more
1772+
// resources under that group
1773+
List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(resource.getAffinityGroupId());
1774+
if (resourcesInGroup.isEmpty()) {
1775+
// delete the group
1776+
_affinityGroupService.deleteAffinityGroup(resource.getAffinityGroupId(), null, null, null);
1777+
}
1778+
}
1779+
}
17551780

17561781
if (!_zoneDao.update(zoneId, zone)) {
17571782
throw new CloudRuntimeException("Failed to edit zone. Please contact Cloud Support.");
@@ -1794,7 +1819,8 @@ public DataCenterVO createZone(long userId, String zoneName, String dns1, String
17941819
txn.start();
17951820
// Create the new zone in the database
17961821
DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr,
1797-
null, null, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled,
1822+
domain, domainId, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled,
1823+
isLocalStorageEnabled,
17981824
ip6Dns1, ip6Dns2);
17991825
if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
18001826
Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
@@ -1807,7 +1833,7 @@ public DataCenterVO createZone(long userId, String zoneName, String dns1, String
18071833
zone = _zoneDao.persist(zone);
18081834
if (domainId != null) {
18091835
// zone is explicitly dedicated to this domain
1810-
// create affinity group associated.
1836+
// create affinity group associated and dedicate the zone.
18111837
AffinityGroup group = createDedicatedAffinityGroup(null, domainId, null);
18121838
DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null,
18131839
domainId, null, group.getId());

0 commit comments

Comments
 (0)