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


##########
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 descripton of the Veeam restore task that 
errored.
+     * @param uid Session uid in Veeam of restore process;
+     * @return the description found in Veeam about the cause of error in 
restore process.
+     */
+    protected String getRestoreVmErrorDescription(String uid) {
+        LOG.debug(String.format("Trying to find cause of error in restore 
process [%s].", uid));

Review Comment:
   ```suggestion
           LOG.debug(String.format("Trying to find the cause of error in the 
restore process [%s].", uid));
   ```



##########
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 descripton of the Veeam restore task that 
errored.
+     * @param uid Session uid in Veeam of restore process;
+     * @return the description found in Veeam about the cause of error in 
restore process.
+     */
+    protected String getRestoreVmErrorDescription(String uid) {
+        LOG.debug(String.format("Trying to find cause of error in restore 
process [%s].", uid));
+        List<String> cmds = Arrays.asList(
+                String.format("$restoreUid = '%s'", uid),
+                "$restore = Get-VBRRestoreSession -Id $restoreUid",
+                "if ($restore) {",
+                    "Write-Output $restore.Description",
+                "} else {",
+                    "Write-Output 'Cannot find restore session with provided 
uid $restoreUid'",
+                "}"
+        );
+        Pair<Boolean, String> result = executePowerShellCommands(cmds);
+        if (result != null && result.first()) {
+            return result.second();
+        }
+        return String.format("Failed to get description of failed restore 
session [%s]. Please contact an administrator.", uid);

Review Comment:
   ```suggestion
           return String.format("Failed to get the description of the failed 
restore session [%s]. Please contact an administrator.", uid);
   ```



##########
plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java:
##########
@@ -162,4 +164,40 @@ public void 
checkIfRestoreSessionFinishedTestTimeoutException() throws IOExcepti
         }
         Mockito.verify(mockClient, times(10)).get(Mockito.anyString());
     }
+
+    @Test
+    public void getRestoreVmErrorDescriptionTestFindErrorDescription() {
+        Pair<Boolean, String> response = new Pair<>(true, "Example of error 
description found in Veeam.");
+        
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
+        
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response);
+        String result = mock.getRestoreVmErrorDescription("uuid");
+        Assert.assertEquals("Example of error description found in Veeam.", 
result);
+    }
+
+    @Test
+    public void getRestoreVmErrorDescriptionTestNotFindErrorDescription() {
+        Pair<Boolean, String> response = new Pair<>(true, "Cannot find restore 
session with provided uid uuid");
+        
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
+        
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response);
+        String result = mock.getRestoreVmErrorDescription("uuid");
+        Assert.assertEquals("Cannot find restore session with provided uid 
uuid", result);
+    }
+
+    @Test
+    public void getRestoreVmErrorDescriptionTestWhenPowerShellOutputIsNull() {
+        
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
+        
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(null);
+        String result = mock.getRestoreVmErrorDescription("uuid");
+        Assert.assertEquals("Failed to get description of failed restore 
session [uuid]. Please contact an administrator.", result);

Review Comment:
   ```suggestion
           Assert.assertEquals("Failed to get the description of the failed 
restore session [%s]. Please contact an administrator.", result);
   ```



##########
plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java:
##########
@@ -162,4 +164,40 @@ public void 
checkIfRestoreSessionFinishedTestTimeoutException() throws IOExcepti
         }
         Mockito.verify(mockClient, times(10)).get(Mockito.anyString());
     }
+
+    @Test
+    public void getRestoreVmErrorDescriptionTestFindErrorDescription() {
+        Pair<Boolean, String> response = new Pair<>(true, "Example of error 
description found in Veeam.");
+        
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
+        
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response);
+        String result = mock.getRestoreVmErrorDescription("uuid");
+        Assert.assertEquals("Example of error description found in Veeam.", 
result);
+    }
+
+    @Test
+    public void getRestoreVmErrorDescriptionTestNotFindErrorDescription() {
+        Pair<Boolean, String> response = new Pair<>(true, "Cannot find restore 
session with provided uid uuid");
+        
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
+        
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response);
+        String result = mock.getRestoreVmErrorDescription("uuid");
+        Assert.assertEquals("Cannot find restore session with provided uid 
uuid", result);
+    }
+
+    @Test
+    public void getRestoreVmErrorDescriptionTestWhenPowerShellOutputIsNull() {
+        
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
+        
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(null);
+        String result = mock.getRestoreVmErrorDescription("uuid");
+        Assert.assertEquals("Failed to get description of failed restore 
session [uuid]. Please contact an administrator.", result);
+    }
+
+    @Test
+    public void getRestoreVmErrorDescriptionTestWhenPowerShellOutputIsFalse() {
+        Pair<Boolean, String> response = new Pair<>(false, null);
+        
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
+        
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response);
+        String result = mock.getRestoreVmErrorDescription("uuid");
+        Assert.assertEquals("Failed to get description of failed restore 
session [uuid]. Please contact an administrator.", result);

Review Comment:
   ```suggestion
           Assert.assertEquals("Failed to get the description of the failed 
restore session [%s]. Please contact an administrator.", result);
   ```



##########
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 descripton of the Veeam restore task that 
errored.
+     * @param uid Session uid in Veeam of restore process;
+     * @return the description found in Veeam about the cause of error in 
restore process.

Review Comment:
   ```suggestion
        * 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.
   ```



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