Search in sources :

Example 16 with Task

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

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

use of org.ow2.proactive.scheduler.common.task.Task 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) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ArrayList(java.util.ArrayList)

Example 19 with Task

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

the class InternalJob method failed.

/**
 * Failed this job due to the given task failure or job has been killed
 *
 * @param taskId    the task that has been the cause to failure. Can be null if
 *                  the job has been killed
 * @param jobStatus type of the failure on this job. (failed/canceled/killed)
 */
public Set<TaskId> failed(TaskId taskId, JobStatus jobStatus) {
    if (jobStatus != JobStatus.KILLED) {
        InternalTask descriptor = tasks.get(taskId);
        if (descriptor.getStartTime() > 0) {
            descriptor.setFinishedTime(System.currentTimeMillis());
            setNumberOfFinishedTasks(getNumberOfFinishedTasks() + 1);
            if (descriptor.getExecutionDuration() < 0) {
                descriptor.setExecutionDuration(descriptor.getFinishedTime() - descriptor.getStartTime());
            }
        }
        descriptor.setStatus((jobStatus == JobStatus.FAILED) ? TaskStatus.FAILED : TaskStatus.FAULTY);
        // terminate this job descriptor
        getJobDescriptor().failed();
    }
    // set the new status of the job
    setFinishedTime(System.currentTimeMillis());
    setNumberOfPendingTasks(0);
    setNumberOfRunningTasks(0);
    setStatus(jobStatus);
    // creating list of status
    Set<TaskId> updatedTasks = new HashSet<>();
    for (InternalTask td : tasks.values()) {
        if (!td.getId().equals(taskId)) {
            if (td.getStatus() == TaskStatus.RUNNING) {
                td.setStatus(TaskStatus.ABORTED);
                td.setFinishedTime(System.currentTimeMillis());
                if (td.getStartTime() > 0 && td.getExecutionDuration() < 0) {
                    td.setExecutionDuration(td.getFinishedTime() - td.getStartTime());
                }
                updatedTasks.add(td.getId());
            } else if (td.getStatus() == TaskStatus.WAITING_ON_ERROR || td.getStatus() == TaskStatus.WAITING_ON_FAILURE) {
                td.setStatus(TaskStatus.NOT_RESTARTED);
                updatedTasks.add(td.getId());
            } else if (td.getStatus() != TaskStatus.FINISHED && td.getStatus() != TaskStatus.FAILED && td.getStatus() != TaskStatus.FAULTY && td.getStatus() != TaskStatus.SKIPPED) {
                td.setStatus(TaskStatus.NOT_STARTED);
                updatedTasks.add(td.getId());
            }
        }
    }
    terminateTaskDataSpaceApplications();
    return updatedTasks;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashSet(java.util.HashSet)

Example 20 with Task

use of org.ow2.proactive.scheduler.common.task.Task 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
 * @return the taskDescriptor that has just been terminated.
 */
public ChangedTasksInfo terminateTask(boolean errorOccurred, TaskId taskId, SchedulerStateUpdate frontend, FlowAction action, TaskResultImpl result, boolean taskIsPaused) {
    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 (taskIsPaused) {
        setNumberOfInErrorTasks(getNumberOfInErrorTasks() - 1);
    } else {
        setNumberOfRunningTasks(getNumberOfRunningTasks() - 1);
    }
    setNumberOfFinishedTasks(getNumberOfFinishedTasks() + 1);
    if ((getStatus() == JobStatus.RUNNING) && (getNumberOfRunningTasks() == 0) && !taskIsPaused) {
        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, taskIsPaused);
    }
    return changesInfo;
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Aggregations

Test (org.junit.Test)152 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)112 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)100 JobId (org.ow2.proactive.scheduler.common.job.JobId)73 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)69 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)68 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)60 ArrayList (java.util.ArrayList)49 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)48 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)43 Task (org.ow2.proactive.scheduler.common.task.Task)41 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)41 File (java.io.File)37 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)34 HashMap (java.util.HashMap)33 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)33 SimpleScript (org.ow2.proactive.scripting.SimpleScript)33 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)27 TaskScript (org.ow2.proactive.scripting.TaskScript)27 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)26