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);
}
}
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;
}
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);
}
}
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;
}
Aggregations