use of org.ow2.proactive.scheduler.common.task.TaskState in project scheduling by ow2-proactive.
the class SchedulerFrontend method getTaskResultFromIncarnation.
/**
* {@inheritDoc}
*/
@Override
@ImmediateService
public TaskResult getTaskResultFromIncarnation(JobId jobId, String taskName, int inc) throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
// checking permissions
frontendState.checkPermissions("getTaskResultFromIncarnation", frontendState.getIdentifiedJob(jobId), YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_TASK_RESULT_OF_THIS_JOB);
if (inc < 0) {
throw new IllegalArgumentException("Incarnation must be 0 or greater.");
}
jlogger.debug(jobId, "trying to get the task result, incarnation " + inc);
if (inc < 0) {
throw new IllegalArgumentException("Incarnation must be 0 or greater.");
}
try {
TaskResult result = dbManager.loadTaskResult(jobId, taskName, inc);
// handling special statuses
TaskState ts = frontendState.getTaskState(jobId, taskName);
switch(ts.getStatus()) {
case NOT_STARTED:
if (result == null) {
return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskCouldNotStartException(), new SimpleTaskLogs("", "The task could not start due to dependency failure"), 0);
} else {
Throwable newException = new TaskCouldNotStartException("The task could not start due to dependency failure", result.getException());
((TaskResultImpl) result).setException(newException);
}
break;
case NOT_RESTARTED:
if (result == null) {
return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskCouldNotRestartException(), new SimpleTaskLogs("", "The task could not be restarted after an error during the previous execution"), 0);
} else {
Throwable newException = new TaskCouldNotRestartException("The task could not be restarted after an error during the previous execution", result.getException());
((TaskResultImpl) result).setException(newException);
}
break;
case SKIPPED:
// result should always be null
return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskSkippedException(), new SimpleTaskLogs("", "The task was skipped in the workflow"), 0);
}
if (result == null) {
// otherwise the task is not finished
jlogger.info(jobId, taskName + " is not finished");
return null;
} else {
return result;
}
} catch (DatabaseManagerException e) {
throw new UnknownTaskException("Unknown task " + taskName + ", job: " + jobId);
}
}
use of org.ow2.proactive.scheduler.common.task.TaskState in project scheduling by ow2-proactive.
the class JobState method getTags.
/**
* To get the list of available tags in a job and that matches a given prefix.
* @param prefix the prefix used to filter the tags.
* @return the list of tags.
*/
public List<String> getTags(String prefix) {
Set<String> result = new HashSet<>();
String tag = null;
for (TaskState task : this.getTasks()) {
tag = task.getTag();
if (tag != null && tag.startsWith(prefix)) {
result.add(task.getTag());
}
}
return new ArrayList<>(result);
}
use of org.ow2.proactive.scheduler.common.task.TaskState 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.scheduler.common.task.TaskState 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.scheduler.common.task.TaskState in project scheduling by ow2-proactive.
the class SchedulerStateRest method jobTask.
/**
* Return the task state 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 state of the task <code>taskname</code> of the job
* <code>jobId</code>
*/
@Override
@GET
@Path("jobs/{jobid}/tasks/{taskname}")
@Produces("application/json")
public TaskStateData jobTask(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException, UnknownTaskRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname);
JobState jobState = s.getJobState(jobId);
for (TaskState ts : jobState.getTasks()) {
if (ts.getId().getReadableName().equals(taskname)) {
return mapper.map(ts, TaskStateData.class);
}
}
throw new UnknownTaskRestException("task " + taskname + "not found");
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
}
}
Aggregations