Search in sources :

Example 26 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask 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 27 with InternalTask

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

Example 28 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class InternalJobFactory method createTask.

/**
 * Create an internal native Task with the given native task (user)
 *
 * @param task the user native task that will be used to create the internal native task.
 * @return the created internal task.
 * @throws JobCreationException an exception if the factory cannot create the given task.
 */
private static InternalTask createTask(Job userJob, InternalJob internalJob, NativeTask task) throws JobCreationException {
    if (((task.getCommandLine() == null) || (task.getCommandLine().length == 0))) {
        String msg = "The command line is null or empty and not generated !";
        logger.info(msg);
        throw new JobCreationException(msg);
    }
    try {
        String commandAndArguments = "\"" + Joiner.on("\" \"").join(task.getCommandLine()) + "\"";
        InternalTask scriptTask;
        if (isForkingTask()) {
            scriptTask = new InternalForkedScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(commandAndArguments, "native"))), internalJob);
            configureRunAsMe(task);
        } else {
            scriptTask = new InternalScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(commandAndArguments, "native"))), internalJob);
        }
        ForkEnvironment forkEnvironment = new ForkEnvironment();
        scriptTask.setForkEnvironment(forkEnvironment);
        // set task common properties
        setTaskCommonProperties(userJob, task, scriptTask);
        return scriptTask;
    } catch (Exception e) {
        throw new JobCreationException(e);
    }
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 29 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class InternalJobFactory method createTask.

/**
 * Create an internal java Task with the given java task (user)
 *
 * @param task the user java task that will be used to create the internal java task.
 * @return the created internal task.
 * @throws JobCreationException an exception if the factory cannot create the given task.
 */
@SuppressWarnings("unchecked")
private static InternalTask createTask(Job userJob, InternalJob internalJob, JavaTask task) throws JobCreationException {
    InternalTask javaTask;
    if (task.getExecutableClassName() != null) {
        HashMap<String, byte[]> args = task.getSerializedArguments();
        try {
            if (isForkingTask()) {
                javaTask = new InternalForkedScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(task.getExecutableClassName(), JavaClassScriptEngineFactory.JAVA_CLASS_SCRIPT_ENGINE_NAME, new Serializable[] { args }))), internalJob);
                javaTask.setForkEnvironment(task.getForkEnvironment());
                configureRunAsMe(task);
            } else {
                javaTask = new InternalScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(task.getExecutableClassName(), JavaClassScriptEngineFactory.JAVA_CLASS_SCRIPT_ENGINE_NAME, new Serializable[] { args }))), internalJob);
            }
        } catch (InvalidScriptException e) {
            throw new JobCreationException(e);
        }
    } else {
        String msg = "You must specify your own executable task class to be launched (in every task)!";
        logger.info(msg);
        throw new JobCreationException(msg);
    }
    // set task common properties
    try {
        setTaskCommonProperties(userJob, task, javaTask);
    } catch (Exception e) {
        throw new JobCreationException(e);
    }
    return javaTask;
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 30 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TerminateIfTaskHandler method searchIfElseJoinTasks.

private InternalTask[] searchIfElseJoinTasks(FlowAction action, InternalTask initiator) {
    InternalTask targetIf = null;
    InternalTask targetElse = null;
    InternalTask targetJoin = null;
    // search for the targets as perfect matches of the unique name
    for (InternalTask it : internalJob.getIHMTasks().values()) {
        // target is finished : probably looped
        if (it.getStatus().equals(TaskStatus.FINISHED) || it.getStatus().equals(TaskStatus.SKIPPED)) {
            continue;
        }
        if (action.getTarget().equals(it.getName())) {
            if (it.getIfBranch().equals(initiator)) {
                targetIf = it;
            }
        } else if (action.getTargetElse().equals(it.getName())) {
            if (it.getIfBranch().equals(initiator)) {
                targetElse = it;
            }
        } else if (action.getTargetContinuation().equals(it.getName())) {
            InternalTask up = internalJob.findTaskUp(initiator.getName(), it);
            if (up != null && up.equals(initiator)) {
                targetJoin = it;
            }
        }
    }
    boolean searchIf = (targetIf == null);
    boolean searchElse = (targetElse == null);
    boolean searchJoin = (targetJoin == null);
    // but the highest iteration index
    for (InternalTask it : internalJob.getIHMTasks().values()) {
        // does not share the same dup index : cannot be the same scope
        if (it.getReplicationIndex() != initiator.getReplicationIndex()) {
            continue;
        }
        if (it.getStatus().equals(TaskStatus.FINISHED) || it.getStatus().equals(TaskStatus.SKIPPED)) {
            continue;
        }
        String name = InternalTask.getInitialName(it.getName());
        if (searchIf && InternalTask.getInitialName(action.getTarget()).equals(name)) {
            if (targetIf == null || targetIf.getIterationIndex() < it.getIterationIndex()) {
                targetIf = it;
            }
        } else if (searchElse && InternalTask.getInitialName(action.getTargetElse()).equals(name)) {
            if (targetElse == null || targetElse.getIterationIndex() < it.getIterationIndex()) {
                targetElse = it;
            }
        } else if (searchJoin && InternalTask.getInitialName(action.getTargetContinuation()).equals(name)) {
            if (targetJoin == null || targetJoin.getIterationIndex() < it.getIterationIndex()) {
                targetJoin = it;
            }
        }
    }
    InternalTask[] result = { targetIf, targetElse, targetJoin };
    return result;
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Aggregations

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)142 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)74 Test (org.junit.Test)72 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)39 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)37 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)32 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)31 ArrayList (java.util.ArrayList)30 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 JobId (org.ow2.proactive.scheduler.common.job.JobId)22 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)18 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)16 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)13 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)12 HashMap (java.util.HashMap)10 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)10 ProActiveTest (org.ow2.tests.ProActiveTest)10 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)9 HashSet (java.util.HashSet)8 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)8