use of org.ow2.proactive.scheduler.common.Page in project scheduling by ow2-proactive.
the class SchedulerStateRest method jobs.
/**
* Returns the ids of the current jobs under a list of string.
*
* @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
* @return a list of jobs' ids under the form of a list of string
*/
@Override
@GET
@Path("jobs")
@Produces("application/json")
public RestPage<String> jobs(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit) throws NotConnectedRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "/scheduler/jobs");
Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(false, true, true, true), DEFAULT_JOB_SORT_PARAMS);
List<String> ids = new ArrayList<String>(page.getList().size());
for (JobInfo jobInfo : page.getList()) {
ids.add(jobInfo.getJobId().value());
}
return new RestPage<String>(ids, page.getSize());
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (PermissionException e) {
throw new PermissionRestException(e);
}
}
use of org.ow2.proactive.scheduler.common.Page 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);
}
}
use of org.ow2.proactive.scheduler.common.Page in project scheduling by ow2-proactive.
the class RestSchedulerJobPaginationTest method testJobsPagination.
@Test
public void testJobsPagination() throws Exception {
Assert.assertEquals("Test expects only one node", 1, RestFuncTHelper.DEFAULT_NUMBER_OF_NODES);
JobId jobId1 = getScheduler().submit(createJob(NonTerminatingJob.class));
waitJobState(jobId1, JobStatus.RUNNING, 30000);
JobId jobId2 = submitDefaultJob();
JobId jobId3 = submitDefaultJob();
checkPagingRequests1();
// check 'jobsinfo' and 'revisionjobsinfo' provide job's attributes
JSONObject page;
JSONArray jobs;
page = getRequestJSONObject(getResourceUrl("jobsinfo"));
jobs = (JSONArray) page.get("list");
checkJob((JSONObject) jobs.get(2), JobStatus.RUNNING, 1, 0);
page = getRequestJSONObject(getResourceUrl("revisionjobsinfo"));
JSONObject map = (JSONObject) page.get("map");
Assert.assertEquals(1, map.keySet().size());
jobs = (JSONArray) map.get(map.keySet().iterator().next());
checkJob((JSONObject) jobs.get(2), JobStatus.RUNNING, 1, 0);
checkFiltering1();
String resource = "jobs/" + jobId1.value() + "/kill";
String schedulerUrl = getResourceUrl(resource);
HttpPut httpPut = new HttpPut(schedulerUrl);
setSessionHeader(httpPut);
HttpResponse response = executeUriRequest(httpPut);
assertHttpStatusOK(response);
waitJobState(jobId1, JobStatus.KILLED, 30000);
waitJobState(jobId2, JobStatus.FINISHED, 30000);
waitJobState(jobId3, JobStatus.FINISHED, 30000);
checkFiltering2();
// check 'jobsinfo' and 'revisionjobsinfo' provide updated job's attributes
JSONObject job = null;
page = getRequestJSONObject(getResourceUrl("jobsinfo"));
jobs = (JSONArray) page.get("list");
checkJob(findJob("1", jobs), JobStatus.KILLED, 0, 0);
page = getRequestJSONObject(getResourceUrl("revisionjobsinfo"));
map = (JSONObject) page.get("map");
Assert.assertEquals(1, map.keySet().size());
jobs = (JSONArray) map.get(map.keySet().iterator().next());
checkJob(findJob("1", jobs), JobStatus.KILLED, 0, 0);
checkPagingRequests2();
}
use of org.ow2.proactive.scheduler.common.Page 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());
}
}
use of org.ow2.proactive.scheduler.common.Page in project scheduling by ow2-proactive.
the class RestTestUtils method newMockedTaskIdPage.
protected static Page<TaskId> newMockedTaskIdPage(String jobIdStr, int nbTasks, String tag) {
List<TaskId> lTaskId = new ArrayList<TaskId>(nbTasks);
for (int i = 0; i < nbTasks; i++) {
TaskId mockedTaskId = mock(TaskId.class);
when(mockedTaskId.getReadableName()).thenReturn(generateReadableName(jobIdStr, i, nbTasks));
when(mockedTaskId.getTag()).thenReturn(tag);
lTaskId.add(mockedTaskId);
}
return new Page<TaskId>(lTaskId, nbTasks);
}
Aggregations