Search in sources :

Example 41 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask 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 42 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestReportingQueries method finishTask.

private long finishTask(InternalJob job, String taskName) throws Exception {
    Thread.sleep(100);
    InternalTask task = job.getTask(taskName);
    TaskResultImpl res = new TaskResultImpl(null, "ok", null, 0);
    job.terminateTask(false, task.getId(), null, null, res);
    if (job.isFinished()) {
        job.terminate();
    }
    dbManager.updateAfterTaskFinished(job, task, res);
    return task.getFinishedTime() - task.getStartTime();
}
Also used : TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Example 43 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestReportingQueries method checkMeanTaskPendingTime.

private void checkMeanTaskPendingTime(InternalJob job) {
    job = loadInternalJob(true, job.getId());
    double expected = 0;
    int counter = 0;
    for (InternalTask task : job.getITasks()) {
        if (task.getStartTime() > 0) {
            expected += task.getStartTime() - job.getSubmittedTime();
            counter++;
        }
    }
    if (counter == 0) {
        expected = 0;
    } else {
        expected /= counter;
    }
    Assert.assertEquals(expected, dbManager.getMeanTaskPendingTime(job.getJobInfo().getJobId().value()), 001);
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Example 44 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestRestoreWorkflowJobs method test.

@Test
public void test() throws Exception {
    TaskFlowJob jobDef = createJob();
    InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
    job.start();
    InternalTask mainTask = job.getTask("T");
    startTask(job, mainTask);
    dbManager.jobTaskStarted(job, mainTask, true);
    TaskResultImpl result = new TaskResultImpl(mainTask.getId(), "ok", null, 0);
    FlowAction action = new FlowAction(FlowActionType.REPLICATE);
    action.setDupNumber(2);
    ChangedTasksInfo changesInfo = job.terminateTask(false, mainTask.getId(), null, action, result);
    dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
    SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
    JobStateMatcher expectedJob;
    expectedJob = job(job.getId(), JobStatus.STALLED).withFinished(task("T", TaskStatus.FINISHED).checkFinished(), true).withPending(task("T1", TaskStatus.PENDING), true).withPending(task("T1*1", TaskStatus.SUBMITTED), true).withPending(task("T2", TaskStatus.PENDING), true).withPending(task("T3", TaskStatus.PENDING), true).withPending(task("T2*1", TaskStatus.SUBMITTED), true).withPending(task("T3*1", TaskStatus.SUBMITTED), true).withPending(task("T4", TaskStatus.PENDING), true).withEligible("T1", "T1*1");
    checkRecoveredState(recoverHelper.recover(-1), state().withRunning(expectedJob));
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) ChangedTasksInfo(org.ow2.proactive.scheduler.job.ChangedTasksInfo) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) Test(org.junit.Test)

Example 45 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestRestoreWorkflowJobs2 method test.

@Test
public void test() throws Exception {
    TaskFlowJob jobDef = createJob();
    InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
    job.start();
    InternalTask mainTask = job.getTask("A");
    startTask(job, mainTask);
    dbManager.jobTaskStarted(job, mainTask, true);
    TaskResultImpl result = new TaskResultImpl(mainTask.getId(), "ok", null, 0);
    FlowAction action = new FlowAction(FlowActionType.IF);
    action.setDupNumber(1);
    action.setTarget("B");
    action.setTargetElse("C");
    ChangedTasksInfo changesInfo = job.terminateTask(false, mainTask.getId(), null, action, result);
    dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
    SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
    RecoveredSchedulerState state = recoverHelper.recover(-1);
    job = state.getRunningJobs().get(0);
    System.out.println("OK");
}
Also used : RecoveredSchedulerState(org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) ChangedTasksInfo(org.ow2.proactive.scheduler.job.ChangedTasksInfo) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) Test(org.junit.Test)

Aggregations

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)142 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)74 Test (org.junit.Test)72 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)39 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)37 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)32 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)31 ArrayList (java.util.ArrayList)30 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 JobId (org.ow2.proactive.scheduler.common.job.JobId)22 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)18 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)16 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)13 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)12 HashMap (java.util.HashMap)10 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)10 ProActiveTest (org.ow2.tests.ProActiveTest)10 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)9 HashSet (java.util.HashSet)8 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)8