Search in sources :

Example 36 with InternalTaskFlowJob

use of org.ow2.proactive.scheduler.job.InternalTaskFlowJob in project scheduling by ow2-proactive.

the class TerminateLoopHandlerTest method generateInternalTask.

private InternalTask generateInternalTask() {
    InternalJob job = new InternalTaskFlowJob("test-name", JobPriority.NORMAL, OnTaskError.CANCEL_JOB, "description");
    InternalTask internalTask = new InternalScriptTask(job);
    internalTask.setId(TaskIdImpl.createTaskId(new JobIdImpl(666L, "JobName"), "readableName", 555L));
    return internalTask;
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob)

Example 37 with InternalTaskFlowJob

use of org.ow2.proactive.scheduler.job.InternalTaskFlowJob in project scheduling by ow2-proactive.

the class DefaultPolicyTest method createSingleTaskJob.

private JobDescriptorImpl createSingleTaskJob(JobPriority jobPriority) {
    InternalTaskFlowJob taskFlowJob = new InternalTaskFlowJob("test", jobPriority, OnTaskError.CANCEL_JOB, "");
    taskFlowJob.setId(JobIdImpl.makeJobId(Integer.toString(jobId++)));
    ArrayList<InternalTask> tasks = new ArrayList<>();
    tasks.add(new InternalScriptTask(taskFlowJob));
    taskFlowJob.addTasks(tasks);
    return new JobDescriptorImpl(taskFlowJob);
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) JobDescriptorImpl(org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl)

Example 38 with InternalTaskFlowJob

use of org.ow2.proactive.scheduler.job.InternalTaskFlowJob in project scheduling by ow2-proactive.

the class InternalTaskParentFinderTest method generateInternalTask.

private InternalTask generateInternalTask(long id, TaskStatus taskStatus) {
    InternalJob job = new InternalTaskFlowJob("test-name", JobPriority.NORMAL, OnTaskError.CANCEL_JOB, "description");
    InternalTask internalTask = new InternalScriptTask(job);
    internalTask.setId(TaskIdImpl.createTaskId(new JobIdImpl(666L, "JobName"), "readableName", id));
    internalTask.setStatus(taskStatus);
    return internalTask;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob)

Example 39 with InternalTaskFlowJob

use of org.ow2.proactive.scheduler.job.InternalTaskFlowJob in project scheduling by ow2-proactive.

the class InternalJobFactory method createJob.

/**
 * Create an internalTaskFlow job with the given task flow job (user)
 *
 * @param userJob the user job that will be used to create the internal job.
 * @return the created internal job.
 * @throws JobCreationException an exception if the factory cannot create the given job.
 */
private static InternalJob createJob(TaskFlowJob userJob) throws JobCreationException {
    if (userJob.getTasks().size() == 0) {
        logger.info("Job '" + userJob.getName() + "' must contain tasks !");
        throw new JobCreationException("This job must contains tasks !");
    }
    // validate taskflow
    List<FlowChecker.Block> blocks = new ArrayList<>();
    FlowError err = FlowChecker.validate(userJob, blocks);
    if (err != null) {
        String e = "";
        e += "Invalid taskflow: " + err.getMessage() + "; context: " + err.getTask();
        logger.error(e);
        throw new JobCreationException(e, err);
    }
    InternalJob job = new InternalTaskFlowJob();
    // keep an initial job content
    job.setTaskFlowJob(userJob);
    Map<Task, InternalTask> tasksList = new LinkedHashMap<>();
    boolean hasPreciousResult = false;
    for (Task t : userJob.getTasks()) {
        tasksList.put(t, createTask(userJob, job, t));
        if (!hasPreciousResult) {
            hasPreciousResult = t.isPreciousResult();
        }
    }
    for (Entry<Task, InternalTask> entry : tasksList.entrySet()) {
        if (entry.getKey().getDependencesList() != null) {
            for (Task t : entry.getKey().getDependencesList()) {
                entry.getValue().addDependence(tasksList.get(t));
            }
        }
        job.addTask(entry.getValue());
    }
    // tag matching blocks in InternalTasks
    for (InternalTask it : tasksList.values()) {
        for (FlowChecker.Block block : blocks) {
            if (it.getName().equals(block.start.element.getName())) {
                it.setMatchingBlock(block.end.element.getName());
            }
            if (it.getName().equals(block.end.element.getName())) {
                it.setMatchingBlock(block.start.element.getName());
            }
        }
    }
    // create if/else/join weak dependencies
    for (InternalTask it : tasksList.values()) {
        // it performs an IF action
        if (it.getFlowScript() != null && it.getFlowScript().getActionType().equals(FlowActionType.IF.toString())) {
            String ifBranch = it.getFlowScript().getActionTarget();
            String elseBranch = it.getFlowScript().getActionTargetElse();
            String join = it.getFlowScript().getActionContinuation();
            List<InternalTask> joinedBranches = new ArrayList<>();
            // find the ifBranch task
            for (InternalTask it2 : tasksList.values()) {
                if (it2.getName().equals(ifBranch)) {
                    it2.setIfBranch(it);
                    String match = it2.getMatchingBlock();
                    // find its matching block task
                    if (match == null) {
                        // no match: single task
                        joinedBranches.add(it2);
                    } else {
                        for (InternalTask it3 : tasksList.values()) {
                            if (it3.getName().equals(match)) {
                                joinedBranches.add(it3);
                                break;
                            }
                        }
                    }
                    break;
                }
            }
            // find the elseBranch task
            for (InternalTask it2 : tasksList.values()) {
                if (it2.getName().equals(elseBranch)) {
                    it2.setIfBranch(it);
                    String match = it2.getMatchingBlock();
                    // find its matching block task
                    if (match == null) {
                        // no match: single task
                        joinedBranches.add(it2);
                    } else {
                        for (InternalTask it3 : tasksList.values()) {
                            if (it3.getName().equals(match)) {
                                joinedBranches.add(it3);
                                break;
                            }
                        }
                    }
                    break;
                }
            }
            // find the joinBranch task
            for (InternalTask it2 : tasksList.values()) {
                if (it2.getName().equals(join)) {
                    it2.setJoinedBranches(joinedBranches);
                }
            }
        }
    }
    return job;
}
Also used : FlowError(org.ow2.proactive.scheduler.common.job.factories.FlowError) Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) LinkedHashMap(java.util.LinkedHashMap) FlowChecker(org.ow2.proactive.scheduler.common.job.factories.FlowChecker)

Example 40 with InternalTaskFlowJob

use of org.ow2.proactive.scheduler.job.InternalTaskFlowJob in project scheduling by ow2-proactive.

the class SchedulerStateRecoverHelperTest method testRecoverWithIncorrectStatusForLoadedNotFinishedJobs.

public void testRecoverWithIncorrectStatusForLoadedNotFinishedJobs(JobStatus jobStatus) {
    InternalJob job = new InternalTaskFlowJob();
    job.setStatus(jobStatus);
    SchedulerDBManager dbManager = Mockito.mock(SchedulerDBManager.class);
    SchedulerStateRecoverHelper stateRecoverHelper = new SchedulerStateRecoverHelper(dbManager);
    Mockito.when(dbManager.loadNotFinishedJobs(true)).thenReturn(ImmutableList.of(job));
    stateRecoverHelper.recover(-1);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob)

Aggregations

InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)39 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)33 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)33 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)30 Test (org.junit.Test)27 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)27 JobId (org.ow2.proactive.scheduler.common.job.JobId)22 ArrayList (java.util.ArrayList)20 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)14 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)10 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)5 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)5 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)5 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 InputStream (java.io.InputStream)3 JobInfoImpl (org.ow2.proactive.scheduler.job.JobInfoImpl)3 File (java.io.File)2 LinkedHashMap (java.util.LinkedHashMap)2 Node (org.objectweb.proactive.core.node.Node)2 SchedulerDBManager (org.ow2.proactive.scheduler.core.db.SchedulerDBManager)2