Search in sources :

Example 6 with GZIP

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

the class SchedulerStateRest method metadataOfTaskResultByTag.

/**
 * Returns the metadata of the task result of task <code>taskName</code> of the
 * job <code>jobId</code>filtered by a given tag.
 * <p>
 * Metadata is a map containing additional information associated with a result. For example a file name if the result represents a file.
 *
 * @param sessionId a valid session id
 * @param jobId     the id of the job
 * @param taskTag   the tag used to filter the tasks.
 * @return a map containing for each task entry, the metadata of the task result
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/metadata")
@Produces("application/json")
public Map<String, Map<String, String>> metadataOfTaskResultByTag(@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, Map<String, String>> result = new HashMap<>(trs.size());
    for (TaskResult currentResult : trs) {
        TaskResult r = PAFuture.getFutureValue(currentResult);
        result.put(r.getTaskId().getReadableName(), r.getMetadata());
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 7 with GZIP

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

the class SchedulerStateRest method taskLogout.

/**
 * Returns the standard 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 stdout 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/out")
@Produces("application/json")
public String taskLogout(@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/out");
        TaskResult tr = s.getTaskResult(jobId, taskname);
        if ((tr != null) && (tr.getOutput() != null)) {
            return tr.getOutput().getStdoutLogs(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)

Example 8 with GZIP

use of org.jboss.resteasy.annotations.GZIP 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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) 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) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) JobState(org.ow2.proactive.scheduler.common.job.JobState) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) TaskStatesPage(org.ow2.proactive.scheduler.common.task.TaskStatesPage) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 9 with GZIP

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

the class SchedulerStateRest method revisionAndJobsInfo.

/**
 * Returns a map containing one entry with the revision id as key and the
 * list of UserJobData as value. each jobs is described using - its id - its
 * owner - the JobInfo class
 *
 * @param sessionId
 *            a valid session id
 * @param index
 *            optional, if a sublist has to be returned the index of the
 *            sublist
 * @param limit
 *            optional, if a sublist has to be returned, the limit of the
 *            sublist
 * @param myJobs
 *            fetch only the jobs for the user making the request
 * @param pending
 *            fetch pending jobs
 * @param running
 *            fetch running jobs
 * @param finished
 *            fetch finished jobs
 * @return a map containing one entry with the revision id as key and the
 *         list of UserJobData as value.
 */
@Override
@GET
@GZIP
@Path("revisionjobsinfo")
@Produces({ "application/json", "application/xml" })
public RestMapPage<Long, ArrayList<UserJobData>> revisionAndJobsInfo(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit, @QueryParam("myjobs") @DefaultValue("false") boolean myJobs, @QueryParam("pending") @DefaultValue("true") boolean pending, @QueryParam("running") @DefaultValue("true") boolean running, @QueryParam("finished") @DefaultValue("true") boolean finished) throws PermissionRestException, NotConnectedRestException {
    try {
        Scheduler s = checkAccess(sessionId, "revisionjobsinfo?index=" + index + "&limit=" + limit);
        String user = sessionStore.get(sessionId).getUserName();
        boolean onlyUserJobs = (myJobs && user != null && user.trim().length() > 0);
        Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(onlyUserJobs, pending, running, finished), DEFAULT_JOB_SORT_PARAMS);
        List<JobInfo> jobsInfo = page.getList();
        ArrayList<UserJobData> jobs = new ArrayList<>(jobsInfo.size());
        for (JobInfo jobInfo : jobsInfo) {
            jobs.add(new UserJobData(mapper.map(jobInfo, JobInfoData.class)));
        }
        HashMap<Long, ArrayList<UserJobData>> map = new HashMap<Long, ArrayList<UserJobData>>(1);
        map.put(SchedulerStateListener.getInstance().getSchedulerStateRevision(), jobs);
        RestMapPage<Long, ArrayList<UserJobData>> restMapPage = new RestMapPage<Long, ArrayList<UserJobData>>();
        restMapPage.setMap(map);
        restMapPage.setSize(page.getSize());
        return restMapPage;
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) RestMapPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestMapPage) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) HashMap(java.util.HashMap) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) UserJobData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 10 with GZIP

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

the class RMRest method executeNodeScript.

@Override
@POST
@GZIP
@Path("node/script")
@Produces("application/json")
public ScriptResult<Object> executeNodeScript(@HeaderParam("sessionid") String sessionId, @FormParam("nodeurl") String nodeUrl, @FormParam("script") String script, @FormParam("scriptEngine") String scriptEngine) throws Throwable {
    RMProxyUserInterface rm = checkAccess(sessionId);
    List<ScriptResult<Object>> results = rm.executeScript(script, scriptEngine, TargetType.NODE_URL.name(), Collections.singleton(nodeUrl));
    if (results.isEmpty()) {
        throw new IllegalStateException("Empty results from script execution");
    }
    return results.get(0);
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) 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