Search in sources :

Example 11 with GZIP

use of org.jboss.resteasy.annotations.GZIP in project scheduling by ow2-proactive.

the class SchedulerStateRest method taskResultByTag.

/**
 * Returns the task results of the set of task filtered by a given tag and
 * owned by the job <code>jobId</code>
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskTag
 *            the tag used to filter the tasks.
 * @return the task results of the set of tasks filtered by the given tag.
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result")
@Produces("application/json")
public List<TaskResultData> taskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskTag + "/result");
        List<TaskResult> taskResults = s.getTaskResultsByTag(jobId, taskTag);
        ArrayList<TaskResultData> results = new ArrayList<TaskResultData>(taskResults.size());
        for (TaskResult current : taskResults) {
            TaskResultData r = buildTaskResultData(PAFuture.getFutureValue(current));
            results.add(r);
        }
        return results;
    } 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) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) ArrayList(java.util.ArrayList) 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)

Example 12 with GZIP

use of org.jboss.resteasy.annotations.GZIP in project scheduling by ow2-proactive.

the class SchedulerStateRest method taskFullLogs.

/**
 * Returns full logs generated by the task from user data spaces if task was
 * run using the precious logs option. Otherwise, logs are retrieved from
 * the database. In this last case they may be truncated.
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskname
 *            the name of the task
 * @return all the logs generated by the task (either stdout and stderr) or
 *         an empty string if the result is not yet available
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result/log/full")
@Produces("application/json")
public InputStream taskFullLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname, @QueryParam("sessionid") String session) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException, IOException {
    try {
        if (sessionId == null) {
            sessionId = session;
        }
        Scheduler scheduler = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname + "/result/log/all");
        TaskResult taskResult = scheduler.getTaskResult(jobId, taskname);
        if (taskResult != null) {
            JobState jobState = scheduler.getJobState(taskResult.getTaskId().getJobId());
            boolean hasPreciousLogs = false;
            for (Task task : jobState.getTasks()) {
                if (task.getName().equals(taskname)) {
                    hasPreciousLogs = task.isPreciousLogs();
                    break;
                }
            }
            if (hasPreciousLogs) {
                return retrieveTaskLogsUsingDataspaces(sessionId, jobId, taskResult.getTaskId());
            } else {
                logger.warn("Retrieving truncated logs for task '" + taskname + "'");
                return IOUtils.toInputStream(retrieveTaskLogsUsingDatabase(sessionId, jobId, taskname));
            }
        } else {
            return null;
        }
    } 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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) Task(org.ow2.proactive.scheduler.common.task.Task) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) 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) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobState(org.ow2.proactive.scheduler.common.job.JobState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 13 with GZIP

use of org.jboss.resteasy.annotations.GZIP in project scheduling by ow2-proactive.

the class SchedulerStateRest method jobLogs.

/**
 * Returns all the logs generated by the job (either stdout and stderr)
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @return all the logs generated by the job (either stdout and stderr) or
 *         an empty string if the result is not yet available
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/result/log/all")
@Produces("application/json")
public String jobLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/result/log/all");
        JobResult jobResult = s.getJobResult(jobId);
        if (jobResult == null) {
            return "";
        }
        StringBuilder jobOutput = new StringBuilder();
        for (TaskResult tr : jobResult.getAllResults().values()) {
            if ((tr != null) && (tr.getOutput() != null)) {
                jobOutput.append(tr.getOutput().getAllLogs(true));
            }
        }
        return jobOutput.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) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) 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)

Example 14 with GZIP

use of org.jboss.resteasy.annotations.GZIP in project scheduling by ow2-proactive.

the class SchedulerStateRest method serializedValueOfTaskResultByTag.

/**
 * Returns the values of a set of tasks of the job <code>jobId</code>
 * filtered by a given tag. This method returns the result as a byte array
 * whatever the result is.
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskTag
 *            the tag used to filter the tasks.
 * @return the values of the set of tasks result as a byte array, indexed by
 *         the readable name of the task.
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/serializedvalue")
@Produces("application/json")
public Map<String, byte[]> serializedValueOfTaskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws Throwable {
    Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/tag" + taskTag + "/result/serializedvalue");
    List<TaskResult> trs = s.getTaskResultsByTag(jobId, taskTag);
    Map<String, byte[]> result = new HashMap<>(trs.size());
    for (TaskResult currentResult : trs) {
        TaskResult r = PAFuture.getFutureValue(currentResult);
        result.put(r.getTaskId().getReadableName(), r.getSerializedValue());
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) 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 15 with GZIP

use of org.jboss.resteasy.annotations.GZIP in project scheduling by ow2-proactive.

the class SchedulerStateRest method taskLogErr.

/**
 * Returns the standard error output (stderr) generated by the task
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskname
 *            the name of the task
 * @return the stderr generated by the task or an empty string if the result
 *         is not yet available
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result/log/err")
@Produces("application/json")
public String taskLogErr(@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/log/err");
        TaskResult tr = s.getTaskResult(jobId, taskname);
        if ((tr != null) && (tr.getOutput() != null)) {
            return tr.getOutput().getStderrLogs(true);
        } else {
            return "";
        }
    } 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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) 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) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) 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

Path (javax.ws.rs.Path)25 Produces (javax.ws.rs.Produces)25 GZIP (org.jboss.resteasy.annotations.GZIP)25 GET (javax.ws.rs.GET)24 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)23 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)17 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)17 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)17 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)17 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)16 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)16 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)16 JobState (org.ow2.proactive.scheduler.common.job.JobState)7 HashMap (java.util.HashMap)5 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)5 UnknownTaskRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException)5 ArrayList (java.util.ArrayList)4 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)4 RestPage (org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage)4 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)2