Skip to content

Commit

Permalink
Edit VroPackageStore and address code review
Browse files Browse the repository at this point in the history
Signed-off-by: Maria Topchieva <[email protected]>
  • Loading branch information
mtopchieva committed Sep 1, 2023
1 parent e9a0149 commit 506aa52
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Fixes
* [artifact-manager] 148 / vra-ng:pull command failure when import/export tags contains underscore
* [maven-plugins] 146 / Pull operations fail on Windows with release 2.34.0
* [artifact-manager] 778 / Backup only works with current package version, otherwise throws exception 404 not found

## v2.34.0 - 05 Jul 2023

Expand Down
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,28 +177,47 @@ 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 {
pkg.setFilesystemPath(backupFilePath);
restClient.exportPackage(pkg, dryrun, exportConfigAttributeValues, exportConfigSecureStringValues);
logger.info("Package for back up: ", pkg.getFQName());

List<Package> samePackagesInDest = new ArrayList<Package>();
for (int i = 0; i < destinationEndpointPackages.size(); i++) {
String currentVroPackageName = destinationEndpointPackages.get(i).getName();

if (currentVroPackageName.equals(pkg.getName())) {
samePackagesInDest.add(destinationEndpointPackages.get(i));
}
}

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 {
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 @@ -375,4 +396,30 @@ private String createBackupFilePath(final Package pkg, final String currentDateT

return newFullPath;
}

/**
* Compares packages by their version and return the highest version package.
* @param packages the collection of packages differring by version
* @return the package with highest version
*/
private Package getHighestVersion(List<Package> packages) {

Package highestVersionPac = packages.get(0);
if (packages.size() == 1) {
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);
} else {
highestVersionPac = packages.get(i + 1);
}
}

logger.info("Highest version package to backup: ", highestVersionPac.getFQName());
return highestVersionPac;
}
}
13 changes: 13 additions & 0 deletions docs/versions/latest/Release.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@ with null object error.

When no imports are defined in typescript SAGA workflow file format, the compiled vRO workflow runs successfully.

### Fixed backup of vRO packages so that the highest available version is backed up
#### Previous Behavior

Back up of vRO packages (using the flag in the environment.properties file: vro_enable_backup=true)
would only work if the currently imported packages (which are to back up), had the same version as the one in vRO.
Otherwise, the import would throw an '404 Not found' exception and break the import process,
due to not finding the same package and version to back up.

#### New Behavior
Back up of vRO packages now works by:
- backing up the highest available version in vRO of the imported package,
- logging a message that back up is skipped for the package, if no versions of it are found in vRO, continuing with backup of next packages, and the import process.

## Upgrade procedure

0 comments on commit 506aa52

Please sign in to comment.