Search in sources :

Example 21 with Task

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

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

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

the class TerminateReplicateTaskHandler method terminateReplicateTask.

public boolean terminateReplicateTask(FlowAction action, InternalTask initiator, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend, TaskId taskId) {
    int runs = action.getDupNumber();
    logger.info("Control Flow Action REPLICATE (runs:" + runs + ")");
    List<InternalTask> toReplicate = new ArrayList<>();
    // find the tasks that need to be replicated
    for (InternalTask internalTask : internalJob.getIHMTasks().values()) {
        List<InternalTask> internalTaskDependencies = internalTask.getIDependences() == null ? new ArrayList<InternalTask>() : internalTask.getIDependences();
        for (InternalTask internalTaskDependency : internalTaskDependencies) {
            if (isTheInitiatorTask(initiator, toReplicate, internalTask, internalTaskDependency)) {
                if (runs < 1) {
                    skipReplication(initiator, changesInfo, internalTask);
                    break;
                } else {
                    toReplicate.add(internalTask);
                }
            }
        }
    }
    // for each initial task to replicate
    for (InternalTask internalTaskToReplicate : toReplicate) {
        // determine the target of the replication whether it is a block or
        // a single task
        InternalTask target = null;
        // target is a task block start : replication of the block
        if (internalTaskToReplicate.getFlowBlock().equals(FlowBlock.START)) {
            String tg = internalTaskToReplicate.getMatchingBlock();
            for (InternalTask internalTask : internalJob.getIHMTasks().values()) {
                if (tg.equals(internalTask.getName()) && !(internalTask.getStatus().equals(TaskStatus.FINISHED) || internalTask.getStatus().equals(TaskStatus.SKIPPED)) && internalTask.dependsOn(internalTaskToReplicate)) {
                    target = internalTask;
                    break;
                }
            }
            if (target == null) {
                logger.error("REPLICATE: could not find matching block '" + tg + "'");
                continue;
            }
        } else // target is not a block : replication of the task
        {
            target = internalTaskToReplicate;
        }
        // for each number of parallel run
        for (int i = 1; i < runs; i++) {
            // accumulates the tasks between the initiator and the target
            Map<TaskId, InternalTask> tasksBetweenInitiatorAndTarget = new HashMap<>();
            // replicate the tasks between the initiator and the target
            try {
                target.replicateTree(tasksBetweenInitiatorAndTarget, internalTaskToReplicate.getId(), false, initiator.getReplicationIndex() * runs, 0);
            } catch (Exception e) {
                logger.error("REPLICATE: could not replicate tree", e);
                break;
            }
            ((JobInfoImpl) internalJob.getJobInfo()).setNumberOfPendingTasks(((JobInfoImpl) internalJob.getJobInfo()).getNumberOfPendingTasks() + tasksBetweenInitiatorAndTarget.size());
            // pointers to the new replicated tasks corresponding the begin
            // and
            // the end of the block ; can be the same
            InternalTask newTarget = null;
            InternalTask newEnd = null;
            // configure the new tasks
            for (InternalTask internalTask : tasksBetweenInitiatorAndTarget.values()) {
                internalTask.setJobInfo(((JobInfoImpl) internalJob.getJobInfo()));
                int dupIndex = getNextReplicationIndex(InternalTask.getInitialName(internalTask.getName()), internalTask.getIterationIndex());
                internalJob.addTask(internalTask);
                internalTask.setReplicationIndex(dupIndex);
                assignReplicationTag(internalTask, initiator, false, action);
            }
            changesInfo.newTasksAdded(tasksBetweenInitiatorAndTarget.values());
            // find the beginning and the ending of the replicated block
            for (Entry<TaskId, InternalTask> tasksBetweenInitiatorAndTargetEntry : tasksBetweenInitiatorAndTarget.entrySet()) {
                InternalTask internalBlockTask = tasksBetweenInitiatorAndTargetEntry.getValue();
                // initiator
                if (internalTaskToReplicate.getId().equals(tasksBetweenInitiatorAndTargetEntry.getKey())) {
                    newTarget = internalBlockTask;
                    newTarget.addDependence(initiator);
                // no need to add newTarget to modifiedTasks
                // because newTarget is among dup.values(), and we
                // have added them all
                }
                // connect the last task of the block with the merge task(s)
                if (target.getId().equals(tasksBetweenInitiatorAndTargetEntry.getKey())) {
                    newEnd = internalBlockTask;
                    List<InternalTask> toAdd = new ArrayList<>();
                    // find the merge tasks ; can be multiple
                    for (InternalTask internalTask : internalJob.getIHMTasks().values()) {
                        List<InternalTask> pdeps = internalTask.getIDependences();
                        if (pdeps != null) {
                            for (InternalTask parent : pdeps) {
                                if (parent.getId().equals(target.getId())) {
                                    toAdd.add(internalTask);
                                }
                            }
                        }
                    }
                    // connect the merge tasks
                    for (InternalTask internalTask : toAdd) {
                        internalTask.addDependence(newEnd);
                        changesInfo.taskUpdated(internalTask);
                    }
                }
            }
            // propagate the changes on the JobDescriptor
            internalJob.getJobDescriptor().doReplicate(taskId, tasksBetweenInitiatorAndTarget, newTarget, target.getId(), newEnd.getId());
        }
    }
    // notify frontend that tasks were added to the job
    ((JobInfoImpl) internalJob.getJobInfo()).setTasksChanges(changesInfo, internalJob);
    if (frontend != null) {
        frontend.jobStateUpdated(internalJob.getOwner(), new NotificationData<>(SchedulerEvent.TASK_REPLICATED, internalJob.getJobInfo()));
        frontend.jobStateUpdated(internalJob.getOwner(), new NotificationData<>(SchedulerEvent.TASK_SKIPPED, internalJob.getJobInfo()));
        frontend.jobUpdatedFullData(internalJob);
    }
    ((JobInfoImpl) internalJob.getJobInfo()).clearTasksChanges();
    // no jump is performed ; now that the tasks have been replicated and
    // configured, the flow can continue its normal operation
    internalJob.getJobDescriptor().terminate(taskId);
    return true;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Example 24 with Task

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

the class InternalForkedScriptTask method createLauncher.

/**
 * {@inheritDoc}
 */
@Override
public TaskLauncher createLauncher(Node node) throws ActiveObjectCreationException, NodeException {
    logger.info(getTaskInfo().getTaskId(), "creating forked task launcher");
    TaskLauncher launcher = (TaskLauncher) PAActiveObject.newActive(TaskLauncher.class.getName(), new Object[] { getDefaultTaskLauncherInitializer(), new ProActiveForkedTaskLauncherFactory() }, node);
    // wait until the task launcher is active
    launcher.isActivated();
    setExecuterInformation(new ExecuterInformation(launcher, node));
    return launcher;
}
Also used : TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) ProActiveForkedTaskLauncherFactory(org.ow2.proactive.scheduler.task.ProActiveForkedTaskLauncherFactory)

Example 25 with Task

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

the class InternalScriptTask method createLauncher.

/**
 * {@inheritDoc}
 */
@Override
public TaskLauncher createLauncher(Node node) throws ActiveObjectCreationException, NodeException {
    logger.info(getTaskInfo().getTaskId(), "creating non forked task launcher");
    TaskLauncher launcher = (TaskLauncher) PAActiveObject.newActive(TaskLauncher.class.getName(), new Object[] { getDefaultTaskLauncherInitializer(), new ProActiveNonForkedTaskLauncherFactory() }, node);
    // wait until the task launcher is active
    launcher.isActivated();
    setExecuterInformation(new ExecuterInformation(launcher, node));
    return launcher;
}
Also used : TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) ProActiveNonForkedTaskLauncherFactory(org.ow2.proactive.scheduler.task.ProActiveNonForkedTaskLauncherFactory)

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