Search in sources :

Example 11 with RestPage

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

the class ListTaskStatesCommandTest method testCommandJobIdUnknownTag.

@Test
public void testCommandJobIdUnknownTag() throws Exception {
    when(restApi.getJobTaskStatesByTag(anyString(), eq("1"), eq("unknownTag"))).thenReturn(new RestPage(new ArrayList<TaskStateData>(), 0));
    executeTest(jobId, unknownTag);
    String out = capturedOutput.toString();
    System.out.println(out);
    assertThat(out, not(containsString("task")));
    assertThat(out, containsString("ID     NAME"));
}
Also used : RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 12 with RestPage

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

the class SchedulerClient method getTaskIds.

@Override
public Page<TaskId> getTaskIds(String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit) throws NotConnectedException, PermissionException {
    RestPage<TaskStateData> page = null;
    try {
        page = restApi().getTaskStates(sid, from, to, mytasks, running, pending, finished, offset, limit, null);
    } catch (NotConnectedRestException e) {
        throw new NotConnectedException(e);
    } catch (PermissionRestException e) {
        throw new PermissionException(e);
    }
    List<TaskId> lTaskIds = new ArrayList<TaskId>(page.getList().size());
    for (TaskStateData taskStateData : page.getList()) {
        TaskInfoData taskInfo = taskStateData.getTaskInfo();
        TaskIdData taskIdData = taskInfo.getTaskId();
        JobId jobId = new JobIdImpl(taskInfo.getJobId().getId(), taskInfo.getJobId().getReadableName());
        TaskId taskId = TaskIdImpl.createTaskId(jobId, taskIdData.getReadableName(), taskIdData.getId());
        lTaskIds.add(taskId);
    }
    return new Page<TaskId>(lTaskIds, page.getSize());
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) TaskInfoData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskInfoData) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Page(org.ow2.proactive.scheduler.common.Page) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TaskIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskIdData) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 13 with RestPage

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

the class SchedulerClient method getTaskStates.

@Override
public Page<TaskState> getTaskStates(String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit, SortSpecifierContainer sortParams) throws NotConnectedException, PermissionException {
    RestPage<TaskStateData> page = null;
    SortSpecifierContainer sortContainer = new SortSpecifierContainer(sortParams.toString());
    try {
        page = restApi().getTaskStates(sid, from, to, mytasks, running, pending, finished, offset, limit, sortContainer);
    } catch (NotConnectedRestException e) {
        throw new NotConnectedException(e);
    } catch (PermissionRestException e) {
        throw new PermissionException(e);
    }
    List<TaskState> lTaskStates = new ArrayList<TaskState>(page.getList().size());
    for (TaskStateData taskStateData : page.getList()) {
        lTaskStates.add(new TaskStateImpl(taskStateData));
    }
    return new Page<TaskState>(lTaskStates, page.getSize());
}
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) ArrayList(java.util.ArrayList) TaskStateImpl(org.ow2.proactive.scheduler.rest.data.TaskStateImpl) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Page(org.ow2.proactive.scheduler.common.Page) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 14 with RestPage

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

the class SchedulerStateRest method getTaskIdsByTag.

@Override
public RestPage<String> getTaskIdsByTag(String sessionId, String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit) throws NotConnectedRestException, PermissionRestException {
    Scheduler s = checkAccess(sessionId, "tasks");
    PageBoundaries boundaries = Pagination.getTasksPageBoundaries(offset, limit, TASKS_PAGE_SIZE);
    Page<TaskId> page = null;
    try {
        page = s.getTaskIds(taskTag, from, to, mytasks, running, pending, finished, boundaries.getOffset(), boundaries.getLimit());
        List<TaskId> taskIds = page.getList();
        List<String> taskNames = new ArrayList<>(taskIds.size());
        for (TaskId taskId : taskIds) {
            taskNames.add(taskId.getReadableName());
        }
        return new RestPage<String>(taskNames, 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) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) PageBoundaries(org.ow2.proactive.scheduler.common.util.PageBoundaries)

Example 15 with RestPage

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

the class SchedulerStateRest method getJobTasksIdsByTagPaginated.

/**
 * 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
 *            the job id.
 * @param taskTag
 *            the tag used to filter the tasks.
 * @param offset
 *            the number of the first task to fetch
 * @param limit
 *            the number of the last task to fetch (non inclusive)
 * @return a list of task' states of the job <code>jobId</code> filtered by
 *         a given tag, for a given pagination.
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/paginated")
@Produces("application/json")
public RestPage<String> getJobTasksIdsByTagPaginated(@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 + "/tasks/" + taskTag + "/paginated");
        JobState jobState = s.getJobState(jobId);
        TaskStatesPage page = jobState.getTaskByTagPaginated(taskTag, offset, limit);
        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) 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