Search in sources :

Example 1 with JobFilterCriteria

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);
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UserJobData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with JobFilterCriteria

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);
    }
}
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 3 with JobFilterCriteria

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;
}
Also used : JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ArrayList(java.util.ArrayList) TaskStatus.statusesToString(org.ow2.proactive.scheduler.common.task.TaskStatus.statusesToString) KeyStoreException(java.security.KeyStoreException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) SignalApiException(org.ow2.proactive.scheduler.signal.SignalApiException)

Example 4 with JobFilterCriteria

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;
}
Also used : JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) UserIdentificationImpl(org.ow2.proactive.scheduler.job.UserIdentificationImpl) ImmediateService(org.objectweb.proactive.annotation.ImmediateService)

Example 5 with JobFilterCriteria

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);
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)7 JobFilterCriteria (org.ow2.proactive.scheduler.common.JobFilterCriteria)5 ArrayList (java.util.ArrayList)4 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)4 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)4 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)4 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)3 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)3 HashMap (java.util.HashMap)2 JobId (org.ow2.proactive.scheduler.common.job.JobId)2 RestPage (org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage)2 UserJobData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData)2 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)1 SimpleJob (functionaltests.jobs.SimpleJob)1 IOException (java.io.IOException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1