Search in sources :

Example 1 with WorkflowSubmitter

use of org.ow2.proactive_grid_cloud_portal.scheduler.WorkflowSubmitter in project scheduling by ow2-proactive.

the class SchedulerStateRest method submitFromUrl.

/**
 * Submits a workflow to the scheduler from a workflow URL, creating hence a
 * new job resource.
 *
 * @param sessionId
 *            a valid session id
 * @param url
 *            url to the workflow content
 * @param pathSegment
 *            variables of the workflow
 * @return the <code>jobid</code> of the newly created job
 * @throws NotConnectedRestException
 * @throws IOException
 * @throws JobCreationRestException
 * @throws PermissionRestException
 * @throws SubmissionClosedRestException
 */
@Override
@POST
@Path("{path:jobs}")
@Produces("application/json")
public JobIdData submitFromUrl(@HeaderParam("sessionid") String sessionId, @HeaderParam("link") String url, @PathParam("path") PathSegment pathSegment) throws JobCreationRestException, NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, IOException {
    Scheduler s = checkAccess(sessionId, "jobs");
    File tmpWorkflowFile = null;
    try {
        String jobXml = downloadWorkflowContent(sessionId, url);
        tmpWorkflowFile = File.createTempFile("job", "d");
        JobId jobId;
        try (OutputStream outputStream = new FileOutputStream(tmpWorkflowFile)) {
            IOUtils.write(jobXml, outputStream);
            WorkflowSubmitter workflowSubmitter = new WorkflowSubmitter(s);
            jobId = workflowSubmitter.submit(tmpWorkflowFile, workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment));
        }
        return mapper.map(jobId, JobIdData.class);
    } catch (IOException e) {
        throw new IOException("Cannot save temporary job file on submission: " + e.getMessage(), e);
    } finally {
        FileUtils.deleteQuietly(tmpWorkflowFile);
    }
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 2 with WorkflowSubmitter

use of org.ow2.proactive_grid_cloud_portal.scheduler.WorkflowSubmitter in project scheduling by ow2-proactive.

the class AbstractFunctCmdTest method submitJob.

protected JobId submitJob(String filename, JobStatus waitForStatus) throws Exception {
    File jobFile = new File(this.getClass().getResource("config/" + filename).toURI());
    WorkflowSubmitter submitter = new WorkflowSubmitter(scheduler);
    JobId id = submitter.submit(jobFile, new HashMap<String, String>());
    waitJobState(id, waitForStatus, 500000);
    return id;
}
Also used : WorkflowSubmitter(org.ow2.proactive_grid_cloud_portal.scheduler.WorkflowSubmitter) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 3 with WorkflowSubmitter

use of org.ow2.proactive_grid_cloud_portal.scheduler.WorkflowSubmitter in project scheduling by ow2-proactive.

the class SchedulerStateRest method submit.

/**
 * Submits a job to the scheduler
 *
 * @param sessionId
 *            a valid session id
 * @return the <code>jobid</code> of the newly created job
 * @throws IOException
 *             if the job was not correctly uploaded/stored
 */
@Override
@POST
@Path("{path:submit}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("application/json")
public JobIdData submit(@HeaderParam("sessionid") String sessionId, @PathParam("path") PathSegment pathSegment, MultipartFormDataInput multipart) throws JobCreationRestException, NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, IOException {
    try {
        Scheduler scheduler = checkAccess(sessionId, "submit");
        Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap();
        String name = formDataMap.keySet().iterator().next();
        File tmpJobFile = null;
        try {
            // "file"
            InputPart part1 = multipart.getFormDataMap().get(name).get(0);
            String fileType = part1.getMediaType().toString().toLowerCase();
            if (!fileType.contains(MediaType.APPLICATION_XML.toLowerCase())) {
                throw new JobCreationRestException("Unknown job descriptor type: " + fileType);
            }
            // is the name of the browser's input field
            InputStream is = part1.getBody(new GenericType<InputStream>() {
            });
            tmpJobFile = File.createTempFile("job", "d");
            JobId jobId;
            try (OutputStream outputStream = new FileOutputStream(tmpJobFile)) {
                IOUtils.copy(is, outputStream);
                Map<String, String> jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
                WorkflowSubmitter workflowSubmitter = new WorkflowSubmitter(scheduler);
                jobId = workflowSubmitter.submit(tmpJobFile, jobVariables);
            }
            return mapper.map(jobId, JobIdData.class);
        } finally {
            if (tmpJobFile != null) {
                // clean the temporary file
                FileUtils.deleteQuietly(tmpJobFile);
            }
        }
    } catch (IOException e) {
        throw new IOException("I/O Error: " + e.getMessage(), e);
    }
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) BufferedInputStream(java.io.BufferedInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with WorkflowSubmitter

use of org.ow2.proactive_grid_cloud_portal.scheduler.WorkflowSubmitter in project scheduling by ow2-proactive.

the class RestSchedulerTagTest method submitJob.

private JobId submitJob(String filename) throws Exception {
    File jobFile = new File(this.getClass().getResource("config/" + filename).toURI());
    WorkflowSubmitter submitter = new WorkflowSubmitter(scheduler);
    JobId id = submitter.submit(jobFile, new HashMap<String, String>());
    waitJobState(id, JobStatus.FINISHED, 500000);
    return id;
}
Also used : WorkflowSubmitter(org.ow2.proactive_grid_cloud_portal.scheduler.WorkflowSubmitter) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Aggregations

File (java.io.File)4 JobId (org.ow2.proactive.scheduler.common.job.JobId)4 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)2 WorkflowSubmitter (org.ow2.proactive_grid_cloud_portal.scheduler.WorkflowSubmitter)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 List (java.util.List)1 Consumes (javax.ws.rs.Consumes)1 InputPart (org.jboss.resteasy.plugins.providers.multipart.InputPart)1 JobCreationRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException)1