Search in sources :

Example 26 with ExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ExecutableContainer in project scheduling by ow2-proactive.

the class InternalTask method replicate.

/**
 * {@inheritDoc}
 */
@Override
public TaskState replicate() throws ExecutableCreationException {
    /*
         * this implementation deep copies everything using serialization. however the new
         * InternalTask cannot be strictly identical and we have to handle the following special
         * cases:
         *
         * - ExecutableContainer is transient and not copied during serialization. It needs to be
         * manually copied, and added to the InternalTask replica
         *
         * - Using the TaskInfo of _this_ gives us a FINISHED task, need to explicitely create a new
         * clean one.
         *
         * - InternalTask dependencies need to be nulled as they contain references to other
         * InternalTasks, and will be rewritten later anyway
         *
         * - Most of the objects down the object graph contain Hibernate @Id fields. If all those
         * fields are not set to 0 when inserting the object in DB, insertion will fail.
         *
         * - Collections are mapped to specific Hibernate internal collections at runtime, which
         * contain references to the @Id fields mentionned above. They need to be reset too.
         */
    InternalTask replicatedTask = null;
    // ExecutableContainer replicatedContainer = null;
    try {
        // Deep copy of the InternalTask using proactive serialization
        replicatedTask = (InternalTask) ProActiveMakeDeepCopy.WithProActiveObjectStream.makeDeepCopy(this);
    } catch (Throwable t) {
        throw new ExecutableCreationException("Failed to serialize task", t);
    }
    replicatedTask.internalJob = internalJob;
    // internalTasksDependencies contain references to other InternalTasks, it needs to be removed.
    // anyway, dependencies for the new task will not be the same as the original
    replicatedTask.internalTasksDependencies = null;
    // the taskinfo needs to be cleaned so that we don't tag this task as finished
    TaskId repId = replicatedTask.taskInfo.getTaskId();
    replicatedTask.taskInfo = new TaskInfoImpl();
    // we only need this id for the HashSet comparisons...
    replicatedTask.taskInfo.setTaskId(repId);
    replicatedTask.taskInfo.setNumberOfExecutionLeft(getMaxNumberOfExecution());
    replicatedTask.taskInfo.setNumberOfExecutionOnFailureLeft(getMaxNumberOfExecutionOnFailure());
    replicatedTask.setReplicatedFrom(this);
    // The next DB.update(InternalJob) will take care of it
    return replicatedTask;
}
Also used : ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl)

Aggregations

ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)23 Test (org.junit.Test)22 SimpleScript (org.ow2.proactive.scripting.SimpleScript)21 TaskScript (org.ow2.proactive.scripting.TaskScript)21 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)13 Semaphore (java.util.concurrent.Semaphore)5 Repeat (org.ow2.proactive.utils.Repeat)5 File (java.io.File)4 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)4 TaskDataspaces (org.ow2.proactive.scheduler.task.data.TaskDataspaces)4 NamingService (org.objectweb.proactive.extensions.dataspaces.core.naming.NamingService)3 FileSelector (org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector)3 OutputSelector (org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector)3 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)2 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)2 InputSelector (org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector)2 WaitAndPrint (org.ow2.proactive.scheduler.examples.WaitAndPrint)2 ExecutableContainer (org.ow2.proactive.scheduler.task.containers.ExecutableContainer)2 Stopwatch (com.google.common.base.Stopwatch)1 InputStreamReader (java.io.InputStreamReader)1