weizhouapache commented on a change in pull request #5259:
URL: https://github.com/apache/cloudstack/pull/5259#discussion_r700965716



##########
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("#.######");

Review comment:
       @rhtyd 
   good question ......
   if it is a bug, we need to change all other usage parsers which use the same 
code. we have not received bug report about it until now.




-- 
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]


Reply via email to