Search in sources :

Example 1 with SubmissionClosedRestException

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

the class SchedulerStateRest method submitFlat.

/**
 * Submit job using flat command file
 *
 * @param sessionId
 *            valid session id
 * @param commandFileContent
 *            content of a command file: endline separated native commands
 * @param jobName
 *            name of the job to create
 * @param selectionScriptContent
 *            content of a selection script, or null
 * @param selectionScriptExtension
 *            extension of the selectionscript to determine script engine
 *            ("js", "py", "rb")
 * @return Id of the submitted job
 * @throws NotConnectedRestException
 * @throws IOException
 * @throws JobCreationRestException
 * @throws PermissionRestException
 * @throws SubmissionClosedRestException
 */
@Override
@POST
@Path("submitflat")
@Produces("application/json")
public JobIdData submitFlat(@HeaderParam("sessionid") String sessionId, @FormParam("commandFileContent") String commandFileContent, @FormParam("jobName") String jobName, @FormParam("selectionScriptContent") String selectionScriptContent, @FormParam("selectionScriptExtension") String selectionScriptExtension) throws NotConnectedRestException, IOException, JobCreationRestException, PermissionRestException, SubmissionClosedRestException {
    Scheduler s = checkAccess(sessionId, "submitflat");
    try {
        File command = File.createTempFile("flatsubmit_commands_", ".txt");
        command.deleteOnExit();
        String selectionPath = null;
        File selection = null;
        if (selectionScriptContent != null && selectionScriptContent.trim().length() > 0) {
            selection = File.createTempFile("flatsubmit_selection_", "." + selectionScriptExtension);
            selection.deleteOnExit();
            try (PrintWriter pw = new PrintWriter(new FileOutputStream(selection))) {
                pw.print(selectionScriptContent);
            }
            selectionPath = selection.getAbsolutePath();
        }
        try (PrintWriter pw = new PrintWriter(new FileOutputStream(command))) {
            pw.print(commandFileContent);
        }
        Job j = FlatJobFactory.getFactory().createNativeJobFromCommandsFile(command.getAbsolutePath(), jobName, selectionPath, null);
        JobId id = s.submit(j);
        command.delete();
        if (selection != null) {
            selection.delete();
        }
        return mapper.map(id, JobIdData.class);
    } catch (IOException e) {
        throw new IOException("I/O Error: " + e.getMessage(), e);
    } catch (JobCreationException e) {
        throw new JobCreationRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (SubmissionClosedException e) {
        throw new SubmissionClosedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) IOException(java.io.IOException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) FileOutputStream(java.io.FileOutputStream) SubmissionClosedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException) Job(org.ow2.proactive.scheduler.common.job.Job) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) PrintWriter(java.io.PrintWriter) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 2 with SubmissionClosedRestException

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

the class SchedulerStateRest method submitPlannings.

@Consumes(MediaType.APPLICATION_JSON)
@POST
@Path("{path:plannings}")
@Produces("application/json")
@Override
public String submitPlannings(@HeaderParam("sessionid") String sessionId, @PathParam("path") PathSegment pathSegment, Map<String, String> jobContentXmlString) throws JobCreationRestException, NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, IOException {
    checkAccess(sessionId, "plannings");
    Map<String, String> jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
    if (jobContentXmlString == null || jobContentXmlString.size() != 1) {
        throw new JobCreationRestException("Cannot find job body: code " + HttpURLConnection.HTTP_BAD_REQUEST);
    }
    Map<String, Object> requestBody = new HashMap<>(2);
    requestBody.put("variables", jobVariables);
    requestBody.put("xmlContentString", jobContentXmlString.entrySet().iterator().next().getValue());
    Response response = null;
    try {
        ResteasyClient client = new ResteasyClientBuilder().build();
        ResteasyWebTarget target = client.target(PortalConfiguration.JOBPLANNER_URL.getValueAsString());
        response = target.request().header("sessionid", sessionId).post(Entity.entity(requestBody, "application/json"));
        if (HttpURLConnection.HTTP_OK != response.getStatus()) {
            throw new IOException(String.format("Cannot access resource %s: code %d", PortalConfiguration.JOBPLANNER_URL.getValueAsString(), response.getStatus()));
        }
        return response.readEntity(String.class);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) Response(javax.ws.rs.core.Response) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) HashMap(java.util.HashMap) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) FileObject(org.apache.commons.vfs2.FileObject) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 3 with SubmissionClosedRestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException 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 4 with SubmissionClosedRestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException 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)

Aggregations

IOException (java.io.IOException)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)3 JobId (org.ow2.proactive.scheduler.common.job.JobId)3 JobCreationRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException)3 OutputStream (java.io.OutputStream)2 Consumes (javax.ws.rs.Consumes)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 SequenceInputStream (java.io.SequenceInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Response (javax.ws.rs.core.Response)1