use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method taskLogoutByTag.
/**
* Returns the standard output (stdout) generated by a set of tasks filtered
* by a given tag.
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job
* @param taskTag
* the tag used to filter the tasks.
* @return the stdout generated by the task or an empty string if the result
* is not yet available
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/log/out")
@Produces("application/json")
public String taskLogoutByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/tag/" + taskTag + "/result/log/out");
List<TaskResult> trs = s.getTaskResultsByTag(jobId, taskTag);
StringBuffer result = new StringBuffer();
for (TaskResult tr : trs) {
if (tr.getOutput() != null) {
result.append(tr.getOutput().getStdoutLogs(true));
}
}
return result.toString();
} 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_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method getJobTasksIdsByTagPaginated.
/**
* Returns a list of the name of the tasks belonging to job
* <code>jobId</code> (with pagination)
*
* @param sessionId
* a valid session id.
* @param jobId
* the job id.
* @param taskTag
* the tag used to filter the tasks.
* @param offset
* the number of the first task to fetch
* @param limit
* the number of the last task to fetch (non inclusive)
* @return a list of task' states of the job <code>jobId</code> filtered by
* a given tag, for a given pagination.
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/paginated")
@Produces("application/json")
public RestPage<String> getJobTasksIdsByTagPaginated(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("-1") int limit) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
if (limit == -1)
limit = TASKS_PAGE_SIZE;
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskTag + "/paginated");
JobState jobState = s.getJobState(jobId);
TaskStatesPage page = jobState.getTaskByTagPaginated(taskTag, offset, limit);
List<TaskState> tasks = page.getTaskStates();
List<String> tasksName = new ArrayList<>(tasks.size());
for (TaskState ts : tasks) {
tasksName.add(ts.getId().getReadableName());
}
return new RestPage<String>(tasksName, 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_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method jobFullLogs.
@Override
@GET
@GZIP
@Path("jobs/{jobid}/log/full")
@Produces("application/json")
public InputStream jobFullLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @QueryParam("sessionid") String session) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException, IOException {
if (sessionId == null) {
sessionId = session;
}
try {
Scheduler scheduler = checkAccess(sessionId, "jobs/" + jobId + "/log/full");
JobState jobState = scheduler.getJobState(jobId);
List<TaskState> tasks = jobState.getTasks();
List<InputStream> streams = new ArrayList<>(tasks.size());
Collections.sort(tasks, TaskState.COMPARE_BY_FINISHED_TIME_ASC);
for (TaskState taskState : tasks) {
InputStream inputStream = null;
try {
if (taskState.isPreciousLogs()) {
inputStream = retrieveTaskLogsUsingDataspaces(sessionId, jobId, taskState.getId());
} else {
String taskLogs = retrieveTaskLogsUsingDatabase(sessionId, jobId, taskState.getName());
if (!taskLogs.isEmpty()) {
inputStream = IOUtils.toInputStream(taskLogs);
}
logger.warn("Retrieving truncated logs for task '" + taskState.getId() + "'");
}
} catch (Exception e) {
logger.info("Could not retrieve logs for task " + taskState.getId() + " (could be a non finished or killed task)", e);
}
if (inputStream != null) {
streams.add(inputStream);
}
}
if (streams.isEmpty()) {
// will produce HTTP 204 code
return null;
} else {
return new SequenceInputStream(Collections.enumeration(streams));
}
} 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_grid_cloud_portal.common.Session 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.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method taskResult.
/**
* Returns the task result of the task <code>taskName</code> of the job
* <code>jobId</code>
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job
* @param taskname
* the name of the task
* @return the task result of the task <code>taskName</code>
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result")
@Produces("application/json")
public TaskResultData taskResult(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname + "/result");
TaskResult taskResult = s.getTaskResult(jobId, taskname);
if (taskResult == null) {
TaskIdData taskIdData = new TaskIdData();
taskIdData.setReadableName(taskname);
TaskResultData taskResultData = new TaskResultData();
taskResultData.setId(taskIdData);
return taskResultData;
}
return buildTaskResultData(taskResult);
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (UnknownTaskException e) {
throw new UnknownTaskRestException(e);
}
}
Aggregations