use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData 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.dto.JobIdData 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.dto.JobIdData in project scheduling by ow2-proactive.
the class SchedulerRestClient method submit.
private JobIdData submit(String sessionId, InputStream job, MediaType mediaType, Map<String, String> variables, Map<String, String> genericInfos) throws NotConnectedRestException {
String uriTmpl = restEndpointURL + addSlashIfMissing(restEndpointURL) + "scheduler/submit";
ResteasyClient client = buildResteasyClient(providerFactory);
ResteasyWebTarget target = client.target(uriTmpl);
// Generic infos
if (genericInfos != null) {
for (String key : genericInfos.keySet()) {
target = target.queryParamNoTemplate(key, genericInfos.get(key));
}
}
// Multipart form
MultipartFormDataOutput formData = new MultipartFormDataOutput();
// Add job to multipart
formData.addFormData(FILE_KEY, job, mediaType);
// Add variables to multipart
if (variables != null && variables.size() > 0) {
formData.addFormData(VARIABLES_KEY, variables, MediaType.APPLICATION_JSON_TYPE);
}
// Multipart form entity
GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(formData) {
};
Response response = target.request().header("sessionid", sessionId).post(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
if (response.getStatus() != HttpURLConnection.HTTP_OK) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedRestException("User not authenticated or session timeout.");
} else {
throwException(String.format("Job submission failed status code: %d", response.getStatus()), response);
}
}
return response.readEntity(JobIdData.class);
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.
the class SchedulerRestClient method reSubmit.
public JobIdData reSubmit(String sessionId, String jobId, Map<String, String> variables, Map<String, String> genericInfos) throws NotConnectedRestException {
String uriTmpl = restEndpointURL + addSlashIfMissing(restEndpointURL) + "scheduler/jobs/" + jobId + "/resubmit";
ResteasyClient client = buildResteasyClient(providerFactory);
ResteasyWebTarget target = client.target(uriTmpl);
// Variables
if (variables != null) {
for (String key : variables.keySet()) {
target = target.matrixParam(key, variables.get(key));
}
}
// Generic infos
if (genericInfos != null) {
for (String key : genericInfos.keySet()) {
target = target.queryParam(key, genericInfos.get(key));
}
}
Response response = target.request().header("sessionid", sessionId).get();
if (response.getStatus() != HttpURLConnection.HTTP_OK) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedRestException("User not authenticated or session timeout.");
} else {
throwException(String.format("Job submission failed status code: %d", response.getStatus()), response);
}
}
return response.readEntity(JobIdData.class);
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.
the class SchedulerClientExample method main.
public static void main(String[] args) throws Exception {
// LOGIN IN
SchedulerRestClient client = new SchedulerRestClient("http://localhost:8080/rest/");
SchedulerRestInterface scheduler = client.getScheduler();
String sessionId = scheduler.login("admin", "admin");
// JOB SUBMISSION
File xmlJobFile = new File("/path/to/some/existing/job/job_1.xml");
JobIdData xmlJob;
try (FileInputStream inputStream = new FileInputStream(xmlJobFile)) {
xmlJob = client.submitXml(sessionId, inputStream);
}
System.out.println(xmlJob.getReadableName() + " " + xmlJob.getId());
// FLAT JOB SUBMISSION
JobIdData flatJob = scheduler.submitFlat(sessionId, "echo hello", "test-hello", null, null);
System.out.println("Jobid=" + flatJob);
String serverlog = scheduler.jobServerLog(sessionId, Long.toString(flatJob.getId()));
System.out.println(serverlog);
while (true) {
JobStateData jobState2 = scheduler.listJobs(sessionId, Long.toString(flatJob.getId()));
System.out.println(jobState2);
if (jobState2.getJobInfo().getStatus().name().equals("FINISHED")) {
break;
}
Thread.sleep(100);
}
JobResultData jobResultData = scheduler.jobResult(sessionId, Long.toString(flatJob.getId()));
System.out.println(jobResultData);
TaskResultData taskresult = scheduler.taskResult(sessionId, Long.toString(flatJob.getId()), "task_1");
System.out.println(taskresult);
List<TaskStateData> jobTaskStates = scheduler.getJobTaskStates(sessionId, Long.toString(flatJob.getId())).getList();
System.out.println(jobTaskStates);
TaskStateData task_1 = scheduler.jobTask(sessionId, Long.toString(flatJob.getId()), "task_1");
System.out.println(task_1);
// OTHER CALLS
List<SchedulerUserData> users = scheduler.getUsers(sessionId);
System.out.println(users);
System.out.println(users.size());
RestMapPage<Long, ArrayList<UserJobData>> page = scheduler.revisionAndJobsInfo(sessionId, 0, 50, true, true, true, true, true, null, null, null, null, null);
Map<Long, ArrayList<UserJobData>> map = page.getMap();
System.out.println(map);
System.out.println(scheduler.getSchedulerStatus(sessionId));
System.out.println(scheduler.getUsageOnMyAccount(sessionId, new Date(), new Date()));
// FAILING CALL
try {
JobStateData jobState = scheduler.listJobs(sessionId, "601");
System.out.println(jobState);
} catch (UnknownJobRestException e) {
System.err.println("exception! " + e.getMessage());
e.printStackTrace();
}
}
Aggregations