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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations