DaanHoogland commented on code in PR #7225:
URL: https://github.com/apache/cloudstack/pull/7225#discussion_r1106883627


##########
server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java:
##########
@@ -1096,6 +1096,26 @@ protected void runInContext() {
             }
         }
 
+        private void syncBackupMetrics(final BackupProvider backupProvider, 
final Map<VirtualMachine, Backup.Metric> metrics) {
+            for (final VirtualMachine vm : metrics.keySet()) {
+                try {
+                    final Backup.Metric metric = metrics.get(vm);
+                    if (metric != null) {
+                        LOG.debug(String.format("Trying to sync backups of VM 
[%s] using backup provider [%s].", vm.getUuid(), backupProvider.getName()));
+                        // Sync out-of-band backups
+                        backupProvider.syncBackups(vm, metric);
+                        // Emit a usage event, update usage metric for the VM 
by the usage server
+                        
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_BACKUP_USAGE_METRIC, 
vm.getAccountId(),
+                                vm.getDataCenterId(), vm.getId(), "Backup-" + 
vm.getHostName() + "-" + vm.getUuid(),
+                                vm.getBackupOfferingId(), null, 
metric.getBackupSize(), metric.getDataSize(),
+                                Backup.class.getSimpleName(), vm.getUuid());
+                    }
+                } catch (final Exception e) {
+                    LOG.error(String.format("Failed to sync backup usage 
metrics and out-of-band backups of VM [%s] due to: [%s].", vm.getUuid(), 
e.getMessage()), e);
+                }

Review Comment:
   for readability the try block can be a separate method.



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