From ebdd7a68fa1d32104782cedc0004d08403134854 Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 8 Feb 2011 19:01:06 -0800 Subject: [PATCH] bug 8491: remove corresponding record from resource_limits table when limit is updated with -1 value status 8491: resolved fixed --- .../api/commands/UpdateResourceLimitCmd.java | 2 +- server/src/com/cloud/user/AccountManagerImpl.java | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java b/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java index 0cb5da1ae8a..f2b841b930c 100644 --- a/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java +++ b/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java @@ -87,7 +87,7 @@ public class UpdateResourceLimitCmd extends BaseCmd { @Override public void execute(){ ResourceLimit result = _accountService.updateResourceLimit(this); - if (result != null){ + if (result != null || (result == null && max != null && max.longValue() == -1L)){ ResourceLimitResponse response = _responseGenerator.createResourceLimitResponse(result); response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 72af7dd14a4..a1b8ca1ac25 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -645,10 +645,19 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag List limits = _resourceLimitDao.search(sc, searchFilter); if (limits.size() == 1) { - // Update the existing limit ResourceLimitVO limit = limits.get(0); - _resourceLimitDao.update(limit.getId(), max); - return _resourceLimitDao.findById(limit.getId()); + //if limit is set to -1, remove the record + if (max != null && max.longValue() == -1L) { + //this parameter is needed by API as it expects the object to be returned and updates the UI with the object's new "max" parameter + ResourceLimitVO limitToReturn = limit; + limitToReturn.setMax(-1L); + _resourceLimitDao.remove(limit.getId()); + return limitToReturn; + } else { + // Update the existing limit + _resourceLimitDao.update(limit.getId(), max); + return _resourceLimitDao.findById(limit.getId()); + } } else { // Persist the new Limit return _resourceLimitDao.persist(new ResourceLimitVO(domainId, accountId, resourceType, max));