Search in sources :

Example 1 with ExecutableCreationException

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

Example 2 with ExecutableCreationException

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

Example 3 with ExecutableCreationException

use of org.ow2.proactive.scheduler.common.exception.ExecutableCreationException in project scheduling by ow2-proactive.

the class JavaClassScriptEngine method getExecutable.

public JavaExecutable getExecutable(String userExecutableClassName) throws ExecutableCreationException {
    try {
        ClassLoader tcl = Thread.currentThread().getContextClassLoader();
        Class<?> userExecutableClass = tcl.loadClass(userExecutableClassName);
        return (JavaExecutable) userExecutableClass.newInstance();
    } catch (ClassNotFoundException e) {
        throw new ExecutableCreationException("Unable to instantiate JavaExecutable. " + userExecutableClassName + " class cannot be found", e);
    } catch (InstantiationException e) {
        throw new ExecutableCreationException("Unable to instantiate JavaExecutable. " + userExecutableClassName + " might not define no-args constructor", e);
    } catch (ClassCastException e) {
        throw new ExecutableCreationException("Unable to instantiate JavaExecutable. " + userExecutableClassName + " might not inherit from org.ow2.proactive.scheduler.common.task.executable.JavaExecutable", e);
    } catch (Throwable e) {
        throw new ExecutableCreationException("Unable to instantiate JavaExecutable", e);
    }
}
Also used : ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException) JavaExecutable(org.ow2.proactive.scheduler.common.task.executable.JavaExecutable)

Aggregations

ExecutableCreationException (org.ow2.proactive.scheduler.common.exception.ExecutableCreationException)3 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)1 JavaExecutable (org.ow2.proactive.scheduler.common.task.executable.JavaExecutable)1 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)1 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)1