Bug 5947: decrement resource count when deployVM fails for direct attached case

This commit is contained in:
kishan 2010-09-17 17:17:17 +05:30
parent 7c6ad35ed7
commit 91d4715b4b
1 changed files with 12 additions and 3 deletions

View File

@ -2777,6 +2777,8 @@ public class UserVmManagerImpl implements UserVmManager {
throw new InternalErrorException("We could not find a suitable pool for creating this directly attached vm");
}
_accountMgr.decrementResourceCount(account.getId(), ResourceType.user_vm);
_accountMgr.decrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
return null;
}
@ -2837,6 +2839,9 @@ public class UserVmManagerImpl implements UserVmManager {
throw new InternalErrorException("No template or ISO was specified for the VM.");
}
boolean isIso = Storage.ImageFormat.ISO.equals(template.getFormat());
long numVolumes = (isIso || (diskOffering == null)) ? 1 : 2;
Transaction txn = Transaction.currentTxn();
try {
UserVmVO vm = null;
@ -2893,8 +2898,6 @@ public class UserVmManagerImpl implements UserVmManager {
_networkGroupManager.addInstanceToGroups(vmId, networkGroups);
_accountMgr.incrementResourceCount(account.getId(), ResourceType.user_vm);
boolean isIso = Storage.ImageFormat.ISO.equals(template.getFormat());
long numVolumes = (isIso || (diskOffering == null)) ? 1 : 2;
_accountMgr.incrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
txn.commit();
@ -2926,7 +2929,9 @@ public class UserVmManagerImpl implements UserVmManager {
{
s_logger.debug("failed to create VM instance : " + name);
}
_accountMgr.decrementResourceCount(account.getId(), ResourceType.user_vm);
_accountMgr.decrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
txn.commit();
return null;
}
@ -2955,11 +2960,15 @@ public class UserVmManagerImpl implements UserVmManager {
return _vmDao.findById(vmId);
} catch (ResourceAllocationException rae) {
_accountMgr.decrementResourceCount(account.getId(), ResourceType.user_vm);
_accountMgr.decrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
if (s_logger.isInfoEnabled()) {
s_logger.info("Failed to create VM for account " + accountId + " due to maximum number of virtual machines exceeded.");
}
throw rae;
} catch (Throwable th) {
_accountMgr.decrementResourceCount(account.getId(), ResourceType.user_vm);
_accountMgr.decrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
s_logger.error("Unable to create vm", th);
throw new CloudRuntimeException("Unable to create vm", th);
}