use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class SchedulerStateRest method schedulerChangeJobPriorityByValue.
/**
* changes the priority of a job
*
* @param sessionId
* a valid session id
* @param jobId
* the job id
* @param priorityValue
* a string representing the value of the priority
* @throws NumberFormatException
* @throws NotConnectedRestException
* @throws UnknownJobRestException
* @throws PermissionRestException
* @throws JobAlreadyFinishedRestException
*/
@Override
@PUT
@Path("jobs/{jobid}/priority/byvalue/{value}")
public void schedulerChangeJobPriorityByValue(@HeaderParam("sessionid") final String sessionId, @PathParam("jobid") final String jobId, @PathParam("value") String priorityValue) throws NumberFormatException, NotConnectedRestException, UnknownJobRestException, PermissionRestException, JobAlreadyFinishedRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/priority/byvalue" + priorityValue);
s.changeJobPriority(jobId, JobPriority.findPriority(Integer.parseInt(priorityValue)));
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (JobAlreadyFinishedException e) {
throw new JobAlreadyFinishedRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
}
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class SchedulerStateRest method getJobTaskStatesByTag.
/**
* Returns a list of taskState of the tasks filtered by a given tag.
*
* @param sessionId
* a valid session id
* @param jobId
* the job id
* @param taskTag
* the tag used to filter the tasks
* @return a list of task' states of the job <code>jobId</code> filtered by
* a given tag.
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/taskstates/{tasktag}")
@Produces("application/json")
public RestPage<TaskStateData> getJobTaskStatesByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/taskstates/" + taskTag);
JobState jobState = s.getJobState(jobId);
TaskStatesPage page = jobState.getTaskByTagPaginated(taskTag, 0, TASKS_PAGE_SIZE);
List<TaskStateData> tasks = map(page.getTaskStates(), TaskStateData.class);
return new RestPage<TaskStateData>(tasks, page.getSize());
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
}
}
use of org.ow2.proactive.scheduler.common.job.Job 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.scheduler.common.job.Job 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.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class ValidationUtil method fillUpdatedVariables.
private void fillUpdatedVariables(TaskFlowJob job, JobValidationData data) {
HashMap<String, String> updatedVariables = new HashMap<>();
for (JobVariable jobVariable : job.getVariables().values()) {
updatedVariables.put(jobVariable.getName(), jobVariable.getValue());
}
for (Task task : job.getTasks()) {
for (TaskVariable taskVariable : task.getVariables().values()) {
updatedVariables.put(task.getName() + ":" + taskVariable.getName(), taskVariable.getValue());
}
}
data.setUpdatedVariables(updatedVariables);
}
Aggregations