use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException 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);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException 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();
}
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException 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.exception.JobCreationRestException 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.exception.JobCreationRestException 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);
}
}
Aggregations