Search in sources :

Example 1 with JobValidationData

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);
        }
    }
}
Also used : InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) BufferedInputStream(java.io.BufferedInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) JobValidationData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData) File(java.io.File)

Example 2 with JobValidationData

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);
    }
}
Also used : JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) JobValidationData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData) File(java.io.File)

Example 3 with JobValidationData

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);
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) HashMap(java.util.HashMap) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 4 with JobValidationData

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);
}
Also used : JobValidationData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData) Test(org.junit.Test)

Example 5 with JobValidationData

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);
}
Also used : JobValidationData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData) Test(org.junit.Test)

Aggregations

JobValidationData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData)8 Test (org.junit.Test)5 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Task (org.ow2.proactive.scheduler.common.task.Task)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 InputPart (org.jboss.resteasy.plugins.providers.multipart.InputPart)1 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)1 Job (org.ow2.proactive.scheduler.common.job.Job)1 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)1 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)1 FlowError (org.ow2.proactive.scheduler.common.job.factories.FlowError)1