Skip to content

Commit

Permalink
VAL-446 Improve error handling & reporting around file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pgwilliams committed Dec 12, 2024
1 parent 0208b12 commit c570d34
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private List<InvalidContent> validateFiles(ValidationRunConfig validationConfig,
!uuidAssertionMap.get(UUID.fromString(item.getRuleId())).getGroups().contains("int-authoring"))
|| ((uuidAssertionMap.get(UUID.fromString(item.getRuleId())).getGroups().contains("common-authoring") ||
uuidAssertionMap.get(UUID.fromString(item.getRuleId())).getGroups().contains("int-authoring"))
&& modules.contains(item.getComponent().getModuleId()))).collect(Collectors.toList());
&& modules.contains(item.getComponent().getModuleId()))).toList();
}
}

Expand Down Expand Up @@ -342,6 +342,7 @@ private List<InvalidContent> checkAgainstWhiteListedItems(List<InvalidContent> i
}

private void extractFiles(ValidationRunConfig validationConfig, Set<String> extractedRF2FilesDirectories, Set<String> previousReleaseDirectories) throws RVFExecutionException, ReleaseImportException, IOException {
verifyLocalFile("extracting prospective file", validationConfig.getLocalProspectiveFile());
try (InputStream testedReleaseFileStream = new FileInputStream(validationConfig.getLocalProspectiveFile())) {
// If the validation is Delta validation, previous snapshot file must be loaded to snapshot files list.
if (validationConfig.isRf2DeltaOnly()) {
Expand All @@ -364,18 +365,26 @@ private void extractFiles(ValidationRunConfig validationConfig, Set<String> extr
if (StringUtils.isBlank(validationConfig.getExtensionDependency()) || !validationConfig.getExtensionDependency().endsWith(EXT_ZIP)) {
throw new RVFExecutionException("Drools validation cannot execute when Extension Dependency is empty or not a .zip file: " + validationConfig.getExtensionDependency());
}
verifyLocalFile("extracting dependency file", validationConfig.getLocalDependencyReleaseFile());
try (InputStream dependencyStream = new FileInputStream(validationConfig.getLocalDependencyReleaseFile())) {
extractedRF2FilesDirectories.add(new ReleaseImporter().unzipRelease(dependencyStream, ReleaseImporter.ImportType.SNAPSHOT).getAbsolutePath());
}
}

if (StringUtils.isNotBlank(validationConfig.getPreviousRelease()) && validationConfig.getPreviousRelease().endsWith(EXT_ZIP)) {
verifyLocalFile("extracting previous release file", validationConfig.getLocalPreviousReleaseFile());
try (InputStream previousReleaseStream = new FileInputStream(validationConfig.getLocalPreviousReleaseFile())) {
previousReleaseDirectories.add(new ReleaseImporter().unzipRelease(previousReleaseStream, ReleaseImporter.ImportType.SNAPSHOT).getAbsolutePath());
}
}
}

private void verifyLocalFile(String step, File file) throws RVFExecutionException {
if (file == null || !file.exists() || !file.canRead()) {
throw new RVFExecutionException("Drools validation failure while " + step + " as it is null, not found, or cannot be read. File name: '" + file + "'");
}
}

private UUID parseUUID(String uuid) {
try{
return UUID.fromString(uuid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.ihtsdo.rvf.core.service;

import org.apache.commons.lang3.exception.ExceptionUtils;

import org.ihtsdo.otf.rest.client.RestClientException;
import org.ihtsdo.otf.rest.exception.BusinessServiceException;
import org.ihtsdo.otf.utils.ExceptionUtils;
import org.ihtsdo.rvf.core.data.model.*;
import org.ihtsdo.rvf.core.service.config.MysqlExecutionConfig;
import org.ihtsdo.rvf.core.service.config.ValidationRunConfig;
Expand Down Expand Up @@ -76,25 +77,30 @@ public ValidationStatusReport runRF2MysqlValidations(ValidationRunConfig validat
}

String reportStorage = validationConfig.getStorageLocation();
String lastItemLoadAttempted = "Item Unknown";
try {
// prepare release data for testing
lastItemLoadAttempted = "Previous Release - " + executionConfig.getPreviousVersion();
releaseVersionLoader.loadPreviousVersion(executionConfig);
if (releaseVersionLoader.isUnknownVersion(executionConfig.getPreviousVersion())) {
statusReport.addFailureMessage("Failed to load previous release " + executionConfig.getPreviousVersion());
}

// load dependency release
releaseVersionLoader.loadDependencyVersion(executionConfig);
lastItemLoadAttempted = "Dependency Release - " + executionConfig.getExtensionDependencyVersion();
if (releaseVersionLoader.isUnknownVersion(executionConfig.getExtensionDependencyVersion())) {
statusReport.addFailureMessage("Failed to load dependency release " + executionConfig.getExtensionDependencyVersion());
}
// load prospective version
lastItemLoadAttempted = "Prospective Release - " + executionConfig.getProspectiveVersion();
releaseVersionLoader.loadProspectiveVersion(statusReport, executionConfig, validationConfig);
} catch (Exception e) {
String errorMsg = String.format("Failed to load data into MySql due to %s", ExceptionUtils.getRootCauseMessage(e));
LOGGER.error(errorMsg, e);
statusReport.addFailureMessage(errorMsg);
statusReport.getReportSummary().put(TestType.SQL.name(), errorMsg);
String errorMsg = String.format("Failed to load data (%s) into MySql", lastItemLoadAttempted);
String errorMsgWithCause = ExceptionUtils.getExceptionCause(errorMsg, e);
LOGGER.error(errorMsgWithCause, e);
statusReport.addFailureMessage(errorMsgWithCause);
statusReport.getReportSummary().put(TestType.SQL.name(), errorMsgWithCause);
return statusReport;
}
if (executionConfig.isExtensionValidation()) {
Expand Down Expand Up @@ -138,10 +144,10 @@ private void runExtensionReleaseValidation(ValidationStatusReport statusReport,
releaseVersionLoader.combineCurrentExtensionWithDependencySnapshot(executionConfig, validationConfig);
this.legacyProspectiveVersions.add(executionConfig.getProspectiveVersion());
} catch (BusinessServiceException e) {
String msg = String.format("Failed to prepare data for extension testing due to error %s", ExceptionUtils.getRootCauseMessage(e));
statusReport.addFailureMessage(msg);
LOGGER.error(msg, e);
statusReport.getReportSummary().put(TestType.SQL.name(), msg);
String errMsg = ExceptionUtils.getExceptionCause("Failed to prepare data for extension testing", e);
statusReport.addFailureMessage(errMsg);
LOGGER.error(errMsg, e);
statusReport.getReportSummary().put(TestType.SQL.name(), errMsg);
}
}
testItems.addAll(runAssertionTests(executionConfig, noneReleaseTypeAssertions, reportStorage, true));
Expand Down Expand Up @@ -289,7 +295,7 @@ private void constructTestReport(ValidationStatusReport statusReport, MysqlExecu
report.addFailedAssertions(Collections.emptyList());
report.addWarningAssertions(Collections.emptyList());
report.addPassedAssertions(Collections.emptyList());
statusReport.addFailureMessage(String.format("Failed to extract test results caused by %s", ExceptionUtils.getRootCauseMessage(exception)));
statusReport.addFailureMessage(ExceptionUtils.getExceptionCause("Failed to extract test results",exception));
}

final long timeEnd = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void loadPreviousVersion(MysqlExecutionConfig executionConfig) throws Bus
String rvfDbSchema = loadRelease(executionConfig.getPreviousVersion());
executionConfig.setPreviousVersion(rvfDbSchema);
} else {
throw new BusinessServiceException("Previous release specified is not found "
throw new BusinessServiceException("Previous release specified is not found: "
+ executionConfig.getPreviousVersion());
}
}
Expand Down

0 comments on commit c570d34

Please sign in to comment.