use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData in project scheduling by ow2-proactive.
the class SchedulerStateRest method validate.
@Override
public JobValidationData validate(PathSegment pathSegment, MultipartFormDataInput multipart) {
File tmpFile = null;
try {
Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap();
String name = formDataMap.keySet().iterator().next();
InputPart part1 = formDataMap.get(name).get(0);
InputStream is = part1.getBody(new GenericType<InputStream>() {
});
tmpFile = File.createTempFile("valid-job", "d");
Map<String, String> jobVariables;
try (OutputStream outputStream = new FileOutputStream(tmpFile)) {
IOUtils.copy(is, outputStream);
jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
}
return jobValidator.validateJobDescriptor(tmpFile, jobVariables);
} catch (IOException e) {
JobValidationData validation = new JobValidationData();
validation.setErrorMessage("Cannot read from the job validation request.");
validation.setStackTrace(getStackTrace(e));
return validation;
} finally {
if (tmpFile != null) {
FileUtils.deleteQuietly(tmpFile);
}
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData in project scheduling by ow2-proactive.
the class SchedulerStateRest method validateFromUrl.
@Override
public JobValidationData validateFromUrl(String sessionId, String url, PathSegment pathSegment) throws NotConnectedRestException {
File tmpWorkflowFile = null;
try {
checkAccess(sessionId);
String jobXml = downloadWorkflowContent(sessionId, url);
tmpWorkflowFile = File.createTempFile("job", "d");
Map<String, String> jobVariables;
try (OutputStream outputStream = new FileOutputStream(tmpWorkflowFile)) {
IOUtils.write(jobXml, outputStream);
jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
}
return jobValidator.validateJobDescriptor(tmpWorkflowFile, jobVariables);
} catch (JobCreationRestException | IOException e) {
JobValidationData validation = new JobValidationData();
validation.setErrorMessage("Error while reading workflow at url: " + url);
validation.setStackTrace(getStackTrace(e));
return validation;
} finally {
FileUtils.deleteQuietly(tmpWorkflowFile);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData in project scheduling by ow2-proactive.
the class ValidationUtil method fillUpdatedVariables.
private void fillUpdatedVariables(TaskFlowJob job, JobValidationData data) {
HashMap<String, String> updatedVariables = new HashMap<>();
for (JobVariable jobVariable : job.getVariables().values()) {
updatedVariables.put(jobVariable.getName(), jobVariable.getValue());
}
for (Task task : job.getTasks()) {
for (TaskVariable taskVariable : task.getVariables().values()) {
updatedVariables.put(task.getName() + ":" + taskVariable.getName(), taskVariable.getValue());
}
}
data.setUpdatedVariables(updatedVariables);
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData in project scheduling by ow2-proactive.
the class SchedulerRestWorkflowFromCatalogExecutionTest method testWhenValidatingACorruptWorkflowThenValidationContainsException.
@Test
public void testWhenValidatingACorruptWorkflowThenValidationContainsException() throws Exception {
String workflowUrl = getBaseUriTestWorkflowsServer() + "/corrupt";
JobValidationData response = schedulerRest.validateFromUrl(sessionId, workflowUrl, getEmptyPathSegment());
checkInvalidResponse(response);
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData in project scheduling by ow2-proactive.
the class SchedulerRestWorkflowFromCatalogExecutionTest method testWhenValidatingUsingAnInvalidWorkflowUrlThenValidationContainsException.
@Test
public void testWhenValidatingUsingAnInvalidWorkflowUrlThenValidationContainsException() throws Exception {
String workflowUrl = getBaseUriTestWorkflowsServer() + "/nonexistent";
JobValidationData response = schedulerRest.validateFromUrl(sessionId, workflowUrl, getEmptyPathSegment());
checkInvalidResponse(response);
}
Aggregations