Search in sources :

Example 6 with JobDescriptor

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

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

the class DefaultPolicy method getOrderedTasks.

/**
 * This method return the tasks using FIFO policy according to the jobs priorities.
 *
 * @see org.ow2.proactive.scheduler.policy.Policy#getOrderedTasks(java.util.List)
 */
@Override
public LinkedList<EligibleTaskDescriptor> getOrderedTasks(List<JobDescriptor> jobs) {
    LinkedList<EligibleTaskDescriptor> toReturn = new LinkedList<>();
    Collections.sort(jobs, FIFO_BY_PRIORITY_COMPARATOR);
    // add all sorted tasks to list of tasks
    for (JobDescriptor jd : jobs) {
        Collection<TaskDescriptor> tasks = jd.getEligibleTasks();
        Collection<EligibleTaskDescriptor> eligibleTasks = (Collection) tasks;
        toReturn.addAll(eligibleTasks);
    }
    // return sorted list of tasks
    return toReturn;
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) Collection(java.util.Collection) LinkedList(java.util.LinkedList)

Example 8 with JobDescriptor

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

the class SchedulingServiceTest2 method testFailedTask.

private void testFailedTask(boolean failNativeTask) throws Exception {
    service.submitJob(createJob(createTestJob()));
    listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
    Map<JobId, JobDescriptor> jobsMap;
    JobDescriptor jobDesc;
    jobsMap = service.lockJobsToSchedule();
    assertEquals(1, jobsMap.size());
    jobDesc = jobsMap.values().iterator().next();
    Assert.assertEquals(2, jobDesc.getEligibleTasks().size());
    for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
        taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
    }
    service.unlockJobsToSchedule(jobsMap.values());
    if (failNativeTask) {
        InternalTask nativeTask = ((JobDescriptorImpl) jobDesc).getInternal().getTask("nativeTask");
        // native task terminates with code 1, flag 'cancelJobOnError' was
        // set so job should be cancelled
        service.taskTerminatedWithResult(nativeTask.getId(), new TaskResultImpl(nativeTask.getId(), new RuntimeException(), null, 0));
    } else {
        InternalTask javaTask = ((JobDescriptorImpl) jobDesc).getInternal().getTask("javaTask");
        // java task terminates with exception, flag 'cancelJobOnError' was
        // set so job should be cancelled
        service.taskTerminatedWithResult(javaTask.getId(), new TaskResultImpl(javaTask.getId(), new RuntimeException(), null, 0));
    }
    jobsMap = service.lockJobsToSchedule();
    assertEquals(0, jobsMap.size());
    listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_UPDATED);
    infrastructure.assertRequests(2);
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 9 with JobDescriptor

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

the class SchedulingServiceTest3 method testTaskKill.

@Test
public void testTaskKill() throws Exception {
    service.submitJob(createJob(createTestJob(false)));
    listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
    Map<JobId, JobDescriptor> jobsMap;
    JobDescriptor jobDesc;
    jobsMap = service.lockJobsToSchedule();
    assertEquals(1, jobsMap.size());
    jobDesc = jobsMap.values().iterator().next();
    Assert.assertEquals(2, jobDesc.getEligibleTasks().size());
    for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
        taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
    }
    service.unlockJobsToSchedule(jobsMap.values());
    try {
        service.killTask(jobDesc.getJobId(), "invalid task name");
        Assert.fail();
    } catch (UnknownTaskException e) {
    }
    try {
        service.killTask(JobIdImpl.makeJobId("1234567"), "javaTask");
        Assert.fail();
    } catch (UnknownJobException e) {
    }
    Assert.assertTrue(service.killTask(jobDesc.getJobId(), "javaTask"));
    listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED);
    infrastructure.assertRequests(1);
    Assert.assertFalse(service.killTask(jobDesc.getJobId(), "javaTask"));
    TaskId nativeTaskId = ((JobDescriptorImpl) jobDesc).getInternal().getTask("nativeTask").getId();
    service.taskTerminatedWithResult(nativeTaskId, new TaskResultImpl(nativeTaskId, new Integer(0), null, 0));
    listener.assertEvents(SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_UPDATED);
    infrastructure.assertRequests(1);
    try {
        service.killTask(jobDesc.getJobId(), "javaTask");
    } catch (UnknownJobException e) {
        Assert.fail("The job should still exist in the memory context as the auto Job removal feature isn't enabled");
    }
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobDescriptorImpl(org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 10 with JobDescriptor

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

the class SchedulingServiceTest3 method testTaskKillAndJobCancel.

@Test
public void testTaskKillAndJobCancel() throws Exception {
    service.submitJob(createJob(createTestJob(true)));
    listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
    Map<JobId, JobDescriptor> jobsMap;
    JobDescriptor jobDesc;
    jobsMap = service.lockJobsToSchedule();
    assertEquals(1, jobsMap.size());
    jobDesc = jobsMap.values().iterator().next();
    Assert.assertEquals(2, jobDesc.getEligibleTasks().size());
    for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
        taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
    }
    service.unlockJobsToSchedule(jobsMap.values());
    Assert.assertTrue(service.killTask(jobDesc.getJobId(), "javaTask"));
    listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_UPDATED);
    infrastructure.assertRequests(2);
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Aggregations

JobDescriptor (org.ow2.proactive.scheduler.common.JobDescriptor)24 EligibleTaskDescriptor (org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor)20 Test (org.junit.Test)15 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)15 JobId (org.ow2.proactive.scheduler.common.job.JobId)13 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)11 JobDescriptorImpl (org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl)10 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)8 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)7 ArrayList (java.util.ArrayList)6 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)4 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 EligibleTaskDescriptorImpl (org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 TopologyDisabledException (org.ow2.proactive.resourcemanager.frontend.topology.TopologyDisabledException)2