Search in sources :

Example 56 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.

the class TestJobRemove method testRuntimeDataRemoveAfterFinishParallel.

@Test
public void testRuntimeDataRemoveAfterFinishParallel() throws Throwable {
    int THREAD_COUNT = 4;
    ExecutorService executorService = Executors.newCachedThreadPool();
    List<InternalJob> jobs = new ArrayList<>(THREAD_COUNT);
    TaskFlowJob jobDef;
    for (int i = 0; i < THREAD_COUNT; i++) {
        jobDef = createJob(2);
        jobs.add(defaultSubmitJobAndLoadInternal(false, jobDef));
    }
    for (int i = 0; i < THREAD_COUNT; i++) {
        final InternalJob job = jobs.get(i);
        executorService.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    dbManager.updateAfterTaskFinished(job, job.getTask("javaTask-0"), new TaskResultImpl(null, "OK1", null, 0));
                    dbManager.updateAfterTaskFinished(job, job.getTask("forkedJavaTask-0"), new TaskResultImpl(null, "OK2", null, 0));
                    dbManager.updateAfterTaskFinished(job, job.getTask("nativeTask-0"), new TaskResultImpl(null, "OK3", null, 0));
                    job.setStatus(JobStatus.FINISHED);
                    dbManager.updateAfterTaskFinished(job, null, null);
                } catch (Throwable throwable) {
                    throwable.printStackTrace();
                }
            }
        });
    }
    executorService.shutdown();
    executorService.awaitTermination(30, TimeUnit.SECONDS);
    for (int i = 0; i < THREAD_COUNT; i++) {
        final InternalJob job = jobs.get(i);
        List<InternalJob> jobsNotFinished = dbManager.loadNotFinishedJobs(true);
        Assert.assertEquals("All jobs should be finished", 0, jobsNotFinished.size());
        checkAllEntitiesDeleted(JobData.class.getName(), JobContent.class.getName(), TaskData.class.getName(), TaskResultData.class.getName());
        // check can still load task results
        Assert.assertEquals("OK1", dbManager.loadTaskResult(job.getTask("javaTask-0").getId(), 0).value());
        Assert.assertEquals("OK2", dbManager.loadTaskResult(job.getTask("forkedJavaTask-0").getId(), 0).value());
        Assert.assertEquals("OK3", dbManager.loadTaskResult(job.getTask("nativeTask-0").getId(), 0).value());
    }
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) ArrayList(java.util.ArrayList) TaskResultData(org.ow2.proactive.scheduler.core.db.TaskResultData) TaskData(org.ow2.proactive.scheduler.core.db.TaskData) JobContent(org.ow2.proactive.scheduler.core.db.JobContent) ExecutorService(java.util.concurrent.ExecutorService) JobData(org.ow2.proactive.scheduler.core.db.JobData) Test(org.junit.Test)

Example 57 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.

the class TestJobRuntimeData method testJobRuntimeData.

@Test
public void testJobRuntimeData() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    job.addTask(createDefaultTask("task1"));
    job.setPriority(JobPriority.LOW);
    System.out.println("Submit and load job");
    InternalJob runtimeData = defaultSubmitJobAndLoadInternal(true, job);
    Assert.assertEquals(JobStatus.PENDING, runtimeData.getStatus());
    Assert.assertEquals(DEFAULT_USER_NAME, runtimeData.getOwner());
    Assert.assertEquals(JobPriority.LOW, runtimeData.getPriority());
    Assert.assertEquals(0, runtimeData.getNumberOfPendingTasks());
    Assert.assertEquals(1, runtimeData.getTotalNumberOfTasks());
    Assert.assertEquals(0, runtimeData.getNumberOfFinishedTasks());
    Assert.assertEquals(0, runtimeData.getNumberOfRunningTasks());
    Assert.assertEquals(this.getClass().getSimpleName(), runtimeData.getName());
    Assert.assertNotNull(runtimeData.getCredentials());
    Assert.assertEquals(1, runtimeData.getITasks().size());
    runtimeData.start();
    InternalTask internalTask = startTask(runtimeData, runtimeData.getITasks().get(0));
    System.out.println("Update started task data");
    dbManager.jobTaskStarted(runtimeData, internalTask, false);
    System.out.println("Load internal job");
    runtimeData = loadInternalJob(true, runtimeData.getId());
    Assert.assertEquals(this.getClass().getSimpleName(), runtimeData.getJobInfo().getJobId().getReadableName());
    Assert.assertEquals(JobStatus.RUNNING, runtimeData.getStatus());
    Assert.assertEquals(1, runtimeData.getNumberOfRunningTasks());
    Assert.assertEquals(0, runtimeData.getNumberOfFinishedTasks());
    Assert.assertEquals(0, runtimeData.getNumberOfPendingTasks());
    Assert.assertTrue(runtimeData.getStartTime() > 0);
    internalTask = runtimeData.getITasks().get(0);
    Assert.assertEquals(TaskStatus.RUNNING, internalTask.getStatus());
    Assert.assertTrue(internalTask.getStartTime() > 0);
    Assert.assertNotNull(internalTask.getExecutionHostName());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Test(org.junit.Test)

Example 58 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.

the class TestLoadJobResult method testEmptyResult.

@Test
public void testEmptyResult() throws Throwable {
    TaskFlowJob jobDef = new TaskFlowJob();
    jobDef.addTask(createDefaultTask("task1"));
    InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
    InternalTask task1 = job.getTask("task1");
    JobResult result;
    result = dbManager.loadJobResult(job.getId());
    Assert.assertNotNull(result.getJobInfo());
    Assert.assertEquals(0, result.getAllResults().size());
    Assert.assertEquals(1, result.getJobInfo().getTotalNumberOfTasks());
    dbManager.updateAfterTaskFinished(job, task1, new TaskResultImpl(null, new TestResult(0, "1_1"), null, 0));
    result = dbManager.loadJobResult(job.getId());
    Assert.assertNotNull(result.getJobInfo());
    Assert.assertEquals(1, result.getAllResults().size());
    Assert.assertEquals(1, result.getJobInfo().getTotalNumberOfTasks());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Test(org.junit.Test)

Example 59 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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 60 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob 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)

Aggregations

InternalJob (org.ow2.proactive.scheduler.job.InternalJob)166 Test (org.junit.Test)115 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)90 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)53 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)36 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)34 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)33 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)32 JobId (org.ow2.proactive.scheduler.common.job.JobId)28 ArrayList (java.util.ArrayList)27 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)26 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)19 RecoveredSchedulerState (org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState)19 Matchers.containsString (org.hamcrest.Matchers.containsString)16 Matchers.anyString (org.mockito.Matchers.anyString)16 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)15 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)13 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)12 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)12 HashMap (java.util.HashMap)10