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
This commit is contained in:
prachi 2012-01-30 16:39:04 -08:00
parent 37a7989623
commit 08bb9eaf47
2 changed files with 25 additions and 7 deletions

View File

@ -230,7 +230,11 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
@Override @Override
public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type) { public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type) {
long max = Resource.RESOURCE_UNLIMITED; long max = Resource.RESOURCE_UNLIMITED;
//no limits on ROOT domain
if(domain.getId() == Domain.ROOT_DOMAIN){
return Resource.RESOURCE_UNLIMITED;
}
// Check account // Check account
ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(domain.getId(), ResourceOwnerType.Domain, type); ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(domain.getId(), ResourceOwnerType.Domain, type);
@ -240,6 +244,10 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
// check domain hierarchy // check domain hierarchy
Long domainId = domain.getParent(); Long domainId = domain.getParent();
while ((domainId != null) && (limit == null)) { while ((domainId != null) && (limit == null)) {
if(domainId == Domain.ROOT_DOMAIN){
return Resource.RESOURCE_UNLIMITED;
}
limit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type); limit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type);
DomainVO tmpDomain = _domainDao.findById(domainId); DomainVO tmpDomain = _domainDao.findById(domainId);
domainId = tmpDomain.getParent(); domainId = tmpDomain.getParent();
@ -299,14 +307,16 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
while (domainId != null) { while (domainId != null) {
DomainVO domain = _domainDao.findById(domainId); DomainVO domain = _domainDao.findById(domainId);
ResourceLimitVO domainLimit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type); //no limit check if it is ROOT domain
if (domainLimit != null && domainLimit.getMax().longValue() != Resource.RESOURCE_UNLIMITED) { if(domainId != Domain.ROOT_DOMAIN){
long domainCount = _resourceCountDao.getResourceCount(domainId, ResourceOwnerType.Domain, type); ResourceLimitVO domainLimit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type);
if ((domainCount + numResources) > domainLimit.getMax().longValue()) { if (domainLimit != null && domainLimit.getMax().longValue() != Resource.RESOURCE_UNLIMITED) {
throw new ResourceAllocationException("Maximum number of resources of type '" + type + "' for domain id=" + domainId + " has been exceeded.", type); 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(); domainId = domain.getParent();
} }
} finally { } finally {
@ -502,6 +512,12 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
Domain domain = _entityMgr.findById(Domain.class, domainId); Domain domain = _entityMgr.findById(Domain.class, domainId);
_accountMgr.checkAccess(caller, domain); _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 ((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... // if the admin is trying to update their own domain, disallow...

View File

@ -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; update vm_template set removed=now() where id=2;
DELETE from `cloud`.`configuration` where name='firewall.rule.ui.enabled'; DELETE from `cloud`.`configuration` where name='firewall.rule.ui.enabled';
DELETE FROM `cloud`.`resource_limit` WHERE domain_id = 1 AND account_id IS NULL;