Skip to content

Commit 4ea0dcd

Browse files
nitinmehyadvr
authored andcommitted
CLOUDSTACK-7870: When Vm deployments fail and end in error state volume count should be decremented
(cherry picked from commit a8b89be) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 54d08a8 commit 4ea0dcd

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,7 @@ public void destroyVolume(Volume volume) {
14641464
} else {
14651465
volService.destroyVolume(volume.getId());
14661466
}
1467+
// FIXME - All this is boiler plate code and should be done as part of state transition. This shouldn't be part of orchestrator.
14671468
// publish usage event for the volume
14681469
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
14691470
Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume());

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4812,7 +4812,10 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId)
48124812
newVol = volumeMgr.allocateDuplicateVolume(root, null);
48134813
}
48144814

4815-
// Create Usage event for the newly created volume
4815+
// 1. Save usage event and update resource count for user vm volumes
4816+
_resourceLimitMgr.incrementResourceCount(newVol.getAccountId(), ResourceType.volume, newVol.isDisplay());
4817+
_resourceLimitMgr.incrementResourceCount(newVol.getAccountId(), ResourceType.primary_storage, newVol.isDisplay(), new Long(newVol.getSize()));
4818+
// 2. Create Usage event for the newly created volume
48164819
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, newVol.getAccountId(), newVol.getDataCenterId(), newVol.getId(), newVol.getName(), newVol.getDiskOfferingId(), template.getId(), newVol.getSize());
48174820
_usageEventDao.persist(usageEvent);
48184821

0 commit comments

Comments
 (0)