Search in sources :

Example 6 with SortParameter

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

the class SchedulerClientTest method testGetJobs.

@Test(timeout = MAX_WAIT_TIME)
public void testGetJobs() throws Throwable {
    ISchedulerClient client = clientInstance();
    // Define jobs
    Job job1 = defaultJob();
    Job job2 = defaultJob();
    Job job3 = defaultJob();
    Job job4 = pendingJob();
    // Set job names
    job1.setName("myJobA");
    job2.setName("myJobB");
    job3.setName("myJobB");
    job4.setName("myJobC");
    // Set project names
    job1.setProjectName("myProjectA");
    job2.setProjectName("myProjectA");
    job3.setProjectName("myProjectB");
    job4.setProjectName("myProjectB");
    // Remove all existing jobs
    Assert.assertTrue(removeAllJobs(client));
    // Submit job2 job3 job4
    JobId job1Id = submitJob(job1, client);
    JobId job2Id = submitJob(job2, client);
    JobId job3Id = submitJob(job3, client);
    JobId job4Id = submitJob(job4, client);
    // Wait for job1, job2 and job3 to finish
    JobResult job1Result = client.waitForJob(job1Id, TimeUnit.MINUTES.toMillis(3));
    JobResult job2Result = client.waitForJob(job2Id, TimeUnit.MINUTES.toMillis(3));
    JobResult job3Result = client.waitForJob(job3Id, TimeUnit.MINUTES.toMillis(3));
    Assert.assertEquals(JobStatus.FINISHED, job1Result.getJobInfo().getStatus());
    Assert.assertEquals(JobStatus.FINISHED, job2Result.getJobInfo().getStatus());
    Assert.assertEquals(JobStatus.FINISHED, job3Result.getJobInfo().getStatus());
    // Test sorts
    JobFilterCriteria allJobsCriteria = new JobFilterCriteria(false, true, true, true, true, "", "", "", new Long(-1));
    SortParameter jobNameDescOrder = new SortParameter<>(JobSortParameter.NAME, SortOrder.DESC);
    SortParameter jobIdAscOrder = new SortParameter<>(JobSortParameter.ID, SortOrder.ASC);
    List<SortParameter<JobSortParameter>> sortParameterList1 = new ArrayList<>();
    sortParameterList1.add(jobNameDescOrder);
    sortParameterList1.add(jobIdAscOrder);
    List<JobInfo> jobsList1 = client.getJobs(0, 4, allJobsCriteria, sortParameterList1).getList();
    Assert.assertEquals(jobsList1.get(0).getJobId().value(), job4Id.value());
    Assert.assertEquals(jobsList1.get(1).getJobId().value(), job2Id.value());
    Assert.assertEquals(jobsList1.get(2).getJobId().value(), job3Id.value());
    Assert.assertEquals(jobsList1.get(3).getJobId().value(), job1Id.value());
    // Test range and limit
    List<JobInfo> jobsList2 = client.getJobs(2, 2, allJobsCriteria, Collections.singletonList(jobIdAscOrder)).getList();
    Assert.assertEquals(jobsList2.get(0).getJobId().value(), job3Id.value());
    Assert.assertEquals(jobsList2.get(1).getJobId().value(), job4Id.value());
    // Test filters
    JobFilterCriteria allJobsFinishedInMyProjectBCriteria = new JobFilterCriteria(false, false, false, true, false, "", "myProjectB", "", new Long(-1));
    List<JobInfo> jobsList3 = client.getJobs(0, 4, allJobsFinishedInMyProjectBCriteria, Collections.singletonList(jobIdAscOrder)).getList();
    Assert.assertEquals(jobsList3.size(), 1);
    Assert.assertEquals(jobsList3.get(0).getJobId().value(), job3Id.value());
    client.killJob(job4Id);
    // Remove all existing jobs
    Assert.assertTrue(removeAllJobs(client));
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ISchedulerClient(org.ow2.proactive.scheduler.rest.ISchedulerClient) SortParameter(org.ow2.proactive.db.SortParameter) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleJob(functionaltests.jobs.SimpleJob) Job(org.ow2.proactive.scheduler.common.job.Job) NonTerminatingJob(functionaltests.jobs.NonTerminatingJob) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 7 with SortParameter

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

the class TestLoadJobsPagination method testPagingAndFiltering.

@Test
public void testPagingAndFiltering() throws Exception {
    InternalJob job;
    InternalTask task;
    String projectName = "project1";
    String jobName = "job1";
    // pending job with projectName - 1
    defaultSubmitJob(createJob(null, null, projectName, null));
    // job for user1 with jobName - 2
    defaultSubmitJob(createJob(jobName, null, null, 1L), "user1");
    // running job - 3
    job = defaultSubmitJob(createJob(null, null, projectName, 1L));
    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(), true);
    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, true, null, null, null, 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, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
    Assert.assertEquals(2, jobs.get(0).getChildrenCount());
    jobs = dbManager.getJobs(-1, -1, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(-1, 5, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5);
    jobs = dbManager.getJobs(2, -1, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(0, 0, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(0, 1, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1);
    jobs = dbManager.getJobs(0, 3, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3);
    jobs = dbManager.getJobs(1, 10, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(5, 10, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 6, 7);
    jobs = dbManager.getJobs(6, 10, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 7);
    jobs = dbManager.getJobs(7, 10, null, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1, 3, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, "user1", true, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 2);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, false, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, false, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 3);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 3, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, true, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, false, true, null, null, null, sortParameters).getList();
    checkJobs(jobs, 1, 3);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, false, true, null, null, null, sortParameters).getList();
    checkJobs(jobs);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, jobName, null, null, sortParameters).getList();
    checkJobs(jobs, 2);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, projectName, null, sortParameters).getList();
    checkJobs(jobs, 1, 3);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, null, 1L, sortParameters).getList();
    checkJobs(jobs, 2, 3);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, jobName, null, 1L, sortParameters).getList();
    checkJobs(jobs, 2);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, true, null, projectName, 1L, sortParameters).getList();
    checkJobs(jobs, 3);
}
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 8 with SortParameter

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

the class SchedulerTHelper method cleanJobs.

public void cleanJobs() throws Exception {
    Scheduler userInt = getSchedulerInterface();
    JobFilterCriteria criteria = new JobFilterCriteria(false, true, true, true, true, null, null, null, null);
    List<JobInfo> jobs = userInt.getJobs(0, 1000, criteria, ImmutableList.of(new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    for (JobInfo job : jobs) {
        userInt.removeJob(job.getJobId());
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) Scheduler(org.ow2.proactive.scheduler.common.Scheduler)

Example 9 with SortParameter

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

the class SchedulerDBManager method getJobs.

public Page<JobInfo> getJobs(final int offset, final int limit, final String user, final boolean pending, final boolean running, final boolean finished, final boolean childJobs, String jobName, String projectName, Long parentId, final List<SortParameter<JobSortParameter>> sortParameters) {
    if (!pending && !running && !finished) {
        return new Page<>(new ArrayList<JobInfo>(0), 0);
    }
    DBJobDataParameters params = new DBJobDataParameters(offset, limit, user, pending, running, finished, childJobs, jobName, projectName, parentId, sortParameters);
    int totalNbJobs = getTotalNumberOfJobs(params);
    final Set<JobStatus> jobStatuses = params.getStatuses();
    List<JobInfo> lJobs = executeReadOnlyTransaction(session -> {
        Criteria criteria = session.createCriteria(JobData.class);
        if (limit > 0) {
            criteria.setMaxResults(limit);
        }
        if (offset >= 0) {
            criteria.setFirstResult(offset);
        }
        if (user != null && !user.isEmpty()) {
            criteria.add(Restrictions.eq("owner", user));
        }
        if (!childJobs) {
            criteria.add(Restrictions.isNull("parentId"));
        }
        if (jobName != null && !jobName.isEmpty()) {
            criteria.add(Restrictions.like("jobName", jobName, MatchMode.START));
        }
        if (projectName != null && !projectName.isEmpty()) {
            criteria.add(Restrictions.like("projectName", projectName, MatchMode.START));
        }
        if (childJobs && parentId != null && parentId > 0L) {
            criteria.add(Restrictions.eq("parentId", parentId));
        }
        boolean allJobs = pending && running && finished;
        if (!allJobs) {
            criteria.add(Restrictions.in("status", jobStatuses));
        }
        if (sortParameters != null) {
            Order sortOrder;
            for (SortParameter<JobSortParameter> param : sortParameters) {
                switch(param.getParameter()) {
                    case ID:
                        sortOrder = configureSortOrder(param, Property.forName("id"));
                        break;
                    case NAME:
                        sortOrder = configureSortOrder(param, Property.forName("jobName"));
                        break;
                    case OWNER:
                        sortOrder = configureSortOrder(param, Property.forName("owner"));
                        break;
                    case PRIORITY:
                        sortOrder = configureSortOrder(param, Property.forName("priority"));
                        break;
                    case STATE:
                        sortOrder = new GroupByStatusSortOrder(param.getSortOrder(), "status");
                        break;
                    case SUBMIT_TIME:
                        sortOrder = configureSortOrder(param, Property.forName("submittedTime"));
                        break;
                    case START_TIME:
                        sortOrder = configureSortOrder(param, Property.forName("startTime"));
                        break;
                    case FINISH_TIME:
                        sortOrder = configureSortOrder(param, Property.forName("finishedTime"));
                        break;
                    case IN_ERROR_TIME:
                        sortOrder = configureSortOrder(param, Property.forName("finishedTime"));
                        break;
                    case TOTAL_TASKS:
                        sortOrder = configureSortOrder(param, Property.forName("totalNumberOfTasks"));
                        break;
                    case PENDING_TASKS:
                        sortOrder = configureSortOrder(param, Property.forName("numberOfPendingTasks"));
                        break;
                    case RUNNING_TASKS:
                        sortOrder = configureSortOrder(param, Property.forName("numberOfRunningTasks"));
                        break;
                    case IN_ERROR_TASKS:
                        sortOrder = configureSortOrder(param, Property.forName("numberOfInErrorTasks"));
                        break;
                    case FINISHED_TASKS:
                        sortOrder = configureSortOrder(param, Property.forName("numberOfFinishedTasks"));
                        break;
                    case FAULTY_TASKS:
                        sortOrder = configureSortOrder(param, Property.forName("numberOfFaultyTasks"));
                        break;
                    case FAILED_TASKS:
                        sortOrder = configureSortOrder(param, Property.forName("numberOfFailedTasks"));
                        break;
                    default:
                        throw new IllegalArgumentException("Unsupported sort parameter: " + param.getParameter());
                }
                criteria.addOrder(sortOrder);
            }
        }
        List<JobData> jobsList = criteria.list();
        return jobsList.stream().map(JobData::toJobInfo).collect(Collectors.toList());
    });
    return new Page<>(lJobs, totalNbJobs);
}
Also used : Order(org.hibernate.criterion.Order) Page(org.ow2.proactive.scheduler.common.Page) Criteria(org.hibernate.Criteria) JobSortParameter(org.ow2.proactive.scheduler.common.JobSortParameter) JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo)

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