Search in sources :

Example 26 with UnknownJobRestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method jobResultValue.

/**
 * Returns all the task results of this job as a map whose the key is the
 * name of the task and its task result.<br>
 * If the result cannot be instantiated, the content is replaced by the
 * string 'Unknown value type'. To get the serialized form of a given
 * result, one has to call the following restful service
 * jobs/{jobid}/tasks/{taskname}/result/serializedvalue
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            a job id
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/result/value")
@Produces("application/json")
public Map<String, String> jobResultValue(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, PermissionRestException, UnknownJobRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/result/value");
        JobResult jobResult = PAFuture.getFutureValue(s.getJobResult(jobId));
        if (jobResult == null) {
            return null;
        }
        Map<String, TaskResult> allResults = jobResult.getAllResults();
        Map<String, String> res = new HashMap<>(allResults.size());
        for (final Entry<String, TaskResult> entry : allResults.entrySet()) {
            TaskResult taskResult = entry.getValue();
            String value = getTaskResultValueAsStringOrExceptionStackTrace(taskResult);
            res.put(entry.getKey(), value);
        }
        return res;
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) HashMap(java.util.HashMap) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 27 with UnknownJobRestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method taskLogByTag.

/**
 * Returns all the logs generated by a set of the tasks (either stdout and
 * stderr) filtered by a 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 list of logs generated by each filtered task (either stdout
 *         and stderr) or an empty string if the result is not yet available
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/log/all")
@Produces("application/json")
public String taskLogByTag(@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/err");
        List<TaskResult> trs = s.getTaskResultsByTag(jobId, taskTag);
        StringBuffer buf = new StringBuffer();
        for (TaskResult tr : trs) {
            if (tr.getOutput() != null) {
                buf.append(tr.getOutput().getAllLogs(true));
            }
        }
        return buf.toString();
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Aggregations

UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)27 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)26 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)26 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)26 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)26 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)26 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)25 Path (javax.ws.rs.Path)24 GET (javax.ws.rs.GET)22 Produces (javax.ws.rs.Produces)22 GZIP (org.jboss.resteasy.annotations.GZIP)16 JobState (org.ow2.proactive.scheduler.common.job.JobState)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)10 ArrayList (java.util.ArrayList)6 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)6 RestPage (org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage)6 UnknownTaskRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException)6 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)5 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)5 JobAlreadyFinishedException (org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException)3