Search in sources :

Example 11 with FlowAction

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

the class JobDescriptorImpl method doLoop.

/**
 * Complete LOOP action on JobDescriptor side
 *
 * @param initiator Task initiating the LOOP action
 * @param tree InternalTask tree of replicated tasks
 * @param target Target task of the LOOP action
 */
public void doLoop(TaskId initiator, Map<TaskId, InternalTask> tree, InternalTask target, InternalTask newInit) {
    Map<TaskId, EligibleTaskDescriptorImpl> acc = new HashMap<>();
    // create new EligibleTasks and accumulate it
    for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
        TaskId itId = it.getValue().getId();
        EligibleTaskDescriptorImpl td = new EligibleTaskDescriptorImpl(it.getValue());
        acc.put(itId, td);
    }
    EligibleTaskDescriptorImpl oldEnd = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
    EligibleTaskDescriptorImpl newStart = acc.get(target.getId());
    EligibleTaskDescriptorImpl newEnd = acc.get(newInit.getId());
    // plug the end of the old tree (initiator) to the beginning of the new (target)
    for (TaskDescriptor ot : oldEnd.getChildren()) {
        newEnd.addChild(ot);
        ot.getParents().remove(oldEnd);
        ot.getParents().add(newEnd);
    }
    oldEnd.clearChildren();
    // recreate the dependencies
    for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
        TaskId itId = it.getValue().getTaskInfo().getTaskId();
        EligibleTaskDescriptorImpl down = acc.get(itId);
        List<InternalTask> ideps = new ArrayList<>();
        int deptype = 0;
        if (it.getValue().hasDependences()) {
            ideps.addAll(it.getValue().getIDependences());
        }
        if (it.getValue().getIfBranch() != null) {
            deptype = 1;
            ideps.add(it.getValue().getIfBranch());
        }
        if (it.getValue().getJoinedBranches() != null) {
            deptype = 2;
            ideps.addAll(it.getValue().getJoinedBranches());
        }
        if (ideps.size() > 0 && !target.equals(itId)) {
            for (InternalTask parent : ideps) {
                if (parent == null) {
                    continue;
                }
                EligibleTaskDescriptorImpl up = acc.get(parent.getTaskInfo().getTaskId());
                switch(deptype) {
                    case 0:
                        if (parent.getId().equals(initiator)) {
                            up = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
                        }
                        up.addChild(down);
                        down.addParent(up);
                        break;
                    case 1:
                    case 2:
                        // 'weak' dependencies from FlowAction#IF are not
                        // represented in TaskDescriptor
                        branchTasks.put(down.getTaskId(), down);
                        break;
                }
            }
        }
    }
    // EligibleTaskDescriptorImpl newTask = (EligibleTaskDescriptorImpl) acc.get(target.getId());
    setNewLoopTaskToPausedIfJobIsPaused(newStart);
    putNewLoopTaskIntoPausedOrEligableList(target.getId(), newStart);
    runningTasks.remove(initiator);
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList)

Example 12 with FlowAction

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

the class TaskResultData method createTaskResultData.

static TaskResultData createTaskResultData(TaskData taskRuntimeData, TaskResultImpl result) {
    TaskResultData resultData = new TaskResultData();
    resultData.setTaskRuntimeData(taskRuntimeData);
    resultData.setLogs(result.getOutput());
    resultData.setPreviewerClassName(result.getPreviewerClassName());
    resultData.setMetadata(result.getMetadata());
    resultData.setPropagatedVariables(result.getPropagatedVariables());
    resultData.setSerializedException(result.getSerializedException());
    resultData.setSerializedValue(result.getSerializedValue());
    resultData.setResultTime(System.currentTimeMillis());
    resultData.setRaw(result.isRaw());
    FlowAction flowAction = result.getAction();
    if (flowAction != null) {
        FlowActionData actionData = new FlowActionData();
        actionData.setDupNumber(flowAction.getDupNumber());
        actionData.setTarget(flowAction.getTarget());
        actionData.setTargetContinuation(flowAction.getTargetContinuation());
        actionData.setTargetElse(flowAction.getTargetElse());
        actionData.setType(flowAction.getType());
        resultData.setFlowAction(actionData);
    }
    return resultData;
}
Also used : FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction)

Example 13 with FlowAction

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

the class InternalJob method terminateTask.

/**
 * Terminate a task, change status, managing dependencies
 * <p>
 * Also, apply a Control Flow Action if provided. This may alter the number
 * of tasks in the job, events have to be sent accordingly.
 *
 * @param errorOccurred has an error occurred for this termination
 * @param taskId        the task to terminate.
 * @param frontend      Used to notify all listeners of the replication of tasks,
 *                      triggered by the FlowAction
 * @param action        a Control Flow Action that will potentially create new tasks
 *                      inside the job
 * @param result        result associated with the task
 * @param taskIsInError If the task is in in-error state
 * @return the taskDescriptor that has just been terminated.
 */
public ChangedTasksInfo terminateTask(boolean errorOccurred, TaskId taskId, SchedulerStateUpdate frontend, FlowAction action, TaskResultImpl result, boolean taskIsInError) {
    final InternalTask descriptor = tasks.get(taskId);
    if (!errorOccurred) {
        decreaseNumberOfFaultyTasks(taskId);
    }
    descriptor.setFinishedTime(System.currentTimeMillis());
    descriptor.setStatus(errorOccurred ? TaskStatus.FAULTY : TaskStatus.FINISHED);
    descriptor.setExecutionDuration(result.getTaskDuration());
    if (taskIsInError) {
        setNumberOfInErrorTasks(getNumberOfInErrorTasks() - 1);
    }
    setNumberOfRunningTasks(getNumberOfRunningTasks() - 1);
    setNumberOfFinishedTasks(getNumberOfFinishedTasks() + 1);
    if ((getStatus() == JobStatus.RUNNING) && (getNumberOfRunningTasks() == 0) && !taskIsInError) {
        setStatus(JobStatus.STALLED);
    }
    ChangedTasksInfo changesInfo = new ChangedTasksInfo();
    changesInfo.taskUpdated(descriptor);
    boolean didAction = false;
    if (action != null) {
        InternalTask initiator = tasks.get(taskId);
        switch(action.getType()) {
            /*
                 * LOOP action
                 */
            case LOOP:
                {
                    didAction = terminateLoopHandler.terminateLoopTask(action, initiator, changesInfo, frontend);
                    break;
                }
            /*
                 * IF action
                 */
            case IF:
                {
                    didAction = terminateIfTaskHandler.terminateIfTask(action, initiator, changesInfo, frontend, descriptor, taskId);
                    break;
                }
            /*
                 * REPLICATE action
                 */
            case REPLICATE:
                {
                    didAction = terminateReplicateTaskHandler.terminateReplicateTask(action, initiator, changesInfo, frontend, taskId);
                    break;
                }
            /*
                 * CONTINUE action : - continue taskflow as if no action was provided
                 */
            case CONTINUE:
                LOGGER.debug("Task flow Action CONTINUE on task " + initiator.getId().getReadableName());
                break;
            default:
                LOGGER.warn("There are inconsistency between InternalJob and FlowActionType classes.");
                break;
        }
    /**
     * System.out.println("******** task dump ** " +
     * this.getJobInfo().getJobId() + " " + initiator.getName() +
     * " does " + action.getType() + " " + ((action.getTarget() == null)
     * ? "." : action.getTarget()) + " " + ((action.getTargetElse() ==
     * null) ? "." : action.getTargetElse()) + " " +
     * ((action.getTargetJoin() == null) ? "." :
     * action.getTargetJoin())); for (InternalTask it :
     * this.tasks.values()) { System.out.print(it.getName() + " "); if
     * (it.getIDependences() != null) { System.out.print("deps "); for
     * (InternalTask parent : it.getIDependences()) {
     * System.out.print(parent.getName() + " "); } } if
     * (it.getIfBranch() != null) { System.out.print("if " +
     * it.getIfBranch().getName() + " "); } if (it.getJoinedBranches()
     * != null && it.getJoinedBranches().size() == 2) {
     * System.out.print("join " +
     * it.getJoinedBranches().get(0).getName() + " " +
     * it.getJoinedBranches().get(1).getName()); } System.out.println();
     * } System.out.println("******** task dump ** " +
     * this.getJobInfo().getJobId()); System.out.println();
     */
    }
    // terminate this task
    if (!didAction) {
        getJobDescriptor().terminate(taskId, taskIsInError);
    }
    return changesInfo;
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Example 14 with FlowAction

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

the class InternalJob method finishInErrorTask.

public ChangedTasksInfo finishInErrorTask(TaskId taskId, TaskResultImpl result, SchedulerStateUpdate frontend) {
    FlowAction action = result.getAction();
    ChangedTasksInfo changedTasksInfo = terminateTask(false, taskId, frontend, action, result, true);
    setUnPause();
    return changedTasksInfo;
}
Also used : FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction)

Example 15 with FlowAction

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

the class TerminateReplicateTaskHandlerTest method init.

@Before
public void init() {
    action = new FlowAction(FlowActionType.REPLICATE);
    action.setDupNumber(0);
    MockitoAnnotations.initMocks(this);
    when(internalJob.getJobInfo()).thenReturn(jobInfoImpl);
    when(internalJob.getJobDescriptor()).thenReturn(jobDescriptorImpl);
    terminateReplicateTaskHandler = new TerminateReplicateTaskHandler(internalJob);
}
Also used : FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction) Before(org.junit.Before)

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