Search in sources :

Example 6 with Page

use of org.ow2.proactive.scheduler.common.Page 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 7 with Page

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

the class SchedulerStateRestPaginationTest method testGetJobTasksIdsPaginated.

@Test
public void testGetJobTasksIdsPaginated() throws Throwable {
    JobState job = newMockedJob(jobIdStr, nbTasks);
    when(mockOfScheduler.getJobState(jobIdStr)).thenReturn(job);
    RestPage<String> page = restInterface.getTasksNamesPaginated(sessionId, jobIdStr, 0, nbTasks);
    assertTasks(nbTasks, jobIdStr, page);
}
Also used : JobState(org.ow2.proactive.scheduler.common.job.JobState) Test(org.junit.Test)

Example 8 with Page

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

the class SchedulerStateRestTaskCentricTest method testGetTaskStatesByTagSortByJobIdAsc.

@Test
public void testGetTaskStatesByTagSortByJobIdAsc() throws Throwable {
    int nbTasksInPage = 6;
    int nbTotalTasks = 6;
    ArrayList<String> jobIds = new ArrayList<String>(Arrays.asList("1", "8", "4", "4", "6", "2"));
    String tag = "TAG-TEST";
    Page<TaskState> expectedPage = RestTestUtils.newMockedTaskStatePage(jobIds, 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(".jobData.id,ascending"));
    RestTestUtils.assertTaskStates(expectedPage, page);
}
Also used : SortSpecifierContainer(org.ow2.proactive.scheduler.common.SortSpecifierContainer) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) ArrayList(java.util.ArrayList) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Test(org.junit.Test)

Example 9 with Page

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

the class SchedulerStateRestTaskCentricTest method testGetJobTasksIdsByTagPaginated.

@Test
public void testGetJobTasksIdsByTagPaginated() throws Throwable {
    int nbTasks = 50;
    String jobIdStr = "1";
    JobState job = RestTestUtils.newMockedJob(jobIdStr, "", nbTasks);
    when(mockOfScheduler.getJobState(jobIdStr)).thenReturn(job);
    RestPage<String> page = restInterface.getTasksNamesPaginated(sessionId, jobIdStr, 0, nbTasks);
    RestTestUtils.assertTasks(nbTasks, jobIdStr, page);
}
Also used : JobState(org.ow2.proactive.scheduler.common.job.JobState) Test(org.junit.Test)

Example 10 with Page

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

the class SchedulerStateRestTaskCentricTest method testGetJobTasksIdsPaginated.

@Test
public void testGetJobTasksIdsPaginated() throws Throwable {
    int nbTasks = 50;
    String jobIdStr = "1";
    JobState job = RestTestUtils.newMockedJob(jobIdStr, "", nbTasks);
    when(mockOfScheduler.getJobState(jobIdStr)).thenReturn(job);
    RestPage<String> page = restInterface.getTasksNamesPaginated(sessionId, jobIdStr, 0, nbTasks);
    RestTestUtils.assertTasks(nbTasks, jobIdStr, page);
}
Also used : JobState(org.ow2.proactive.scheduler.common.job.JobState) Test(org.junit.Test)

Aggregations

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