From 08bb9eaf4753c43a4d195233ef57bfa2c2640521 Mon Sep 17 00:00:00 2001 From: prachi Date: Mon, 30 Jan 2012 16:39:04 -0800 Subject: [PATCH] Bug 11426 - UpdateResourceCount api: don't recalculate the resources for System account Changes: - Throw error is anyone tries to update the resource limits for ROOT domain using updateResourceLimit API - For ROOT domain always return -1 (infinite) limit - DB upgrade: remove any limits set for ROOT domain --- .../ResourceLimitManagerImpl.java | 30 ++++++++++++++----- setup/db/db/schema-2214to30.sql | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java index d84767d7d13..040b5182aaa 100755 --- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java +++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java @@ -230,7 +230,11 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{ @Override public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type) { long max = Resource.RESOURCE_UNLIMITED; - + + //no limits on ROOT domain + if(domain.getId() == Domain.ROOT_DOMAIN){ + return Resource.RESOURCE_UNLIMITED; + } // Check account ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(domain.getId(), ResourceOwnerType.Domain, type); @@ -240,6 +244,10 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{ // check domain hierarchy Long domainId = domain.getParent(); while ((domainId != null) && (limit == null)) { + + if(domainId == Domain.ROOT_DOMAIN){ + return Resource.RESOURCE_UNLIMITED; + } limit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type); DomainVO tmpDomain = _domainDao.findById(domainId); domainId = tmpDomain.getParent(); @@ -299,14 +307,16 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{ while (domainId != null) { DomainVO domain = _domainDao.findById(domainId); - ResourceLimitVO domainLimit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type); - if (domainLimit != null && domainLimit.getMax().longValue() != Resource.RESOURCE_UNLIMITED) { - long domainCount = _resourceCountDao.getResourceCount(domainId, ResourceOwnerType.Domain, type); - if ((domainCount + numResources) > domainLimit.getMax().longValue()) { - throw new ResourceAllocationException("Maximum number of resources of type '" + type + "' for domain id=" + domainId + " has been exceeded.", type); + //no limit check if it is ROOT domain + if(domainId != Domain.ROOT_DOMAIN){ + ResourceLimitVO domainLimit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type); + if (domainLimit != null && domainLimit.getMax().longValue() != Resource.RESOURCE_UNLIMITED) { + long domainCount = _resourceCountDao.getResourceCount(domainId, ResourceOwnerType.Domain, type); + if ((domainCount + numResources) > domainLimit.getMax().longValue()) { + throw new ResourceAllocationException("Maximum number of resources of type '" + type + "' for domain id=" + domainId + " has been exceeded.", type); + } } } - domainId = domain.getParent(); } } finally { @@ -502,6 +512,12 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{ Domain domain = _entityMgr.findById(Domain.class, domainId); _accountMgr.checkAccess(caller, domain); + + if (Domain.ROOT_DOMAIN == domainId.longValue()) { + // no one can add limits on ROOT domain, disallow... + throw new PermissionDeniedException("Cannot update resource limit for ROOT domain " + domainId + ", permission denied"); + } + if ((caller.getDomainId() == domainId.longValue()) && caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { // if the admin is trying to update their own domain, disallow... diff --git a/setup/db/db/schema-2214to30.sql b/setup/db/db/schema-2214to30.sql index ce9716f1805..d6b17927380 100755 --- a/setup/db/db/schema-2214to30.sql +++ b/setup/db/db/schema-2214to30.sql @@ -616,3 +616,5 @@ UPDATE `cloud`.`event` e set e.domain_id = (select acc.domain_id from account ac update vm_template set removed=now() where id=2; DELETE from `cloud`.`configuration` where name='firewall.rule.ui.enabled'; + +DELETE FROM `cloud`.`resource_limit` WHERE domain_id = 1 AND account_id IS NULL; \ No newline at end of file