Search in sources :

Example 6 with ChangedTasksInfo

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

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

Example 8 with ChangedTasksInfo

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

the class SchedulerDBManagerTest method terminateJob.

private void terminateJob(int jobIndex, long finishedTime) throws Throwable {
    InternalJob finishedJob = actualInternalJobs.get(jobIndex);
    finishedJob.start();
    finishedJob.terminate();
    for (InternalTask task : finishedJob.getITasks()) {
        TaskResultImpl result = new TaskResultImpl(task.getId(), "ok", null, 0);
        FlowAction action = new FlowAction(FlowActionType.CONTINUE);
        ChangedTasksInfo changesInfo = finishedJob.terminateTask(false, task.getId(), null, action, result);
        task.setFinishedTime(finishedTime);
        dbManager.updateAfterWorkflowTaskFinished(finishedJob, changesInfo, result);
    }
}
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)

Example 9 with ChangedTasksInfo

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

the class JobInfoImpl method setTasksChanges.

public void setTasksChanges(ChangedTasksInfo changesInfo, JobState job) {
    this.modifiedTasks = new ArrayList<>(changesInfo.getNewTasks().size() + changesInfo.getUpdatedTasks().size());
    for (TaskId id : changesInfo.getNewTasks()) {
        modifiedTasks.add(new ClientTaskState(job.getHMTasks().get(id)));
    }
    for (TaskId id : changesInfo.getUpdatedTasks()) {
        modifiedTasks.add(new ClientTaskState(job.getHMTasks().get(id)));
    }
    this.tasksSkipped = new HashSet<>(changesInfo.getSkippedTasks());
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ClientTaskState(org.ow2.proactive.scheduler.task.ClientTaskState)

Example 10 with ChangedTasksInfo

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

the class TerminateIfTaskHandler method terminateIfTask.

public boolean terminateIfTask(FlowAction action, InternalTask initiator, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend, InternalTask descriptor, TaskId taskId) {
    InternalTask[] targets = searchIfElseJoinTasks(action, initiator);
    // the targetIf from action getTarget is the selected branch
    // the IF condition has already been evaluated prior to being put in a
    // FlowAction
    // the targetElse from action getTargetElse is the branch that was NOT
    // selected
    InternalTask targetIf = targets[0];
    InternalTask targetElse = targets[1];
    InternalTask targetJoin = targets[2];
    LOGGER.info("Control Flow Action IF: " + targetIf.getId() + " join: " + ((targetJoin == null) ? "null" : targetJoin.getId()));
    // these 2 tasks delimit the Task Block formed by the IF branch
    InternalTask branchStart = targetIf;
    InternalTask branchEnd = null;
    String match = targetIf.getMatchingBlock();
    if (match != null) {
        for (InternalTask t : internalJob.getIHMTasks().values()) {
            if (match.equals(t.getName()) && !(t.getStatus().equals(TaskStatus.FINISHED) || t.getStatus().equals(TaskStatus.SKIPPED))) {
                branchEnd = t;
            }
        }
    }
    // no matching block: there is no block, the branch is a single task
    if (branchEnd == null) {
        branchEnd = targetIf;
    }
    // plug the branch
    branchStart.addDependence(initiator);
    changesInfo.taskUpdated(branchStart);
    if (targetJoin != null) {
        targetJoin.addDependence(branchEnd);
        changesInfo.taskUpdated(targetJoin);
    }
    // the other branch will not be executed
    // first, find the concerned tasks
    List<InternalTask> elseTasks = new ArrayList<>();
    // elseTasks.add(targetElse);
    for (InternalTask t : internalJob.getIHMTasks().values()) {
        if (t.dependsOn(targetElse)) {
            elseTasks.add(t);
        }
    }
    // even though the targetElse is not going to be executed, a
    // dependency on initiator still makes sense and would help
    // reconstruct the job graph on the client
    targetElse.addDependence(initiator);
    changesInfo.taskUpdated(targetElse);
    for (InternalTask it : elseTasks) {
        it.setFinishedTime(descriptor.getFinishedTime() + 1);
        it.setStatus(TaskStatus.SKIPPED);
        it.setExecutionDuration(0);
        changesInfo.taskSkipped(it);
        internalJob.setNumberOfPendingTasks(internalJob.getNumberOfPendingTasks() - 1);
        internalJob.setNumberOfFinishedTasks(internalJob.getNumberOfFinishedTasks() + 1);
        LOGGER.info("Task " + it.getId() + " will not be executed");
    }
    // plug the branch in the descriptor
    TaskId joinId = null;
    if (targetJoin != null) {
        joinId = targetJoin.getId();
    }
    internalJob.getJobDescriptor().doIf(initiator.getId(), branchStart.getId(), branchEnd.getId(), joinId, targetElse.getId(), elseTasks);
    ((JobInfoImpl) internalJob.getJobInfo()).setTasksChanges(changesInfo, internalJob);
    // notify frontend that tasks were modified
    if (frontend != null) {
        frontend.jobStateUpdated(internalJob.getOwner(), new NotificationData<>(SchedulerEvent.TASK_SKIPPED, internalJob.getJobInfo()));
        frontend.jobUpdatedFullData(internalJob);
    }
    ((JobInfoImpl) internalJob.getJobInfo()).clearTasksChanges();
    // no jump is performed ; now that the tasks have been plugged
    // the flow can continue its normal operation
    internalJob.getJobDescriptor().terminate(taskId);
    return true;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Aggregations

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)10 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)7 ChangedTasksInfo (org.ow2.proactive.scheduler.job.ChangedTasksInfo)6 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)6 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 FlowAction (org.ow2.proactive.scheduler.common.task.flow.FlowAction)4 JobInfoImpl (org.ow2.proactive.scheduler.job.JobInfoImpl)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)3 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)3 HashMap (java.util.HashMap)2 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)2 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)2 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)2 InvalidPatternException (it.sauronsoftware.cron4j.InvalidPatternException)1 Predictor (it.sauronsoftware.cron4j.Predictor)1 Date (java.util.Date)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutableCreationException (org.ow2.proactive.scheduler.common.exception.ExecutableCreationException)1