From e81a8d915e5bea858bbe2806d621d250ec85f505 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Wed, 1 Oct 2025 09:31:27 -0400 Subject: [PATCH 1/6] Veeam: Use restore timeout as a time interval as opposed to a counter --- .../java/org/apache/cloudstack/backup/veeam/VeeamClient.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java index e2df854f16d1..dfaca90d3056 100644 --- a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java @@ -366,7 +366,9 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException * that is used to wait for the restore to complete before throwing a {@link CloudRuntimeException}. */ protected void checkIfRestoreSessionFinished(String type, String path) throws IOException { - for (int j = 0; j < restoreTimeout; j++) { + long startTime = System.currentTimeMillis(); + long timeoutMs = restoreTimeout * 1000L; + if (System.currentTimeMillis() - startTime < timeoutMs) { HttpResponse relatedResponse = get(path); RestoreSession session = parseRestoreSessionResponse(relatedResponse); if (session.getResult().equals("Success")) { From cd63800d157b24b7298f8718758a39683033d158 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Wed, 1 Oct 2025 10:05:27 -0400 Subject: [PATCH 2/6] fix log --- .../java/org/apache/cloudstack/backup/veeam/VeeamClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java index dfaca90d3056..82e74a9af8d7 100644 --- a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java @@ -382,7 +382,8 @@ protected void checkIfRestoreSessionFinished(String type, String path) throws IO getRestoreVmErrorDescription(StringUtils.substringAfterLast(sessionUid, ":")))); throw new CloudRuntimeException(String.format("Restore job [%s] failed.", sessionUid)); } - logger.debug(String.format("Waiting %s seconds, out of a total of %s seconds, for the restore backup process to finish.", j, restoreTimeout)); + logger.debug(String.format("Waiting %d seconds, out of a total of %d seconds, for the restore backup process to finish.", + (System.currentTimeMillis() - startTime) / 1000, restoreTimeout)); try { Thread.sleep(1000); From bb1443d270d38cf8fa68e5e80b8b6eb659f0fc04 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 6 Oct 2025 09:40:55 -0400 Subject: [PATCH 3/6] fix unit test --- .../org/apache/cloudstack/backup/veeam/VeeamClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java b/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java index 3485f402417e..234c15e402c0 100644 --- a/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java +++ b/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java @@ -157,7 +157,7 @@ public void getRepositoryNameFromJobTestSuccess() throws Exception { @Test public void checkIfRestoreSessionFinishedTestTimeoutException() throws IOException { try { - ReflectionTestUtils.setField(mockClient, "restoreTimeout", 10); + ReflectionTestUtils.setField(mockClient, "restoreTimeout", 2); RestoreSession restoreSession = Mockito.mock(RestoreSession.class); HttpResponse httpResponse = Mockito.mock(HttpResponse.class); Mockito.when(mockClient.get(Mockito.anyString())).thenReturn(httpResponse); @@ -169,7 +169,7 @@ public void checkIfRestoreSessionFinishedTestTimeoutException() throws IOExcepti } catch (Exception e) { Assert.assertEquals("Related job type: RestoreTest was not successful", e.getMessage()); } - Mockito.verify(mockClient, times(10)).get(Mockito.anyString()); + Mockito.verify(mockClient, Mockito.atLeastOnce()).get(Mockito.anyString()); } @Test From ca5bfea397bccc712d3579b2f0fe1d429ac53510 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 6 Oct 2025 10:09:27 -0400 Subject: [PATCH 4/6] remove unused imports --- .../java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java b/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java index 234c15e402c0..9a3dfc64deec 100644 --- a/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java +++ b/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java @@ -25,7 +25,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static org.junit.Assert.fail; -import static org.mockito.Mockito.times; import java.io.ByteArrayInputStream; import java.io.IOException; From df843081cde14ab31e001565ccdd7cbb9771b803 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 6 Oct 2025 10:47:07 -0400 Subject: [PATCH 5/6] fix comment --- .../java/org/apache/cloudstack/backup/veeam/VeeamClient.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java index 82e74a9af8d7..8d4e67f53f82 100644 --- a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java @@ -90,6 +90,7 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.util.Supplier; public class VeeamClient { protected Logger logger = LogManager.getLogger(getClass()); @@ -382,8 +383,8 @@ protected void checkIfRestoreSessionFinished(String type, String path) throws IO getRestoreVmErrorDescription(StringUtils.substringAfterLast(sessionUid, ":")))); throw new CloudRuntimeException(String.format("Restore job [%s] failed.", sessionUid)); } - logger.debug(String.format("Waiting %d seconds, out of a total of %d seconds, for the restore backup process to finish.", - (System.currentTimeMillis() - startTime) / 1000, restoreTimeout)); + logger.debug("Waiting {} seconds, out of a total of {} seconds, for the restore backup process to finish.", + (System.currentTimeMillis() - startTime) / 1000, restoreTimeout); try { Thread.sleep(1000); From 11cab28847bb06742272be2dbb5b9b6ab0371119 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 6 Oct 2025 13:36:56 -0400 Subject: [PATCH 6/6] unused import --- .../java/org/apache/cloudstack/backup/veeam/VeeamClient.java | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java index 8d4e67f53f82..3685675288f6 100644 --- a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java @@ -90,7 +90,6 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.util.Supplier; public class VeeamClient { protected Logger logger = LogManager.getLogger(getClass());