Search in sources :

Example 6 with FlowAction

use of org.ow2.proactive.scheduler.common.task.flow.FlowAction 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 7 with FlowAction

use of org.ow2.proactive.scheduler.common.task.flow.FlowAction 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.SUBMITTED), true).withPending(task("T1*1", TaskStatus.SUBMITTED), true).withPending(task("T2", TaskStatus.SUBMITTED), true).withPending(task("T3", TaskStatus.SUBMITTED), true).withPending(task("T2*1", TaskStatus.SUBMITTED), true).withPending(task("T3*1", TaskStatus.SUBMITTED), true).withPending(task("T4", TaskStatus.SUBMITTED), 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 8 with FlowAction

use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.

the class TagTest method execute.

private void execute(InternalTask task) {
    task.setExecuterInformation(executerInformationMock);
    job.startTask(task);
    FlowScript script = task.getFlowScript();
    FlowAction action = null;
    if (script != null) {
        action = task.getFlowScript().execute().getResult();
    }
    job.terminateTask(false, task.getId(), schedulerStateUpdateMock, action, resultMock);
    System.out.println("executed " + task.getName() + " -> " + getTaskNameList(true));
}
Also used : FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript)

Example 9 with FlowAction

use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.

the class InternalJob method replicateForNextLoopIteration.

public boolean replicateForNextLoopIteration(InternalTask initiator, InternalTask target, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend, FlowAction action) {
    LOGGER.info("LOOP (init:" + initiator.getId() + "; target:" + target.getId() + ")");
    // accumulates the tasks between the initiator and the target
    Map<TaskId, InternalTask> dup = new HashMap<>();
    // replicate the tasks between the initiator and the target
    try {
        initiator.replicateTree(dup, target.getId(), true, initiator.getReplicationIndex(), initiator.getIterationIndex());
    } catch (ExecutableCreationException e) {
        LOGGER.error("", e);
        return false;
    }
    ((JobInfoImpl) this.getJobInfo()).setNumberOfPendingTasks(this.getJobInfo().getNumberOfPendingTasks() + dup.size());
    // time-consuming but safe
    for (InternalTask nt : dup.values()) {
        boolean ok;
        do {
            ok = true;
            for (InternalTask task : tasks.values()) {
                if (nt.getName().equals(task.getName())) {
                    nt.setIterationIndex(nt.getIterationIndex() + 1);
                    ok = false;
                }
            }
        } while (!ok);
    }
    // configure the new tasks
    InternalTask newTarget = null;
    InternalTask newInit = null;
    for (Entry<TaskId, InternalTask> it : dup.entrySet()) {
        InternalTask nt = it.getValue();
        if (target.getId().equals(it.getKey())) {
            newTarget = nt;
        }
        if (initiator.getId().equals(it.getKey())) {
            newInit = nt;
        }
        nt.setJobInfo(getJobInfo());
        this.addTask(nt);
        assignReplicationTag(nt, initiator, true, action);
    }
    changesInfo.newTasksAdded(dup.values());
    // connect replicated tree
    newTarget.addDependence(initiator);
    changesInfo.taskUpdated(newTarget);
    // connect mergers
    List<InternalTask> mergers = new ArrayList<>();
    for (InternalTask t : this.tasks.values()) {
        if (t.getIDependences() != null) {
            for (InternalTask p : t.getIDependences()) {
                if (p.getId().equals(initiator.getId())) {
                    if (!t.equals(newTarget)) {
                        mergers.add(t);
                    }
                }
            }
        }
    }
    for (InternalTask t : mergers) {
        t.getIDependences().remove(initiator);
        t.addDependence(newInit);
        changesInfo.taskUpdated(t);
    }
    // propagate the changes in the job descriptor
    getJobDescriptor().doLoop(initiator.getId(), dup, newTarget, newInit);
    this.jobInfo.setTasksChanges(changesInfo, this);
    // notify frontend that tasks were added and modified
    frontend.jobStateUpdated(this.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.TASK_REPLICATED, new JobInfoImpl(jobInfo)));
    frontend.jobUpdatedFullData(this);
    this.jobInfo.clearTasksChanges();
    return true;
}
Also used : ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ArrayList(java.util.ArrayList)

Example 10 with FlowAction

use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.

the class TerminateLoopHandler method terminateLoopTask.

public boolean terminateLoopTask(FlowAction action, InternalTask initiator, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend) {
    // find the target of the loop
    InternalTask target = null;
    if (action.getTarget().equals(initiator.getName())) {
        target = initiator;
    } else {
        target = internalJob.findTask(action.getTarget());
    }
    boolean replicateForNextLoopIteration = internalJob.replicateForNextLoopIteration(initiator, target, changesInfo, frontend, action);
    if (replicateForNextLoopIteration && action.getCronExpr() != null) {
        for (TaskId tid : changesInfo.getNewTasks()) {
            InternalTask newTask = internalJob.getIHMTasks().get(tid);
            try {
                Date startAt = (new Predictor(action.getCronExpr())).nextMatchingDate();
                newTask.addGenericInformation(InternalJob.GENERIC_INFO_START_AT_KEY, ISO8601DateUtil.parse(startAt));
                newTask.setScheduledTime(startAt.getTime());
            } catch (InvalidPatternException e) {
                // this will not happen as the cron expression is
                // already being validated in FlowScript class.
                LOGGER.debug(e.getMessage());
            }
        }
    }
    return replicateForNextLoopIteration;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InvalidPatternException(it.sauronsoftware.cron4j.InvalidPatternException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Predictor(it.sauronsoftware.cron4j.Predictor) Date(java.util.Date)

Aggregations

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