use of org.ow2.proactive.scheduler.common.JobFilterCriteria in project scheduling by ow2-proactive.
the class SchedulerStateRest method jobsInfo.
/**
* Returns a subset of the scheduler state, including pending, running,
* finished jobs (in this particular order). each jobs is described using -
* its id - its owner - the JobInfo class
*
* @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 sessionId
* a valid session id
* @return a list of UserJobData
*/
@Override
@GET
@Path("jobsinfo")
@Produces({ "application/json", "application/xml" })
public RestPage<UserJobData> jobsInfo(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit) throws PermissionRestException, NotConnectedRestException {
try {
Scheduler s = checkAccess(sessionId, "/scheduler/jobsinfo");
Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(false, true, true, true), DEFAULT_JOB_SORT_PARAMS);
List<UserJobData> userJobInfoList = new ArrayList<UserJobData>(page.getList().size());
for (JobInfo jobInfo : page.getList()) {
userJobInfoList.add(new UserJobData(mapper.map(jobInfo, JobInfoData.class)));
}
return new RestPage<UserJobData>(userJobInfoList, page.getSize());
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (PermissionException e) {
throw new PermissionRestException(e);
}
}
use of org.ow2.proactive.scheduler.common.JobFilterCriteria 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.JobFilterCriteria in project scheduling by ow2-proactive.
the class SchedulerClient method getJobs.
@Override
public Page<JobInfo> getJobs(int index, int range, JobFilterCriteria criteria, List<SortParameter<JobSortParameter>> jobSortParameters) throws NotConnectedException, PermissionException {
Page<JobInfo> jobInfos = null;
try {
String sortParams = createJobSortParamsString(jobSortParameters);
RestMapPage<Long, ArrayList<UserJobData>> userJobsAllRevisions = restApi().revisionAndJobsInfo(sid, index, range, criteria.isMyJobsOnly(), criteria.isPending(), criteria.isRunning(), criteria.isFinished(), criteria.isChildJobs(), criteria.getJobName(), criteria.getProjectName(), criteria.getUserName(), criteria.getParentId(), sortParams);
List<UserJobData> userJobs = userJobsAllRevisions.getMap().values().iterator().next();
jobInfos = new Page<JobInfo>(toJobInfos(userJobs), userJobs.size());
} catch (Exception e) {
throwNCEOrPE(e);
}
return jobInfos;
}
use of org.ow2.proactive.scheduler.common.JobFilterCriteria in project scheduling by ow2-proactive.
the class SchedulerFrontend method getJobs.
/**
* {@inheritDoc}
*/
@Override
@ImmediateService
public Page<JobInfo> getJobs(int offset, int limit, JobFilterCriteria filterCriteria, List<SortParameter<JobSortParameter>> sortParameters) throws NotConnectedException, PermissionException {
UserIdentificationImpl ident = frontendState.checkPermission("getJobs", "You don't have permissions to load jobs");
boolean myJobsOnly = filterCriteria.isMyJobsOnly();
String user = filterCriteria.getUserName();
if (myJobsOnly) {
user = ident.getUsername();
}
Page<JobInfo> jobsInfo = dbManager.getJobs(offset, limit, user, filterCriteria.isPending(), filterCriteria.isRunning(), filterCriteria.isFinished(), filterCriteria.isChildJobs(), filterCriteria.getJobName(), filterCriteria.getProjectName(), filterCriteria.getParentId(), sortParameters);
/**
* Add/inject to each JobInfo the list of signals used by the job, if they exist.
*/
insertSignals(jobsInfo.getList());
/**
* Inject visualization connection strings for running job when available
*/
insertVisualization(jobsInfo.getList());
/**
* Remove variables and generic info when the user is not allowed to see these details
*/
filterVariablesAndGenericInfo(jobsInfo.getList());
return jobsInfo;
}
use of org.ow2.proactive.scheduler.common.JobFilterCriteria 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);
}
}
Aggregations