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.
This commit is contained in:
Rohit Yadav 2019-04-10 17:12:55 +05:30 committed by GitHub
parent 1af5dedfb1
commit 491a10be0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -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());
}
}