Skip to content

Commit 54225ec

Browse files
committed
Veeam: fix incompatible types: String cannot be converted to Date
1 parent b8904f7 commit 54225ec

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ public class VeeamClient {
107107
private static final String RESTORE_POINT_REFERENCE = "RestorePointReference";
108108
private static final String BACKUP_FILE_REFERENCE = "BackupFileReference";
109109
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
110-
private static final SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
111110

112111

113112
private String veeamServerIp;
@@ -897,7 +896,7 @@ public List<Backup.RestorePoint> processHttpResponseForVmRestorePoints(InputStre
897896
continue;
898897
}
899898
String vmRestorePointId = vmRestorePoint.getUid().substring(vmRestorePoint.getUid().lastIndexOf(':') + 1);
900-
String created = formatDate(vmRestorePoint.getCreationTimeUtc());
899+
Date created = formatDate(vmRestorePoint.getCreationTimeUtc());
901900
String type = vmRestorePoint.getPointType();
902901
LOG.debug(String.format("Adding restore point %s, %s, %s", vmRestorePointId, created, type));
903902
vmRestorePointList.add(new Backup.RestorePoint(vmRestorePointId, created, type));
@@ -909,8 +908,8 @@ public List<Backup.RestorePoint> processHttpResponseForVmRestorePoints(InputStre
909908
return vmRestorePointList;
910909
}
911910

912-
private String formatDate(String date) throws ParseException {
913-
return newDateFormat.format(dateFormat.parse(StringUtils.substring(date, 0, 19)));
911+
private Date formatDate(String date) throws ParseException {
912+
return dateFormat.parse(StringUtils.substring(date, 0, 19));
914913
}
915914

916915
public Pair<Boolean, String> restoreVMToDifferentLocation(String restorePointId, String hostIp, String dataStoreUuid) {

plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.ByteArrayInputStream;
3131
import java.io.IOException;
3232
import java.io.InputStream;
33+
import java.text.SimpleDateFormat;
3334
import java.util.List;
3435
import java.util.Map;
3536

@@ -55,6 +56,7 @@ public class VeeamClientTest {
5556
private String adminPassword = "password";
5657
private VeeamClient client;
5758
private VeeamClient mockClient;
59+
private static final SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
5860

5961
@Rule
6062
public WireMockRule wireMockRule = new WireMockRule(9399);
@@ -463,7 +465,7 @@ public void testListVmRestorePointsViaVeeamAPI() {
463465

464466
Assert.assertEquals(1, vmRestorePointList.size());
465467
Assert.assertEquals("f6d504cf-eafe-4cd2-8dfc-e9cfe2f1e977", vmRestorePointList.get(0).getId());
466-
Assert.assertEquals("2023-11-03 16:26:12", vmRestorePointList.get(0).getCreated());
468+
Assert.assertEquals("2023-11-03 16:26:12", newDateFormat.format(vmRestorePointList.get(0).getCreated()));
467469
Assert.assertEquals("Full", vmRestorePointList.get(0).getType());
468470
}
469471

0 commit comments

Comments
 (0)