Skip to content

Commit

Permalink
Veeam: fix incompatible types: String cannot be converted to Date
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhouapache committed Feb 5, 2024
1 parent b8904f7 commit 54225ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -897,7 +896,7 @@ public List<Backup.RestorePoint> processHttpResponseForVmRestorePoints(InputStre
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));
Expand All @@ -909,8 +908,8 @@ public List<Backup.RestorePoint> processHttpResponseForVmRestorePoints(InputStre
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

Expand All @@ -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);
Expand Down Expand Up @@ -463,7 +465,7 @@ public void testListVmRestorePointsViaVeeamAPI() {

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());
}

Expand Down

0 comments on commit 54225ec

Please sign in to comment.