Skip to content

Commit

Permalink
IAC-778 Address code review comments and fix issue with backed up pac…
Browse files Browse the repository at this point in the history
…kage path

Signed-off-by: Maria Topchieva <[email protected]>
  • Loading branch information
mtopchieva committed Sep 1, 2023
1 parent 7ee9aa3 commit 60412c2
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public final List<Package> importAllPackages(final List<Package> pkg, final bool
public final List<Package> importAllPackages(final List<Package> vroPackages, final boolean dryrun, final boolean mergePackages, final boolean vroEnableBackup) {
this.validateFilesystem(vroPackages);

System.out.println("Start executing import all packages...");
logger.info("Start executing import all packages...");

this.validateFilesystem(vroPackages);

List<Package> packagesToImport = vroPackages;
Expand All @@ -163,7 +164,8 @@ public final List<Package> importAllPackages(final List<Package> vroPackages, fi

if (vroEnableBackup && packagesToImport.size() > 0) {
//TO change the packages to backup to ALL the packages currently present in vRO -> in this if statements replace packagesToImport with destinationEndpointPackages
System.out.println("Number of packages to backup: " + packagesToImport.size());
logger.info("Number of packages to backup: ", packagesToImport.size());

boolean exportConfigAttributeValues = true;
boolean exportConfigSecureStringValues = true;

Expand All @@ -175,10 +177,9 @@ public final List<Package> importAllPackages(final List<Package> vroPackages, fi

packagesToImport.forEach(pkg -> {
String originalPkgFilePath = pkg.getFilesystemPath();
String backupFilePath = this.createBackupFilePath(pkg, currentDateTimeString, backupFilesDirectory);

try {
System.out.println("Package for back up: " + pkg.getFQName());
logger.info("Package for back up: ", pkg.getFQName());

List<Package> samePackagesInDest = new ArrayList<Package>();
for (int i = 0; i < destinationEndpointPackages.size(); i++) {
Expand All @@ -191,30 +192,32 @@ public final List<Package> importAllPackages(final List<Package> vroPackages, fi

if (samePackagesInDest.size() > 0) {
Package highestVersionPac = this.getHighestVersion(samePackagesInDest);
String backupFilePath = this.createBackupFilePath(highestVersionPac, currentDateTimeString, backupFilesDirectory);
highestVersionPac.setFilesystemPath(backupFilePath);
restClient.exportPackage(highestVersionPac, dryrun, exportConfigAttributeValues, exportConfigSecureStringValues);

} else {
System.out.println("Package with name: " + pkg.getName() + " does not exist in vRO and backup is skipped.");

logger.info("The package does not exist in vRO and backup is skipped: ", pkg.getName());
}
} catch (Exception ex) {
String exceptionMessage = ex.getMessage();
System.out.println("ExceptionMessage: " + exceptionMessage);
System.out.println("Package Name: " + pkg.getName());
logger.info("ExceptionMessage: ", exceptionMessage);
logger.info("Package Name: ", pkg.getName());

if (!exceptionMessage.contains("404 Not Found")
||
!exceptionMessage.contains(pkg.getName())) { //Unexpected exception
throw ex;
} else { //The package to be imported has been deleted from the server
System.out.println(ex.getMessage());
logger.info("ExceptionMessage: ", ex.getMessage());
}
}

System.out.println("Restoring original file path...");
logger.info("Restoring original file path... ");

pkg.setFilesystemPath(originalPkgFilePath);
System.out.println("File path after restoration: " + pkg.getFilesystemPath());
logger.info("File path after restoration: ", pkg.getFilesystemPath());

});
}

Expand Down Expand Up @@ -403,12 +406,11 @@ private Package getHighestVersion(List<Package> packages) {

Package highestVersionPac = packages.get(0);
if (packages.size() == 1) {
System.out.println("Highest version package to backup: " + highestVersionPac.getFQName());
logger.info("Highest version package to backup: ", highestVersionPac.getFQName());
return highestVersionPac;
}

for (int i = 0; i < packages.size() - 1; i++) {

int diff = highestVersionPac.compareTo(packages.get(i + 1));
if (diff > 0) {
highestVersionPac = packages.get(i);
Expand All @@ -417,7 +419,7 @@ private Package getHighestVersion(List<Package> packages) {
}
}

System.out.println("Highest version package to backup: " + highestVersionPac.getFQName());
logger.info("Highest version package to backup: ", highestVersionPac.getFQName());
return highestVersionPac;
}
}

0 comments on commit 60412c2

Please sign in to comment.