Search in sources :

Example 41 with TaskId

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

the class JobDescriptorImpl method terminate.

/**
 * Update the eligible list of task and dependencies if necessary.
 * This function considered that the taskId is in eligible task list.
 * Visibility is package because user cannot use this method.
 *
 * @param taskId the task to remove from running task.
 */
public void terminate(TaskId taskId, boolean inErrorTask) {
    Map<TaskId, ? extends TaskDescriptor> currentTasks = inErrorTask ? pausedTasks : runningTasks;
    List<TaskId> taskIdsToSkip = new ArrayList<>();
    if (getInternal().getType() == JobType.TASKSFLOW) {
        TaskDescriptor taskToTerminate = currentTasks.get(taskId);
        if (taskToTerminate != null) {
            for (TaskDescriptor childTask : taskToTerminate.getChildren()) {
                decreaseParentCount(childTask);
                if (((EligibleTaskDescriptorImpl) childTask).getCount() == 0) {
                    if (internalJob.getStatus() == JobStatus.PAUSED) {
                        pausedTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
                    } else if (internalJob.getStatus() == JobStatus.IN_ERROR && ((EligibleTaskDescriptorImpl) childTask).getInternal().getStatus() == TaskStatus.PAUSED) {
                        pausedTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
                    } else if (((EligibleTaskDescriptorImpl) childTask).getInternal().getStatus() == TaskStatus.SKIPPED) {
                        runningTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
                        taskIdsToSkip.add(childTask.getTaskId());
                    } else {
                        eligibleTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
                    }
                }
            }
            decreaseChildrenCountForAllParents(taskToTerminate);
        }
    }
    currentTasks.remove(taskId);
    for (TaskId taskIdToSkip : taskIdsToSkip) {
        terminate(taskIdToSkip);
    }
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ArrayList(java.util.ArrayList)

Example 42 with TaskId

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

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

the class JobDescriptorImpl method doIf.

/**
 * Complete IF action on JobDescriptor side
 *
 * @param initiator Task initiating the IF action
 * @param branchStart START task of the IF branch
 * @param branchEnd END task of the IF branch
 * @param ifJoin JOIN task of the IF action, or null
 * @param elseTarget the START task of the ELSE branch that will not be executed
 * @param elseTasks list of tasks contained in the not executed ELSE branch
 */
public void doIf(TaskId initiator, TaskId branchStart, TaskId branchEnd, TaskId ifJoin, TaskId elseTarget, List<InternalTask> elseTasks) {
    EligibleTaskDescriptorImpl init = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
    EligibleTaskDescriptorImpl start = (EligibleTaskDescriptorImpl) branchTasks.get(branchStart);
    EligibleTaskDescriptorImpl end = null;
    EligibleTaskDescriptorImpl join = null;
    if (ifJoin != null) {
        join = (EligibleTaskDescriptorImpl) branchTasks.get(ifJoin);
    }
    // plug the initiator with the beginning of the IF block
    init.addChild(start);
    start.addParent(init);
    // the join task is optional
    if (join != null) {
        for (EligibleTaskDescriptor td : branchTasks.values()) {
            LinkedList<EligibleTaskDescriptorImpl> q = new LinkedList<>();
            q.offer((EligibleTaskDescriptorImpl) td);
            // find the matching end block task
            do {
                EligibleTaskDescriptorImpl ptr = q.poll();
                // if (ptr.getChildren() == null || ptr.getChildren().size() == 0) {
                if (ptr.getTaskId().equals(branchEnd)) {
                    end = ptr;
                    break;
                } else {
                    for (TaskDescriptor desc : ptr.getChildren()) {
                        if (!q.contains(desc)) {
                            q.offer((EligibleTaskDescriptorImpl) desc);
                        }
                    }
                }
            } while (q.size() > 0);
            if (end != null) {
                break;
            }
        }
        // plug the join task with the end of the if block
        join.addParent(end);
        end.addChild(join);
    }
    branchTasks.remove(start);
    if (join != null) {
        branchTasks.remove(join);
    }
    for (InternalTask it : elseTasks) {
        EligibleTaskDescriptorImpl td = (EligibleTaskDescriptorImpl) branchTasks.remove(it.getId());
        LinkedList<EligibleTaskDescriptorImpl> q = new LinkedList<>();
        if (td != null) {
            q.clear();
            q.offer(td);
            while (q.size() > 0) {
                EligibleTaskDescriptorImpl ptr = q.poll();
                ptr.setChildrenCount(0);
                ptr.setCount(0);
                if (ptr.getChildren() != null) {
                    for (TaskDescriptor child : ptr.getChildren()) {
                        q.offer((EligibleTaskDescriptorImpl) child);
                    }
                }
            }
        }
    }
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) LinkedList(java.util.LinkedList)

Example 44 with TaskId

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

the class JobDescriptorImpl method restoreRunningTasks.

/**
 * {@inheritDoc}
 */
public void restoreRunningTasks() {
    final String performanceTestOngoing = System.getProperty("performanceTestOngoing");
    if (performanceTestOngoing != null && performanceTestOngoing.equalsIgnoreCase("true")) {
        logger.info(STARTING_TASK_RECOVERY_FOR_JOB + jobId);
    }
    final Iterator<Entry<TaskId, EligibleTaskDescriptor>> iterator = eligibleTasks.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<TaskId, EligibleTaskDescriptor> entry = iterator.next();
        TaskId taskId = entry.getKey();
        EligibleTaskDescriptor task = entry.getValue();
        if (((EligibleTaskDescriptorImpl) task).getInternal().getStatus() == TaskStatus.RUNNING) {
            logger.debug("Move task " + taskId + " from eligible tasks to running tasks");
            runningTasks.put(taskId, task);
            iterator.remove();
        }
    }
}
Also used : Entry(java.util.Map.Entry) TaskId(org.ow2.proactive.scheduler.common.task.TaskId)

Example 45 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId 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)

Aggregations

TaskId (org.ow2.proactive.scheduler.common.task.TaskId)100 Test (org.junit.Test)43 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)43 JobId (org.ow2.proactive.scheduler.common.job.JobId)33 ArrayList (java.util.ArrayList)27 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)25 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)22 HashMap (java.util.HashMap)18 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)18 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)15 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)12 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)12 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)11 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)11 List (java.util.List)10 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)9 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)9