From a8b89bea4f37a54267694b9a49be6b5bec91f0b0 Mon Sep 17 00:00:00 2001 From: Nitin Mehta Date: Sun, 9 Nov 2014 23:01:28 -0800 Subject: [PATCH] CLOUDSTACK-7870: When Vm deployments fail and end in error state volume count should be decremented --- .../cloudstack/engine/orchestration/VolumeOrchestrator.java | 4 ++++ server/src/com/cloud/vm/UserVmManagerImpl.java | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index 4b40d5abbb4..826e2eebd66 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -1380,9 +1380,13 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } else { volService.destroyVolume(volume.getId()); } + // FIXME - All this is boiler plate code and should be done as part of state transition. This shouldn't be part of orchestrator. // publish usage event for the volume UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume()); + _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplay()); + //FIXME - why recalculate and not decrement + _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.primary_storage.getOrdinal()); } catch (Exception e) { s_logger.debug("Failed to destroy volume" + volume.getId(), e); throw new CloudRuntimeException("Failed to destroy volume" + volume.getId(), e); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index ba07211e6d8..8096841066b 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -4785,7 +4785,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir newVol = volumeMgr.allocateDuplicateVolume(root, null); } - // Create Usage event for the newly created volume + // 1. Save usage event and update resource count for user vm volumes + _resourceLimitMgr.incrementResourceCount(newVol.getAccountId(), ResourceType.volume, newVol.isDisplay()); + _resourceLimitMgr.incrementResourceCount(newVol.getAccountId(), ResourceType.primary_storage, newVol.isDisplay(), new Long(newVol.getSize())); + // 2. Create Usage event for the newly created volume UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, newVol.getAccountId(), newVol.getDataCenterId(), newVol.getId(), newVol.getName(), newVol.getDiskOfferingId(), template.getId(), newVol.getSize()); _usageEventDao.persist(usageEvent);