diff --git a/server/src/com/cloud/api/commands/ListResourceLimitsCmd.java b/server/src/com/cloud/api/commands/ListResourceLimitsCmd.java index 742934b34dd..bf69e45aa47 100644 --- a/server/src/com/cloud/api/commands/ListResourceLimitsCmd.java +++ b/server/src/com/cloud/api/commands/ListResourceLimitsCmd.java @@ -110,7 +110,7 @@ public class ListResourceLimitsCmd extends BaseListCmd { } } - resourceLimitResponse.setResourceType(limit.getType().ordinal()); + resourceLimitResponse.setResourceType(Integer.valueOf(limit.getType().ordinal()).toString()); resourceLimitResponse.setMax(limit.getMax()); resourceLimitResponse.setResponseName("resourcelimit"); diff --git a/server/src/com/cloud/api/commands/UpdateResourceLimitCmd.java b/server/src/com/cloud/api/commands/UpdateResourceLimitCmd.java index 361b66f2cd9..df7b12f75cc 100644 --- a/server/src/com/cloud/api/commands/UpdateResourceLimitCmd.java +++ b/server/src/com/cloud/api/commands/UpdateResourceLimitCmd.java @@ -103,7 +103,7 @@ public class UpdateResourceLimitCmd extends BaseCmd { response.setDomainName(ApiDBUtils.findDomainById(accountTemp.getDomainId()).getName()); } } - response.setResourceType(limit.getType().ordinal()); + response.setResourceType(Integer.valueOf(limit.getType().ordinal()).toString()); response.setMax(limit.getMax()); response.setResponseName(getName()); diff --git a/server/src/com/cloud/api/response/ResourceLimitResponse.java b/server/src/com/cloud/api/response/ResourceLimitResponse.java index 5b4ba74a4df..3c501397201 100644 --- a/server/src/com/cloud/api/response/ResourceLimitResponse.java +++ b/server/src/com/cloud/api/response/ResourceLimitResponse.java @@ -31,7 +31,7 @@ public class ResourceLimitResponse extends BaseResponse { private String domainName; @SerializedName("resourcetype") @Param(description="resource type. Values include 0, 1, 2, 3, 4. See the resourceType parameter for more information on these values.") - private Integer resourceType; + private String resourceType; @SerializedName("max") @Param(description="the maximum number of the resource. A -1 means the resource currently has no limit.") private Long max; @@ -60,11 +60,11 @@ public class ResourceLimitResponse extends BaseResponse { this.domainName = domainName; } - public Integer getResourceType() { + public String getResourceType() { return resourceType; } - public void setResourceType(Integer resourceType) { + public void setResourceType(String resourceType) { this.resourceType = resourceType; } diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 0759115fc98..b7282e96750 100644 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -410,6 +410,7 @@ public class AccountManagerImpl implements AccountManager { public ResourceLimitVO updateResourceLimit(UpdateResourceLimitCmd cmd) throws InvalidParameterValueException { Account account = (Account)UserContext.current().getAccount(); + String accountName = cmd.getAccountName(); Long domainId = cmd.getDomainId(); Long max = cmd.getMax(); Integer type = cmd.getResourceType(); @@ -447,9 +448,9 @@ public class AccountManagerImpl implements AccountManager { } if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) { - if ((domainId != null) && (account.getAccountName() == null) && domainId.equals(account.getDomainId())) { + if ((domainId != null) && (accountName == null) && domainId.equals(account.getDomainId())) { // if the admin is trying to update their own domain, disallow... - throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update resource limit for " + ((account.getAccountName() == null) ? "" : "account " + account.getAccountName() + " in ") + "domain " + domainId + ", permission denied"); + throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update resource limit for domain " + domainId + ", permission denied"); } // If there is an existing ROOT domain limit, make sure its max isn't being exceeded @@ -471,15 +472,12 @@ public class AccountManagerImpl implements AccountManager { if (domainId == null) { throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to update resource limit, unable to determine domain in which to update limit."); - } else if (account != null) { - if (account.getAccountName() != null) { - Account userAccount = _accountDao.findActiveAccount(account.getAccountName(), domainId); - if (userAccount == null) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find account by name " + account.getAccountName() + " in domain with id " + domainId); - } - accountId = userAccount.getId(); - domainId = userAccount.getDomainId(); + } else if (accountName != null) { + Account userAccount = _accountDao.findActiveAccount(accountName, domainId); + if (userAccount == null) { + throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find account by name " + account.getAccountName() + " in domain with id " + domainId); } + accountId = userAccount.getId(); } if (accountId != null) domainId = null;