cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ro...@apache.org
Subject [cloudstack] branch master updated: storage: publish delete usage event for snapshot deletion (#3212)
Date Wed, 10 Apr 2019 11:43:04 GMT
This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new 491a10b  storage: publish delete usage event for snapshot deletion (#3212)
491a10b is described below

commit 491a10be0c77716ead01961f50328f5d81c6497c
Author: Rohit Yadav <rohit@apache.org>
AuthorDate: Wed Apr 10 17:12:55 2019 +0530

    storage: publish delete usage event for snapshot deletion (#3212)
    
    Problem: Users are billed for destroyed VMs with VM snapshots because usage records don't
get that the VM and VM snapshots are removed.
    Root Cause: The destroyVirtualMachine and expungeVirtualMachine APIs were removing VM
snapshots but not generating VMSNAPSHOT.DELETE usage event due to which the VM snapshots were
not marked as removed in the usage_vmsnapshot table.
    Solution: The issue was fixed by emitting the proper usage event for all the VM snapshots
of a VM that is destroyed.
---
 .../cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java    | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java
b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java
index ebe8b27..19777f0 100644
--- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java
+++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java
@@ -423,6 +423,12 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements
VMSnapshot
             s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested");
             throw new CloudRuntimeException("Failed to change vm snapshot state with event
ExpungeRequested: " + e.getMessage());
         }
+        UserVm userVm = userVmDao.findById(vmSnapshot.getVmId());
+        List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
+        for (VolumeObjectTO volumeTo: volumeTOs) {
+            volumeTo.setSize(0);
+            publishUsageEvent(EventTypes.EVENT_VM_SNAPSHOT_DELETE, vmSnapshot, userVm, volumeTo);
+        }
         return vmSnapshotDao.remove(vmSnapshot.getId());
     }
 }


Mime
View raw message