mirror of https://github.com/apache/cloudstack.git
Bug 5947: decrement resource count when deployVM fails for direct attached case
This commit is contained in:
parent
e001d7e577
commit
808f17cbdb
|
|
@ -2581,6 +2581,8 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||
_eventDao.persist(event);
|
||||
String eventParams = "\nvmName=" + name + "\nsoId=" + serviceOfferingId + "\ndoId=" + diskOfferingIdentifier + "\ntId=" + templateId + "\ndcId=" + dataCenterId;
|
||||
event.setParameters(eventParams);
|
||||
_accountMgr.decrementResourceCount(account.getId(), ResourceType.user_vm);
|
||||
_accountMgr.decrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
|
||||
txn.commit();
|
||||
return null;
|
||||
}
|
||||
|
|
@ -2633,6 +2635,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;
|
||||
|
|
@ -2689,8 +2694,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();
|
||||
|
||||
|
|
@ -2737,6 +2740,8 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||
_eventDao.persist(event);
|
||||
String eventParams = "\nvmName=" + name + "\nsoId=" + serviceOfferingId + "\ndoId=" + diskOfferingIdentifier + "\ntId=" + templateId + "\ndcId=" + dataCenterId;
|
||||
event.setParameters(eventParams);
|
||||
_accountMgr.decrementResourceCount(account.getId(), ResourceType.user_vm);
|
||||
_accountMgr.decrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
|
||||
txn.commit();
|
||||
return null;
|
||||
}
|
||||
|
|
@ -2756,11 +2761,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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue