From 012afceed22721bd2ace5c3b62bf068fe8ab1afe Mon Sep 17 00:00:00 2001 From: Prachi Damle Date: Mon, 12 Aug 2013 17:33:18 -0700 Subject: [PATCH] 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 --- .../DedicatedResourceManagerImpl.java | 21 ++++++++++ .../com/cloud/api/query/QueryManagerImpl.java | 12 +++--- .../ConfigurationManagerImpl.java | 42 +++++++++++++++---- 3 files changed, 62 insertions(+), 13 deletions(-) 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 9eaf589a01b..6a6b47ccfd7 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 diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index 4a40b54359b..2e716bc9f0b 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 diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 113df5ac869..f9b1e8ded87 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 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 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());