From fb2ed48304820a2aa6b57708a860876d2fb36c7d Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 5 Mar 2012 15:41:30 -0800 Subject: [PATCH] bug 14103: mark account for cleanup only in cleanupAccount and disableAccount method, not in the callers methods status 14103: resolved fixed --- .../com/cloud/user/AccountManagerImpl.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 4839e482c31..8d71445b664 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -1078,6 +1078,9 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag s_logger.info("Cleanup for account " + account.getId() + (accountCleanupNeeded ? " is needed." : " is not needed.")); if (accountCleanupNeeded) { _accountDao.markForCleanup(accountId); + } else { + account.setNeedsCleanup(false); + _accountDao.update(accountId, account); } } } @@ -1101,9 +1104,18 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag success = _accountDao.update(Long.valueOf(accountId), acctForUpdate); if (success) { - if (!doDisableAccount(accountId)) { - s_logger.warn("Failed to disable account " + account + " resources as a part of disableAccount call, marking the account for cleanup"); - _accountDao.markForCleanup(accountId); + boolean disableAccountResult = false; + try { + disableAccountResult = doDisableAccount(accountId); + } finally { + if (!disableAccountResult) { + s_logger.warn("Failed to disable account " + account + " resources as a part of disableAccount call, marking the account for cleanup"); + _accountDao.markForCleanup(accountId); + } else { + acctForUpdate = _accountDao.createForUpdate(); + account.setNeedsCleanup(false); + _accountDao.update(accountId, account); + } } } } @@ -1773,14 +1785,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag s_logger.info("Found " + removedAccounts.size() + " removed accounts to cleanup"); for (AccountVO account : removedAccounts) { s_logger.debug("Cleaning up " + account.getId()); - try { - if (cleanupAccount(account, getSystemUser().getId(), getSystemAccount())) { - account.setNeedsCleanup(false); - _accountDao.update(account.getId(), account); - } - } catch (Exception e) { - s_logger.error("Skipping due to error on account " + account.getId(), e); - } + cleanupAccount(account, getSystemUser().getId(), getSystemAccount()); } //cleanup disabled accounts @@ -1789,10 +1794,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag for (AccountVO account : disabledAccounts) { s_logger.debug("Cleaning up " + account.getId()); try { - if (disableAccount(account.getId())) { - account.setNeedsCleanup(false); - _accountDao.update(account.getId(), account); - } + disableAccount(account.getId()); } catch (Exception e) { s_logger.error("Skipping due to error on account " + account.getId(), e); }