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


##########
server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java:
##########
@@ -585,17 +595,64 @@ public boolean restoreBackup(final Long backupId) {
 
         final BackupOffering offering = 
backupOfferingDao.findByIdIncludingRemoved(vm.getBackupOfferingId());
         if (offering == null) {
-            throw new CloudRuntimeException("Failed to find backup offering of 
the VM backup");
+            throw new CloudRuntimeException("Failed to find backup offering of 
the VM backup.");
         }
 
-        final BackupProvider backupProvider = 
getBackupProvider(offering.getProvider());
-        if (!backupProvider.restoreVMFromBackup(vm, backup)) {
-            throw new CloudRuntimeException("Error restoring VM from backup ID 
" + backup.getId());
+        String backupDetailsInMessage = 
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(backup, "uuid", 
"externalId", "vmId", "type", "status", "date");
+        try {
+            updateVmState(vm, VirtualMachine.Event.RestoringRequested);
+            updateVolumeState(vm, Volume.Event.RestoreRequested);
+            final BackupProvider backupProvider = 
getBackupProvider(offering.getProvider());
+            if (!backupProvider.restoreVMFromBackup(vm, backup)) {
+                throw new CloudRuntimeException(String.format("Error restoring 
%s from backup [%s].", vm, backupDetailsInMessage));
+            }
+        } catch (Exception e) {

Review Comment:
   Your explanation is perfect, @SadiJr better than any I have ever heard about 
a pokemon catch. I would like to see it in a comment in the code, so people 
that don't see this PR know the reason as well ;)



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