From 742c9c9a45244d8f6dddbce8325f2c93c109ece0 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 19 Dec 2011 10:23:36 -0800 Subject: [PATCH] bug 12615: fixed resource limits - treat -1 as unlimited for domain limit status 12615: resolved fixed --- api/src/com/cloud/configuration/Resource.java | 2 ++ .../resourcelimit/ResourceLimitManagerImpl.java | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/src/com/cloud/configuration/Resource.java b/api/src/com/cloud/configuration/Resource.java index 4c9cda41058..f9a05f09143 100644 --- a/api/src/com/cloud/configuration/Resource.java +++ b/api/src/com/cloud/configuration/Resource.java @@ -18,6 +18,8 @@ package com.cloud.configuration; public interface Resource { + + public static final short RESOURCE_UNLIMITED = -1; public enum ResourceType{ user_vm ("user_vm", 0, ResourceOwnerType.Account, ResourceOwnerType.Domain), diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java index 6bc6a7f054e..9eb61dc8744 100755 --- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java +++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java @@ -200,7 +200,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{ @Override public long findCorrectResourceLimitForAccount(Account account, ResourceType type) { - long max = -1; //if resource limit is not found, then we treat it as unlimited + long max = Resource.RESOURCE_UNLIMITED; //if resource limit is not found, then we treat it as unlimited ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(account.getId(), ResourceOwnerType.Account, type); // Check if limit is configured for account @@ -224,7 +224,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{ @Override public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type) { - long max = -1; + long max = Resource.RESOURCE_UNLIMITED; // Check account ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(domain.getId(), ResourceOwnerType.Domain, type); @@ -274,7 +274,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{ // Check account limits long accountLimit = findCorrectResourceLimitForAccount(account, type); long potentialCount = _resourceCountDao.getResourceCount(account.getId(), ResourceOwnerType.Account, type) + numResources; - if (accountLimit != -1 && potentialCount > accountLimit) { + if (accountLimit != Resource.RESOURCE_UNLIMITED && potentialCount > accountLimit) { String message = "Maximum number of resources of type \"" + type + "\" for account name=" + account.getAccountName() + " in domain id=" + account.getDomainId() + " has been exceeded."; if (project != null) { @@ -295,7 +295,7 @@ 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) { + 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); @@ -458,8 +458,8 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{ Account caller = UserContext.current().getCaller(); if (max == null) { - max = new Long(-1); - } else if (max < -1) { + max = new Long(Resource.RESOURCE_UNLIMITED); + } else if (max.longValue() < Resource.RESOURCE_UNLIMITED) { throw new InvalidParameterValueException("Please specify either '-1' for an infinite limit, or a limit that is at least '0'."); }