Search in sources :

Example 16 with TaskStateData

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData 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 17 with TaskStateData

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

the class RestTestUtils method newMockedTaskStateData.

protected static TaskStateData newMockedTaskStateData(String jobIdStr, String tag, long cnt, int nbTasks) {
    TaskStateData mockedTaskStateData = mock(TaskStateData.class);
    TaskInfoData mockedTaskInfoData = mock(TaskInfoData.class);
    TaskIdData mockedTaskIdData = mock(TaskIdData.class);
    when(mockedTaskIdData.getReadableName()).thenReturn(generateReadableName(jobIdStr, cnt, nbTasks));
    when(mockedTaskIdData.getId()).thenReturn(cnt);
    when(mockedTaskInfoData.getTaskId()).thenReturn(mockedTaskIdData);
    when(mockedTaskStateData.getTaskInfo()).thenReturn(mockedTaskInfoData);
    when(mockedTaskStateData.getTag()).thenReturn(tag);
    return mockedTaskStateData;
}
Also used : TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) TaskInfoData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskInfoData) TaskIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskIdData)

Example 18 with TaskStateData

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

the class RestTestUtils method assertTaskStates.

protected static void assertTaskStates(Page<TaskState> expected, RestPage<TaskStateData> actual) {
    assertEquals("Number of tasks in page is incorrect", expected.getList().size(), actual.getList().size());
    assertEquals("Total number of tasks is incorrect", expected.getSize(), actual.getSize());
    for (int i = 0; i < expected.getList().size(); i++) {
        TaskState tExpected = expected.getList().get(i);
        TaskStateData tActual = actual.getList().get(i);
        assertEquals("readableName incorrect", tExpected.getId().getReadableName(), tActual.getName());
        assertEquals("tag incorrect", tExpected.getTag(), tActual.getTag());
    }
}
Also used : TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 19 with TaskStateData

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

the class SchedulerStateRestTaskCentricTest method testGetTaskStatesByTagNoSorting.

@Test
public void testGetTaskStatesByTagNoSorting() throws Throwable {
    int nbTasksInPage = 50;
    int nbTotalTasks = 100;
    String jobIdStr = "1";
    String tag = "TAG-TEST";
    Page<TaskState> expectedPage = RestTestUtils.newMockedTaskStatePage(jobIdStr, tag, nbTasksInPage, nbTotalTasks);
    when(mockOfScheduler.getTaskStates(anyString(), anyLong(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyInt(), anyInt(), any(SortSpecifierContainer.class))).thenReturn(expectedPage);
    RestPage<TaskStateData> page = restInterface.getTaskStatesByTag(sessionId, tag, 0, 0, false, true, true, true, 0, nbTasksInPage, new SortSpecifierContainer());
    RestTestUtils.assertTaskStates(expectedPage, page);
}
Also used : SortSpecifierContainer(org.ow2.proactive.scheduler.common.SortSpecifierContainer) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Test(org.junit.Test)

Example 20 with TaskStateData

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

the class JobStateImpl method getTasksByTag.

@Override
public List<TaskState> getTasksByTag(String tag) {
    Map<String, TaskStateData> taskStateMap = jobStateData.getTasks();
    List<TaskState> taskStateList = new ArrayList<>(taskStateMap.size());
    for (TaskStateData ts : taskStateMap.values()) {
        String taskTag = ts.getTag();
        if (taskTag != null && taskTag.equals(tag)) {
            taskStateList.add(DataUtility.taskState(ts));
        }
    }
    return taskStateList;
}
Also used : TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) ArrayList(java.util.ArrayList) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Aggregations

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