Search in sources :

Example 1 with SortParameter

use of org.ow2.proactive.db.SortParameter in project scheduling by ow2-proactive.

the class TestLoadJobsPagination method testPagingAndFilteting.

@Test
public void testPagingAndFilteting() throws Exception {
    InternalJob job;
    InternalTask task;
    // pending job - 1
    defaultSubmitJob(createJob());
    // job for user1 - 2
    defaultSubmitJob(createJob(), "user1");
    // running job - 3
    job = defaultSubmitJob(createJob());
    job.start();
    task = startTask(job, job.getITasks().get(0));
    dbManager.jobTaskStarted(job, task, true);
    // killed job - 4
    job = defaultSubmitJob(createJob());
    job.failed(null, JobStatus.KILLED);
    dbManager.updateAfterJobKilled(job, Collections.<TaskId>emptySet());
    // job for user2 - 5
    defaultSubmitJob(createJob(), "user2");
    // finished job - 6
    job = defaultSubmitJob(createJob());
    job.start();
    task = startTask(job, job.getITasks().get(0));
    dbManager.jobTaskStarted(job, task, true);
    TaskResultImpl result = new TaskResultImpl(null, new TestResult(0, "result"), null, 0);
    job.terminateTask(false, task.getId(), null, null, result);
    job.terminate();
    dbManager.updateAfterTaskFinished(job, task, new TaskResultImpl(null, new TestResult(0, "result"), null, 0));
    // canceled job - 7
    job = defaultSubmitJob(createJob());
    job.failed(job.getITasks().get(0).getId(), JobStatus.CANCELED);
    dbManager.updateAfterJobKilled(job, Collections.<TaskId>emptySet());
    // job marked as removed, method 'getJobs' shouldn't return it
    job = defaultSubmitJob(createJob());
    dbManager.removeJob(job.getId(), System.currentTimeMillis(), false);
    List<JobInfo> jobs;
    List<SortParameter<JobSortParameter>> sortParameters = new ArrayList<>();
    sortParameters.add(new SortParameter<>(JobSortParameter.ID, SortOrder.ASC));
    jobs = dbManager.getJobs(5, 1, null, true, true, true, sortParameters).getList();
    JobInfo jobInfo = jobs.get(0);
    Assert.assertEquals("6", jobInfo.getJobId().value());
    Assert.assertEquals(JobStatus.FINISHED, jobInfo.getStatus());
    Assert.assertEquals("TestLoadJobsPagination", jobInfo.getJobId().getReadableName());
    Assert.assertEquals(1, jobInfo.getTotalNumberOfTasks());
    Assert.assertEquals(1, jobInfo.getNumberOfFinishedTasks());
    Assert.assertEquals(0, jobInfo.getNumberOfRunningTasks());
    Assert.assertEquals(0, jobInfo.getNumberOfPendingTasks());
    Assert.assertEquals(JobPriority.NORMAL, jobInfo.getPriority());
    Assert.assertEquals(DEFAULT_USER_NAME, jobInfo.getJobOwner());
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(-1, -1, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(-1, 5, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5);
    jobs = dbManager.getJobs(2, -1, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(0, 0, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(0, 1, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1);
    jobs = dbManager.getJobs(0, 3, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3);
    jobs = dbManager.getJobs(1, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(5, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 6, 7);
    jobs = dbManager.getJobs(6, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 7);
    jobs = dbManager.getJobs(7, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 3, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, "user1", true, true, true, sortParameters).getList();
    checkJobs(jobs, 2);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, false, sortParameters).getList();
    checkJobs(jobs, 1);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, false, sortParameters).getList();
    checkJobs(jobs, 3);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, true, sortParameters).getList();
    checkJobs(jobs, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, true, sortParameters).getList();
    checkJobs(jobs, 3, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, true, sortParameters).getList();
    checkJobs(jobs, 1, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, false, sortParameters).getList();
    checkJobs(jobs, 1, 3);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, false, sortParameters).getList();
    checkJobs(jobs);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ArrayList(java.util.ArrayList) JobSortParameter(org.ow2.proactive.scheduler.common.JobSortParameter) SortParameter(org.ow2.proactive.db.SortParameter) Test(org.junit.Test)

Example 2 with SortParameter

use of org.ow2.proactive.db.SortParameter in project scheduling by ow2-proactive.

the class SchedulerStateRest method createJobSortParams.

private static List<SortParameter<JobSortParameter>> createJobSortParams(String sortString) {
    String[] sortParams = sortString.split(",");
    List<SortParameter<JobSortParameter>> jobSortParamsList = new ArrayList<>(sortParams.length);
    for (String param : sortParams) {
        SortOrder order;
        if (param.endsWith(ASC_SUFFIX)) {
            order = SortOrder.ASC;
            param = param.substring(0, param.length() - ASC_SUFFIX.length());
        } else if (param.endsWith(DESC_SUFFIX)) {
            order = SortOrder.DESC;
            param = param.substring(0, param.length() - DESC_SUFFIX.length());
        } else {
            throw new IllegalArgumentException("Invalid sort order in " + sortString);
        }
        JobSortParameter jobSortParameter = JobSortParameter.valueOf(param);
        jobSortParamsList.add(new SortParameter<>(jobSortParameter, order));
    }
    return jobSortParamsList;
}
Also used : SortOrder(org.ow2.proactive.db.SortOrder) SortParameter(org.ow2.proactive.db.SortParameter)

Example 3 with SortParameter

use of org.ow2.proactive.db.SortParameter 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 SortParameter

use of org.ow2.proactive.db.SortParameter in project scheduling by ow2-proactive.

the class TestLoadJobsPagination method testSorting.

@Test
public void testSorting() throws Exception {
    // 1
    InternalJob job1 = defaultSubmitJob(createJob("A", JobPriority.IDLE), "user_a");
    // 2
    defaultSubmitJob(createJob("B", JobPriority.LOWEST), "user_b");
    // 3
    InternalJob job3 = defaultSubmitJob(createJob("C", JobPriority.LOW), "user_c");
    // 4
    defaultSubmitJob(createJob("A", JobPriority.NORMAL), "user_d");
    // 5
    InternalJob job5 = defaultSubmitJob(createJob("B", JobPriority.HIGH), "user_e");
    // 6
    defaultSubmitJob(createJob("C", JobPriority.HIGHEST), "user_f");
    // change status for some jobs
    job1.failed(null, JobStatus.KILLED);
    dbManager.updateAfterJobKilled(job1, Collections.<TaskId>emptySet());
    job3.setPaused();
    dbManager.updateJobAndTasksState(job3);
    job5.start();
    InternalTask taskJob5 = startTask(job5, job5.getITasks().get(0));
    dbManager.jobTaskStarted(job5, taskJob5, true);
    List<JobInfo> jobs;
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.ID, SortOrder.DESC))).getList();
    checkJobs(jobs, 6, 5, 4, 3, 2, 1);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.NAME, SortOrder.ASC), new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 4, 2, 5, 3, 6);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.NAME, SortOrder.ASC), new SortParameter<>(JobSortParameter.ID, SortOrder.DESC))).getList();
    checkJobs(jobs, 4, 1, 5, 2, 6, 3);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.OWNER, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.OWNER, SortOrder.DESC))).getList();
    checkJobs(jobs, 6, 5, 4, 3, 2, 1);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.PRIORITY, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.PRIORITY, SortOrder.DESC))).getList();
    checkJobs(jobs, 6, 5, 4, 3, 2, 1);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.STATE, SortOrder.ASC), new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    checkJobs(jobs, 2, 4, 6, 3, 5, 1);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, null, sortParameters(new SortParameter<>(JobSortParameter.STATE, SortOrder.DESC), new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 3, 5, 2, 4, 6);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) JobSortParameter(org.ow2.proactive.scheduler.common.JobSortParameter) SortParameter(org.ow2.proactive.db.SortParameter) Test(org.junit.Test)

Example 5 with SortParameter

use of org.ow2.proactive.db.SortParameter 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)

Aggregations

JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)7 SortParameter (org.ow2.proactive.db.SortParameter)5 Test (org.junit.Test)4 JobSortParameter (org.ow2.proactive.scheduler.common.JobSortParameter)4 ArrayList (java.util.ArrayList)3 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)3 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)3 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)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 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Criteria (org.hibernate.Criteria)1 Order (org.hibernate.criterion.Order)1 ImmediateService (org.objectweb.proactive.annotation.ImmediateService)1 SortOrder (org.ow2.proactive.db.SortOrder)1 JobFilterCriteria (org.ow2.proactive.scheduler.common.JobFilterCriteria)1