Search in sources :

Example 1 with SchedulerStateRecoverHelper

use of org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper in project scheduling by ow2-proactive.

the class SchedulerTasksStateRecoverIntegrationTest method testRecover.

@Test
public void testRecover() throws Exception {
    SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
    RecoveredSchedulerState state = recoverHelper.recover(-1);
    Assert.assertEquals(0, state.getFinishedJobs().size());
    Assert.assertEquals(0, state.getRunningJobs().size());
    Assert.assertEquals(0, state.getPendingJobs().size());
    TaskFlowJob job1 = new TaskFlowJob();
    JavaTask task1 = createDefaultTask("task1");
    JavaTask task2 = createDefaultTask("task2");
    JavaTask task3 = createDefaultTask("task3");
    task1.addDependence(task2);
    task1.addDependence(task3);
    task2.addDependence(task3);
    job1.addTask(task1);
    job1.addTask(task2);
    job1.addTask(task3);
    InternalJob job = defaultSubmitJob(job1);
    JobStateMatcher expectedJob;
    expectedJob = job(job.getId(), JobStatus.PENDING).withPending(task("task1", TaskStatus.SUBMITTED), false).withPending(task("task2", TaskStatus.SUBMITTED), false).withPending(task("task3", TaskStatus.SUBMITTED), false).withEligible("task3");
    state = checkRecoveredState(recoverHelper.recover(-1), state().withPending(expectedJob));
    job = state.getPendingJobs().get(0);
    TaskDescriptor task = job.getJobDescriptor().getEligibleTasks().iterator().next();
    Assert.assertEquals(2, task.getChildren().size());
    Assert.assertEquals(0, task.getParents().size());
    job.terminate();
    dbManager.updateAfterTaskFinished(job, null, null);
    expectedJob = job(job.getId(), JobStatus.FINISHED).withPending(task("task1", TaskStatus.SUBMITTED), false).withPending(task("task2", TaskStatus.SUBMITTED), false).withPending(task("task3", TaskStatus.SUBMITTED), false).withEligible("task3");
    state = checkRecoveredState(recoverHelper.recover(-1), state().withFinished(expectedJob));
    job = state.getFinishedJobs().get(0);
    Assert.assertEquals(3, job.getJobDescriptor().getEligibleTasks().size());
    task = job.getJobDescriptor().getEligibleTasks().iterator().next();
    // finished jobs tasks have no dependency information
    Assert.assertEquals(0, task.getChildren().size());
    Assert.assertEquals(0, task.getParents().size());
}
Also used : RecoveredSchedulerState(org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState) TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) Test(org.junit.Test)

Example 2 with SchedulerStateRecoverHelper

use of org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper in project scheduling by ow2-proactive.

the class SchedulerTasksStateRecoverIntegrationTest method testRecoverAfterRestart.

@Test
public void testRecoverAfterRestart() throws Exception {
    TaskFlowJob jobDef = new TaskFlowJob();
    jobDef.addTask(createDefaultTask("task1"));
    InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
    InternalTask task = job.getTask("task1");
    job.start();
    startTask(job, task);
    dbManager.jobTaskStarted(job, task, true);
    SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
    JobStateMatcher expectedJob;
    expectedJob = job(job.getId(), JobStatus.STALLED).withPending(task("task1", TaskStatus.SUBMITTED), true).withEligible("task1");
    RecoveredSchedulerState state;
    state = checkRecoveredState(recoverHelper.recover(-1), state().withRunning(expectedJob));
    job = state.getRunningJobs().get(0);
    task = job.getTask("task1");
    startTask(job, task);
    dbManager.jobTaskStarted(job, task, true);
    job.newWaitingTask();
    job.reStartTask(task);
    dbManager.taskRestarted(job, task, null);
    state = checkRecoveredState(recoverHelper.recover(-1), state().withRunning(expectedJob));
    // check it is possible to load ExecutableContainer for restored task
    job = state.getRunningJobs().get(0);
    ExecutableContainer container = dbManager.loadExecutableContainer(job.getTask("task1"));
    Assert.assertNotNull(container);
}
Also used : RecoveredSchedulerState(org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ExecutableContainer(org.ow2.proactive.scheduler.task.containers.ExecutableContainer) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) Test(org.junit.Test)

Example 3 with SchedulerStateRecoverHelper

use of org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper in project scheduling by ow2-proactive.

the class TestJobOperations method recoverJob.

private InternalJob recoverJob() {
    SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
    Collection<InternalJob> jobs = recoverHelper.recover(-1).getPendingJobs();
    Assert.assertEquals(1, jobs.size());
    return jobs.iterator().next();
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)

Example 4 with SchedulerStateRecoverHelper

use of org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper in project scheduling by ow2-proactive.

the class SchedulerStateRecoverHelperTest method testRecoverWithCopyAndSortThrowingRuntimeException.

@Test
public void testRecoverWithCopyAndSortThrowingRuntimeException() throws KeyException, JobCreationException {
    RecoveredSchedulerState recoveredState = new Scenario(createJob(JobStatus.RUNNING)).execute(new SchedulerStateRecoverHelperSupplier() {

        @Override
        public SchedulerStateRecoverHelper get(SchedulerDBManager dbManager) {
            return new SchedulerStateRecoverHelper(dbManager) {

                @Override
                protected List<InternalTask> copyAndSort(List<InternalTask> tasks) {
                    throw new RuntimeException("bouh!");
                }
            };
        }
    }, false);
    assertThat(recoveredState.getFinishedJobs()).hasSize(1);
    assertThat(recoveredState.getPendingJobs()).hasSize(0);
    assertThat(recoveredState.getRunningJobs()).hasSize(0);
    assertThat(recoveredState.getFinishedJobs().get(0).getStatus()).isEqualTo(JobStatus.CANCELED);
}
Also used : RecoveredSchedulerState(org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 5 with SchedulerStateRecoverHelper

use of org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper 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

SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)14 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)12 Test (org.junit.Test)11 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)9 RecoveredSchedulerState (org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState)8 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)8 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)3 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)2 JobState (org.ow2.proactive.scheduler.common.job.JobState)2 FlowAction (org.ow2.proactive.scheduler.common.task.flow.FlowAction)2 SchedulerDBManager (org.ow2.proactive.scheduler.core.db.SchedulerDBManager)2 ChangedTasksInfo (org.ow2.proactive.scheduler.job.ChangedTasksInfo)2 ImmutableList (com.google.common.collect.ImmutableList)1 KeyException (java.security.KeyException)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1