weizhouapache commented on a change in pull request #5259:
URL: https://github.com/apache/cloudstack/pull/5259#discussion_r700962149
##########
File path: usage/src/main/java/com/cloud/usage/parser/BackupUsageParser.java
##########
@@ -68,65 +66,33 @@ public static boolean parse(AccountVO account, Date
startDate, Date endDate) {
return true;
}
- final Map<Long, BackupInfo> vmUsageMap = new HashMap<>();
for (final UsageBackupVO usageBackup : usageBackups) {
final Long vmId = usageBackup.getVmId();
final Long zoneId = usageBackup.getZoneId();
final Long offeringId = usageBackup.getBackupOfferingId();
- if (vmUsageMap.get(vmId) == null) {
- vmUsageMap.put(vmId, new BackupUsageParser.BackupInfo(new
Backup.Metric(0L, 0L), zoneId, vmId, offeringId));
+ Date createdDate = usageBackup.getCreated();
+ Date removedDate = usageBackup.getRemoved();
+ if (createdDate.before(startDate)) {
+ createdDate = startDate;
}
- final Backup.Metric metric = vmUsageMap.get(vmId).getMetric();
- metric.setBackupSize(metric.getBackupSize() +
usageBackup.getSize());
- metric.setDataSize(metric.getDataSize() +
usageBackup.getProtectedSize());
- }
+ if (removedDate == null || removedDate.after(endDate)) {
+ removedDate = endDate;
+ }
+ final long duration = (removedDate.getTime() -
createdDate.getTime()) + 1;
+ final float usage = duration / 1000f / 60f / 60f;
+ DecimalFormat dFormat = new DecimalFormat("#.######");
+ String usageDisplay = dFormat.format(usage);
- for (final BackupInfo backupInfo : vmUsageMap.values()) {
- final Long vmId = backupInfo.getVmId();
- final Long zoneId = backupInfo.getZoneId();
- final Long offeringId = backupInfo.getOfferingId();
- final Double rawUsage = (double)
backupInfo.getMetric().getBackupSize();
- final Double sizeGib = rawUsage / (1024.0 * 1024.0 * 1024.0);
- final String description = String.format("Backup usage VM ID: %d",
vmId);
- final String usageDisplay = String.format("%.4f GiB", sizeGib);
+ final Double rawUsage = (double) usageBackup.getSize();
+ final String description = String.format("Backup usage VM ID: %d,
backup offering: %d", vmId, offeringId);
final UsageVO usageRecord =
- new UsageVO(zoneId, account.getAccountId(),
account.getDomainId(), description, usageDisplay,
- UsageTypes.BACKUP, rawUsage, vmId, null,
offeringId, null, vmId,
- backupInfo.getMetric().getBackupSize(),
backupInfo.getMetric().getDataSize(), startDate, endDate);
+ new UsageVO(zoneId, account.getAccountId(),
account.getDomainId(), description, usageDisplay + " Hrs",
Review comment:
@rhtyd
I have checked the usage for snapshots and volumes - cloudstack displays
running time for both. see
https://github.com/apache/cloudstack/blob/main/usage/src/main/java/com/cloud/usage/parser/VolumeUsageParser.java#L150-L153
https://github.com/apache/cloudstack/blob/main/usage/src/main/java/com/cloud/usage/parser/VMSnapshotUsageParser.java#L131-L134
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]