weizhouapache commented on code in PR #7224:
URL: https://github.com/apache/cloudstack/pull/7224#discussion_r1425058325


##########
plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java:
##########
@@ -319,13 +319,26 @@ private boolean checkTaskStatus(final HttpResponse 
response) throws IOException
         return false;
     }
 
+    /**
+     * Checks the status of the restore session. Checked states are "Success" 
and "Failure".<br/>
+     * There is also a timeout defined in the global configuration, 
backup.plugin.veeam.restore.timeout,<br/>
+     * that is used to wait for the restore to complete before throwing a 
{@link CloudRuntimeException}.
+     */
     protected boolean checkIfRestoreSessionFinished(String type, String path) 
throws IOException {
-        for (int j = 0; j < this.restoreTimeout; j++) {
+        for (int j = 0; j < restoreTimeout; j++) {
             HttpResponse relatedResponse = get(path);
             RestoreSession session = 
parseRestoreSessionResponse(relatedResponse);
             if (session.getResult().equals("Success")) {
                 return true;
             }
+            if (session.getResult().equalsIgnoreCase("Failed")) {
+                String sessionUid = session.getUid();
+                LOG.error(String.format("Failed to restore backup [%s] of VM 
[%s] due to [%s].",
+                        sessionUid, session.getVmDisplayName(),
+                        
getRestoreVmErrorDescription(StringUtils.substringAfterLast(sessionUid, ":"))));
+                throw new CloudRuntimeException(String.format("Restore job 
[%s] failed.", sessionUid));
+            }
+            LOG.debug(String.format("Waiting %s seconds, out of a total of %s 
seconds, for the backup process to finish.", j, restoreTimeout));

Review Comment:
   the log mentions "backup process", is it correct  ?



##########
plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java:
##########
@@ -723,4 +736,27 @@ public Pair<Boolean, String> 
restoreVMToDifferentLocation(String restorePointId,
         }
         return new Pair<>(result.first(), restoreLocation);
     }
+
+    /**
+     * Tries to retrieve the error's description of the Veeam restore task 
that resulted in an error.
+     * @param uid Session uid in Veeam of the restore process;
+     * @return the description found in Veeam about the cause of error in the 
restore process.
+     */
+    protected String getRestoreVmErrorDescription(String uid) {
+        LOG.debug(String.format("Trying to find the cause of error in the 
restore process [%s].", uid));
+        List<String> cmds = Arrays.asList(

Review Comment:
   can this be replaced by REST api ? 
   
https://helpcenter.veeam.com/docs/backup/em_rest/restoresessions_id.html?ver=120
   powershell command is slow ..



##########
plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java:
##########
@@ -303,7 +303,7 @@ private boolean checkTaskStatus(final HttpResponse 
response) throws IOException
                         String type = pair.second();
                         String path = url.replace(apiURI.toString(), "");
                         if (type.equals("RestoreSession")) {
-                            return checkIfRestoreSessionFinished(type, path);
+                            checkIfRestoreSessionFinished(type, path);

Review Comment:
   if so, we could change the return type to "void" instead of "boolean"



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