Skip to content

Commit d7ca18e

Browse files
author
Marcus Sorensen
committed
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
1 parent 639fb38 commit d7ca18e

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎server/src/com/cloud/event/ActionEventUtils.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ private static void publishOnEventBus(long userId, long accountId, String eventC
183183

184184
private static long getDomainId(long accountId){
185185
AccountVO account = _accountDao.findByIdIncludingRemoved(accountId);
186+
if (account == null) {
187+
s_logger.error("Failed to find account(including removed ones) by id '" + accountId + "'");
188+
return 0;
189+
}
186190
return account.getDomainId();
187191
}
188192

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,13 +2172,6 @@ public boolean destroyNetwork(long networkId, ReservationContext context) {
21722172
return false;
21732173
}
21742174

2175-
// Don't allow to delete network via api call when it has vms assigned to it
2176-
int nicCount = getActiveNicsInNetwork(networkId);
2177-
if (nicCount > 0) {
2178-
s_logger.debug("Unable to remove the network id=" + networkId + " as it has active Nics.");
2179-
return false;
2180-
}
2181-
21822175
// Make sure that there are no user vms in the network that are not Expunged/Error
21832176
List<UserVmVO> userVms = _userVmDao.listByNetworkIdAndStates(networkId);
21842177

@@ -2189,6 +2182,15 @@ public boolean destroyNetwork(long networkId, ReservationContext context) {
21892182
}
21902183
}
21912184

2185+
// Don't allow to delete network via api call when it has vms assigned to it
2186+
int nicCount = getActiveNicsInNetwork(networkId);
2187+
if (nicCount > 0) {
2188+
s_logger.debug("The network id=" + networkId + " has active Nics, but shouldn't.");
2189+
// at this point we have already determined that there are no active user vms in network
2190+
// if the op_networks table shows active nics, it's a bug in releasing nics updating op_networks
2191+
_networksDao.changeActiveNicsBy(networkId, (-1 * nicCount));
2192+
}
2193+
21922194
//In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network
21932195
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
21942196
if (zone.getNetworkType() == NetworkType.Basic) {

0 commit comments

Comments
 (0)