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 Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/012afcee Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/012afcee Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/012afcee Branch: refs/heads/master Commit: 012afceed22721bd2ace5c3b62bf068fe8ab1afe Parents: 96ca70e Author: Prachi Damle <[email protected]> Authored: Mon Aug 12 17:33:18 2013 -0700 Committer: Prachi Damle <[email protected]> Committed: Tue Sep 3 20:02:56 2013 -0700 ---------------------------------------------------------------------- .../dedicated/DedicatedResourceManagerImpl.java | 21 ++++++++++ .../com/cloud/api/query/QueryManagerImpl.java | 12 +++--- .../configuration/ConfigurationManagerImpl.java | 42 ++++++++++++++++---- 3 files changed, 62 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/012afcee/plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java ---------------------------------------------------------------------- diff --git a/plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java b/plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java index 9eaf589..6a6b47c 100755 --- a/plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java +++ b/plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java @@ -237,6 +237,14 @@ public class DedicatedResourceManagerImpl implements DedicatedService { dedicatedResource.setAccountId(accountId); } dedicatedResource = _dedicatedDao.persist(dedicatedResource); + + // save the domainId in the zone + dc.setDomainId(domainId); + if (!_zoneDao.update(zoneId, dc)) { + throw new CloudRuntimeException( + "Failed to dedicate zone, could not set domainId. Please contact Cloud Support."); + } + } catch (Exception e) { s_logger.error("Unable to dedicate zone due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); @@ -905,6 +913,19 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (!_dedicatedDao.remove(resourceId)) { throw new CloudRuntimeException("Failed to delete Resource " + resourceId); } + if (zoneId != null) { + // remove the domainId set in zone + DataCenterVO dc = _zoneDao.findById(zoneId); + if (dc != null) { + dc.setDomainId(null); + dc.setDomain(null); + if (!_zoneDao.update(zoneId, dc)) { + throw new CloudRuntimeException( + "Failed to release dedicated zone, could not clear domainId. Please contact Cloud Support."); + } + } + } + txn.commit(); // find the group associated and check if there are any more http://git-wip-us.apache.org/repos/asf/cloudstack/blob/012afcee/server/src/com/cloud/api/query/QueryManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index 4a40b54..2e716bc 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -2497,12 +2497,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { /* * List all resources due to Explicit Dedication except the - * dedicated resources of other account if (domainId != null) { // - * for domainId != null // right now, we made the decision to only - * list zones associated // with this domain, private zone - * sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); } else + * dedicated resources of other account */ - if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) { + if (domainId != null && account.getType() == Account.ACCOUNT_TYPE_ADMIN) { // + // for domainId != null // right now, we made the decision to + // only + // / list zones associated // with this domain, private zone + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); + } else if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) { // it was decided to return all zones for the user's domain, and // everything above till root // list all zones belonging to this domain, and all of its http://git-wip-us.apache.org/repos/asf/cloudstack/blob/012afcee/server/src/com/cloud/configuration/ConfigurationManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 113df5a..f9b1e8d 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1543,6 +1543,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati DedicatedResourceVO dr = _dedicatedDao.findByZoneId(zoneId); if (dr != null) { _dedicatedDao.remove(dr.getId()); + // find the group associated and check if there are any more + // resources under that group + List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(dr + .getAffinityGroupId()); + if (resourcesInGroup.isEmpty()) { + // delete the group + _affinityGroupService.deleteAffinityGroup(dr.getAffinityGroupId(), null, null, null); + } } } @@ -1695,12 +1703,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } - // update a private zone to public; not vice versa - if (isPublic != null && isPublic) { - zone.setDomainId(null); - zone.setDomain(null); - } - Transaction txn = Transaction.currentTxn(); txn.start(); @@ -1752,6 +1754,29 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (dhcpProvider != null) { zone.setDhcpProvider(dhcpProvider); } + + // update a private zone to public; not vice versa + if (isPublic != null && isPublic) { + zone.setDomainId(null); + zone.setDomain(null); + + // release the dedication for this zone + DedicatedResourceVO resource = _dedicatedDao.findByZoneId(zoneId); + Long resourceId = null; + if (resource != null) { + resourceId = resource.getId(); + if (!_dedicatedDao.remove(resourceId)) { + throw new CloudRuntimeException("Failed to delete dedicated Zone Resource " + resourceId); + } + // find the group associated and check if there are any more + // resources under that group + List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(resource.getAffinityGroupId()); + if (resourcesInGroup.isEmpty()) { + // delete the group + _affinityGroupService.deleteAffinityGroup(resource.getAffinityGroupId(), null, null, null); + } + } + } if (!_zoneDao.update(zoneId, zone)) { throw new CloudRuntimeException("Failed to edit zone. Please contact Cloud Support."); @@ -1794,7 +1819,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati txn.start(); // Create the new zone in the database DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr, - null, null, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled, + domain, domainId, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, + isLocalStorageEnabled, ip6Dns1, ip6Dns2); if (allocationStateStr != null && !allocationStateStr.isEmpty()) { Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr); @@ -1807,7 +1833,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati zone = _zoneDao.persist(zone); if (domainId != null) { // zone is explicitly dedicated to this domain - // create affinity group associated. + // create affinity group associated and dedicate the zone. AffinityGroup group = createDedicatedAffinityGroup(null, domainId, null); DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null, domainId, null, group.getId());
