From 566ce3e625933033c6cdabe078ed788f5e88c6c9 Mon Sep 17 00:00:00 2001 From: Marcus Sorensen Date: Tue, 30 Jul 2013 11:20:15 -0600 Subject: [PATCH] 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 1375204815 -0600 --- server/src/com/cloud/event/ActionEventUtils.java | 4 ++++ .../com/cloud/network/NetworkManagerImpl.java | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/server/src/com/cloud/event/ActionEventUtils.java b/server/src/com/cloud/event/ActionEventUtils.java index 7b727cd6f9d..4ee6e9e0a2b 100755 --- a/server/src/com/cloud/event/ActionEventUtils.java +++ b/server/src/com/cloud/event/ActionEventUtils.java @@ -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(); } } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 5fc4f418ca2..b4890970ec1 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -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 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) {