use of org.apache.airavata.orchestrator.core.validator.JobMetadataValidator in project airavata by apache.
the class SimpleOrchestratorImpl method validateExperiment.
public ValidationResults validateExperiment(ExperimentModel experiment) throws OrchestratorException, LaunchValidationException {
org.apache.airavata.model.error.ValidationResults validationResults = new org.apache.airavata.model.error.ValidationResults();
// initially making it to success, if atleast one failed them simply mark it failed.
validationResults.setValidationState(true);
String errorMsg = "Validation Errors : ";
if (this.orchestratorConfiguration.isEnableValidation()) {
List<String> validatorClasses = this.orchestratorContext.getOrchestratorConfiguration().getValidatorClasses();
for (String validator : validatorClasses) {
try {
Class<? extends JobMetadataValidator> vClass = Class.forName(validator.trim()).asSubclass(JobMetadataValidator.class);
JobMetadataValidator jobMetadataValidator = vClass.newInstance();
validationResults = jobMetadataValidator.validate(experiment, null);
if (validationResults.isValidationState()) {
logger.info("Validation of " + validator + " is SUCCESSFUL");
} else {
List<ValidatorResult> validationResultList = validationResults.getValidationResultList();
for (ValidatorResult result : validationResultList) {
if (!result.isResult()) {
String validationError = result.getErrorDetails();
if (validationError != null) {
errorMsg += validationError + " ";
}
}
}
logger.error("Validation of " + validator + " for experiment Id " + experiment.getExperimentId() + " is FAILED:[error]. " + errorMsg);
validationResults.setValidationState(false);
try {
ErrorModel details = new ErrorModel();
details.setActualErrorMessage(errorMsg);
details.setCreationTime(Calendar.getInstance().getTimeInMillis());
orchestratorContext.getRegistry().getExperimentCatalog().add(ExpCatChildDataType.EXPERIMENT_ERROR, details, experiment.getExperimentId());
} catch (RegistryException e) {
logger.error("Error while saving error details to registry", e);
}
break;
}
} catch (ClassNotFoundException e) {
logger.error("Error loading the validation class: ", validator, e);
validationResults.setValidationState(false);
} catch (InstantiationException e) {
logger.error("Error loading the validation class: ", validator, e);
validationResults.setValidationState(false);
} catch (IllegalAccessException e) {
logger.error("Error loading the validation class: ", validator, e);
validationResults.setValidationState(false);
}
}
}
if (validationResults.isValidationState()) {
return validationResults;
} else {
// atleast one validation has failed, so we throw an exception
LaunchValidationException launchValidationException = new LaunchValidationException();
launchValidationException.setValidationResult(validationResults);
launchValidationException.setErrorMessage("Validation failed refer the validationResults list for " + "detail error. Validation errors : " + errorMsg);
throw launchValidationException;
}
}
use of org.apache.airavata.orchestrator.core.validator.JobMetadataValidator in project airavata by apache.
the class SimpleOrchestratorImpl method validateProcess.
public ValidationResults validateProcess(ExperimentModel experiment, ProcessModel processModel) throws OrchestratorException, LaunchValidationException {
org.apache.airavata.model.error.ValidationResults validationResults = new org.apache.airavata.model.error.ValidationResults();
// initially making it to success, if atleast one failed them simply mark it failed.
validationResults.setValidationState(true);
String errorMsg = "Validation Errors : ";
if (this.orchestratorConfiguration.isEnableValidation()) {
List<String> validatorClzzez = this.orchestratorContext.getOrchestratorConfiguration().getValidatorClasses();
for (String validator : validatorClzzez) {
try {
Class<? extends JobMetadataValidator> vClass = Class.forName(validator.trim()).asSubclass(JobMetadataValidator.class);
JobMetadataValidator jobMetadataValidator = vClass.newInstance();
validationResults = jobMetadataValidator.validate(experiment, processModel);
if (validationResults.isValidationState()) {
logger.info("Validation of " + validator + " is SUCCESSFUL");
} else {
List<ValidatorResult> validationResultList = validationResults.getValidationResultList();
for (ValidatorResult result : validationResultList) {
if (!result.isResult()) {
String validationError = result.getErrorDetails();
if (validationError != null) {
errorMsg += validationError + " ";
}
}
}
logger.error("Validation of " + validator + " for experiment Id " + experiment.getExperimentId() + " is FAILED:[error]. " + errorMsg);
validationResults.setValidationState(false);
try {
ErrorModel details = new ErrorModel();
details.setActualErrorMessage(errorMsg);
details.setCreationTime(Calendar.getInstance().getTimeInMillis());
orchestratorContext.getRegistry().getExperimentCatalog().add(ExpCatChildDataType.PROCESS_ERROR, details, processModel.getProcessId());
} catch (RegistryException e) {
logger.error("Error while saving error details to registry", e);
}
break;
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
logger.error("Error loading the validation class: ", validator, e);
validationResults.setValidationState(false);
}
}
}
if (validationResults.isValidationState()) {
return validationResults;
} else {
// atleast one validation has failed, so we throw an exception
LaunchValidationException launchValidationException = new LaunchValidationException();
launchValidationException.setValidationResult(validationResults);
launchValidationException.setErrorMessage("Validation failed refer the validationResults " + "list for detail error. Validation errors : " + errorMsg);
throw launchValidationException;
}
}
Aggregations