SadiJr commented on code in PR #7238:
URL: https://github.com/apache/cloudstack/pull/7238#discussion_r1112979436
##########
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) {
+ LOG.error(String.format("Failed to restore backup [%s] due to:
[%s].", backupDetailsInMessage, e.getMessage()), e);
+ updateVolumeState(vm, Volume.Event.RestoreFailed);
+ updateVmState(vm, VirtualMachine.Event.RestoringFailed);
+ throw new CloudRuntimeException(String.format("Error restoring VM
from backup [%s].", backupDetailsInMessage));
}
Review Comment:
Done, thanks for the suggestion.
--
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]