This is an automated email from the ASF dual-hosted git repository.

weizhou pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit 54225ecd150fa1145782792dd75624ea709994a6
Author: Wei Zhou <[email protected]>
AuthorDate: Mon Feb 5 10:50:16 2024 +0100

    Veeam: fix incompatible types: String cannot be converted to Date
---
 .../main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java  | 7 +++----
 .../java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java   | 4 +++-
 2 files changed, 6 insertions(+), 5 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 b24feb6162f..701c45f1a9d 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
@@ -107,7 +107,6 @@ public class VeeamClient {
     private static final String RESTORE_POINT_REFERENCE = 
"RestorePointReference";
     private static final String BACKUP_FILE_REFERENCE = "BackupFileReference";
     private static final SimpleDateFormat dateFormat = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-    private static final SimpleDateFormat newDateFormat = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
 
     private String veeamServerIp;
@@ -897,7 +896,7 @@ public class VeeamClient {
                     continue;
                 }
                 String vmRestorePointId = 
vmRestorePoint.getUid().substring(vmRestorePoint.getUid().lastIndexOf(':') + 1);
-                String created = 
formatDate(vmRestorePoint.getCreationTimeUtc());
+                Date created = formatDate(vmRestorePoint.getCreationTimeUtc());
                 String type = vmRestorePoint.getPointType();
                 LOG.debug(String.format("Adding restore point %s, %s, %s", 
vmRestorePointId, created, type));
                 vmRestorePointList.add(new 
Backup.RestorePoint(vmRestorePointId, created, type));
@@ -909,8 +908,8 @@ public class VeeamClient {
         return vmRestorePointList;
     }
 
-    private String formatDate(String date) throws ParseException {
-        return 
newDateFormat.format(dateFormat.parse(StringUtils.substring(date, 0, 19)));
+    private Date formatDate(String date) throws ParseException {
+        return dateFormat.parse(StringUtils.substring(date, 0, 19));
     }
 
     public Pair<Boolean, String> restoreVMToDifferentLocation(String 
restorePointId, String hostIp, String dataStoreUuid) {
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 48d1f886b48..06804d68da2 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
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.times;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Map;
 
@@ -55,6 +56,7 @@ public class VeeamClientTest {
     private String adminPassword = "password";
     private VeeamClient client;
     private VeeamClient mockClient;
+    private static final SimpleDateFormat newDateFormat = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
     @Rule
     public WireMockRule wireMockRule = new WireMockRule(9399);
@@ -463,7 +465,7 @@ public class VeeamClientTest {
 
         Assert.assertEquals(1, vmRestorePointList.size());
         Assert.assertEquals("f6d504cf-eafe-4cd2-8dfc-e9cfe2f1e977", 
vmRestorePointList.get(0).getId());
-        Assert.assertEquals("2023-11-03 16:26:12", 
vmRestorePointList.get(0).getCreated());
+        Assert.assertEquals("2023-11-03 16:26:12", 
newDateFormat.format(vmRestorePointList.get(0).getCreated()));
         Assert.assertEquals("Full", vmRestorePointList.get(0).getType());
     }
 

Reply via email to