Summary: Fix null pointer and op_networks blocker to account cleanup

Detail: Accounts can fail in cleanup/gc process due to inconsistent op_networks
table and null pointer in looking up account for event publishing.

BUG-ID: CLOUDSTACK-3957
Signed-off-by: Marcus Sorensen <marcus@betterservers.com> 1375204815 -0600
This commit is contained in:
Marcus Sorensen 2013-07-30 11:20:15 -06:00
parent 2b0946c6db
commit 566ce3e625
2 changed files with 13 additions and 7 deletions

View File

@ -200,6 +200,10 @@ public class ActionEventUtils {
private static long getDomainId(long accountId){
AccountVO account = _accountDao.findByIdIncludingRemoved(accountId);
if (account == null) {
s_logger.error("Failed to find account(including removed ones) by id '" + accountId + "'");
return 0;
}
return account.getDomainId();
}
}

View File

@ -2805,13 +2805,6 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
return false;
}
// Don't allow to delete network via api call when it has vms assigned to it
int nicCount = getActiveNicsInNetwork(networkId);
if (nicCount > 0) {
s_logger.debug("Unable to remove the network id=" + networkId + " as it has active Nics.");
return false;
}
// Make sure that there are no user vms in the network that are not Expunged/Error
List<UserVmVO> userVms = _userVmDao.listByNetworkIdAndStates(networkId);
@ -2822,6 +2815,15 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
}
}
// Don't allow to delete network via api call when it has vms assigned to it
int nicCount = getActiveNicsInNetwork(networkId);
if (nicCount > 0) {
s_logger.debug("The network id=" + networkId + " has active Nics, but shouldn't.");
// at this point we have already determined that there are no active user vms in network
// if the op_networks table shows active nics, it's a bug in releasing nics updating op_networks
_networksDao.changeActiveNicsBy(networkId, (-1 * nicCount));
}
//In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic) {