Search in sources :

Example 1 with RestPage

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage in project scheduling by ow2-proactive.

the class SchedulerStateRest method jobsInfo.

/**
 * Returns a subset of the scheduler state, including pending, running,
 * finished jobs (in this particular order). each jobs is described using -
 * its id - its owner - the JobInfo class
 *
 * @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 sessionId
 *            a valid session id
 * @return a list of UserJobData
 */
@Override
@GET
@Path("jobsinfo")
@Produces({ "application/json", "application/xml" })
public RestPage<UserJobData> jobsInfo(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit) throws PermissionRestException, NotConnectedRestException {
    try {
        Scheduler s = checkAccess(sessionId, "/scheduler/jobsinfo");
        Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(false, true, true, true), DEFAULT_JOB_SORT_PARAMS);
        List<UserJobData> userJobInfoList = new ArrayList<UserJobData>(page.getList().size());
        for (JobInfo jobInfo : page.getList()) {
            userJobInfoList.add(new UserJobData(mapper.map(jobInfo, JobInfoData.class)));
        }
        return new RestPage<UserJobData>(userJobInfoList, page.getSize());
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UserJobData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) 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)

Example 2 with RestPage

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage in project scheduling by ow2-proactive.

the class SchedulerStateRest method getJobTaskStatesByTagPaginated.

/**
 * {@inheritDoc}
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/taskstates/{tasktag}/paginated")
@Produces("application/json")
public RestPage<TaskStateData> getJobTaskStatesByTagPaginated(@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 + "/taskstates/" + taskTag + "/paginated");
        JobState jobState = s.getJobState(jobId);
        TaskStatesPage page = jobState.getTaskByTagPaginated(taskTag, offset, limit);
        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 3 with RestPage

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage in project scheduling by ow2-proactive.

the class SchedulerStateRest method getTaskStatesByTag.

@Override
public RestPage<TaskStateData> getTaskStatesByTag(String sessionId, String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit, SortSpecifierContainer sortParams) throws NotConnectedRestException, PermissionRestException {
    Scheduler s = checkAccess(sessionId, "tasks/tag/" + taskTag);
    PageBoundaries boundaries = Pagination.getTasksPageBoundaries(offset, limit, TASKS_PAGE_SIZE);
    Page<TaskState> page = null;
    // sortParams will be null
    if (sortParams == null) {
        sortParams = new SortSpecifierContainer();
    }
    try {
        page = s.getTaskStates(taskTag, from, to, mytasks, running, pending, finished, boundaries.getOffset(), boundaries.getLimit(), sortParams);
        List<TaskStateData> tasks = map(page.getList(), TaskStateData.class);
        return new RestPage<TaskStateData>(tasks, page.getSize());
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) SortSpecifierContainer(org.ow2.proactive.scheduler.common.SortSpecifierContainer) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PageBoundaries(org.ow2.proactive.scheduler.common.util.PageBoundaries) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 4 with RestPage

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage in project scheduling by ow2-proactive.

the class SchedulerStateRest method getTasksNamesPaginated.

/**
 * 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
 *            jobid one wants to list the tasks' name
 * @param offset
 *            the number of the first task to fetch
 * @param limit
 *            the number of the last task to fetch (non inclusive)
 * @return the list of task ids with the total number of them
 */
@Override
@GET
@Path("jobs/{jobid}/tasks/paginated")
@Produces("application/json")
public RestPage<String> getTasksNamesPaginated(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @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");
        JobState jobState = s.getJobState(jobId);
        TaskStatesPage page = jobState.getTasksPaginated(offset, limit);
        List<String> tasksNames = new ArrayList<>(page.getTaskStates().size());
        for (TaskState ts : page.getTaskStates()) {
            tasksNames.add(ts.getId().getReadableName());
        }
        return new RestPage<String>(tasksNames, 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) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) TaskStatesPage(org.ow2.proactive.scheduler.common.task.TaskStatesPage) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with RestPage

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage 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)

Aggregations

RestPage (org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage)15 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)12 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)12 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)12 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)10 JobState (org.ow2.proactive.scheduler.common.job.JobState)10 TaskStateData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData)10 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)9 GET (javax.ws.rs.GET)8 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)6 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)6 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)6 SortSpecifierContainer (org.ow2.proactive.scheduler.common.SortSpecifierContainer)5 GZIP (org.jboss.resteasy.annotations.GZIP)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3