Search in sources :

Example 6 with TaskStatesPage

use of org.ow2.proactive.scheduler.common.task.TaskStatesPage in project scheduling by ow2-proactive.

the class SchedulerStateRest method getJobTasksIdsByTag.

/**
 * Returns a list of the name of the tasks belonging to job and filtered by
 * a given tag. <code>jobId</code>
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            jobid one wants to list the tasks' name
 * @param taskTag
 *            the tag used to filter the tasks.
 * @return the list of task ids with the total number of them
 */
@Override
@GET
@Path("jobs/{jobid}/tasks/tag/{tasktag}")
@Produces("application/json")
public RestPage<String> getJobTasksIdsByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks");
        JobState jobState = s.getJobState(jobId);
        TaskStatesPage page = jobState.getTaskByTagPaginated(taskTag, 0, TASKS_PAGE_SIZE);
        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);
    }
}
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 7 with TaskStatesPage

use of org.ow2.proactive.scheduler.common.task.TaskStatesPage in project scheduling by ow2-proactive.

the class SchedulerStateRest method getJobTaskStatesPaginated.

/**
 * Returns a list of taskState with pagination
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the job id
 * @param offset
 *            the index of the first TaskState to return
 * @param limit
 *            the index (non inclusive) of the last TaskState to return
 * @return a list of task' states of the job <code>jobId</code>
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/taskstates/paginated")
@Produces("application/json")
public RestPage<TaskStateData> getJobTaskStatesPaginated(@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 + "/taskstates/paginated");
        JobState jobState = s.getJobState(jobId);
        TaskStatesPage page = jobState.getTasksPaginated(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 8 with TaskStatesPage

use of org.ow2.proactive.scheduler.common.task.TaskStatesPage in project scheduling by ow2-proactive.

the class RestTestUtils method newMockedJob.

protected static JobState newMockedJob(final String jobIdStr, final String tag, final int nbTasks) {
    JobState mockedJob = mock(JobState.class);
    JobId mockedJobId = mock(JobId.class);
    JobInfo mockedJobInfo = mock(JobInfo.class);
    List<TaskState> dumbList = new ArrayList<TaskState>(nbTasks);
    for (int i = 0; i < nbTasks; i++) {
        dumbList.add(newTaskState(jobIdStr, null, i, nbTasks));
    }
    when(mockedJobId.value()).thenReturn(jobIdStr);
    when(mockedJobInfo.getJobId()).thenReturn(mockedJobId);
    when(mockedJobInfo.getStatus()).thenReturn(JobStatus.PENDING);
    when(mockedJob.getId()).thenReturn(mockedJobId);
    when(mockedJob.getTasksPaginated(0, 50)).thenReturn(new TaskStatesPage(dumbList, nbTasks));
    when(mockedJob.getTaskByTagPaginated("", 0, 50)).thenReturn(new TaskStatesPage(dumbList, nbTasks));
    when(mockedJob.getJobInfo()).thenReturn(mockedJobInfo);
    return mockedJob;
}
Also used : JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ArrayList(java.util.ArrayList) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskStatesPage(org.ow2.proactive.scheduler.common.task.TaskStatesPage) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 9 with TaskStatesPage

use of org.ow2.proactive.scheduler.common.task.TaskStatesPage in project scheduling by ow2-proactive.

the class SchedulerStateRestPaginationTest method newMockedJob.

private JobState newMockedJob(final String jobIdStr, final int nbTasks) {
    JobState mockedJob = mock(JobState.class);
    JobId mockedJobId = mock(JobId.class);
    List<TaskState> dumbList = new ArrayList<TaskState>(nbTasks);
    for (int i = 0; i < nbTasks; i++) {
        TaskState mockedTask = mock(TaskState.class);
        TaskId mockedTaskId = mock(TaskId.class);
        when(mockedTaskId.getReadableName()).thenReturn(generateReadableName(jobIdStr, i, nbTasks));
        when(mockedTask.getId()).thenReturn(mockedTaskId);
        dumbList.add(mockedTask);
    }
    when(mockedJobId.value()).thenReturn(jobIdStr);
    when(mockedJob.getId()).thenReturn(mockedJobId);
    when(mockedJob.getTasksPaginated(0, 50)).thenReturn(new TaskStatesPage(dumbList, nbTasks));
    when(mockedJob.getTaskByTagPaginated("", 0, 50)).thenReturn(new TaskStatesPage(dumbList, nbTasks));
    return mockedJob;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ArrayList(java.util.ArrayList) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskStatesPage(org.ow2.proactive.scheduler.common.task.TaskStatesPage) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Aggregations

TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)9 JobState (org.ow2.proactive.scheduler.common.job.JobState)8 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)6 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)6 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)6 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)6 RestPage (org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage)6 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)6 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)6 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)6 ArrayList (java.util.ArrayList)5 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)5 GZIP (org.jboss.resteasy.annotations.GZIP)4 TaskStateData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData)3 JobId (org.ow2.proactive.scheduler.common.job.JobId)2 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)1 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)1