Search in sources :

Example 6 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor in project scheduling by ow2-proactive.

the class JobDescriptorImpl method doIf.

/**
 * Complete IF action on JobDescriptor side
 *
 * @param initiator Task initiating the IF action
 * @param branchStart START task of the IF branch
 * @param branchEnd END task of the IF branch
 * @param ifJoin JOIN task of the IF action, or null
 * @param elseTarget the START task of the ELSE branch that will not be executed
 * @param elseTasks list of tasks contained in the not executed ELSE branch
 */
public void doIf(TaskId initiator, TaskId branchStart, TaskId branchEnd, TaskId ifJoin, TaskId elseTarget, List<InternalTask> elseTasks) {
    EligibleTaskDescriptorImpl init = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
    EligibleTaskDescriptorImpl start = (EligibleTaskDescriptorImpl) branchTasks.get(branchStart);
    EligibleTaskDescriptorImpl end = null;
    EligibleTaskDescriptorImpl join = null;
    if (ifJoin != null) {
        join = (EligibleTaskDescriptorImpl) branchTasks.get(ifJoin);
    }
    // plug the initiator with the beginning of the IF block
    init.addChild(start);
    start.addParent(init);
    // the join task is optional
    if (join != null) {
        for (EligibleTaskDescriptor td : branchTasks.values()) {
            LinkedList<EligibleTaskDescriptorImpl> q = new LinkedList<>();
            q.offer((EligibleTaskDescriptorImpl) td);
            // find the matching end block task
            do {
                EligibleTaskDescriptorImpl ptr = q.poll();
                // if (ptr.getChildren() == null || ptr.getChildren().size() == 0) {
                if (ptr.getTaskId().equals(branchEnd)) {
                    end = ptr;
                    break;
                } else {
                    for (TaskDescriptor desc : ptr.getChildren()) {
                        if (!q.contains(desc)) {
                            q.offer((EligibleTaskDescriptorImpl) desc);
                        }
                    }
                }
            } while (q.size() > 0);
            if (end != null) {
                break;
            }
        }
        // plug the join task with the end of the if block
        join.addParent(end);
        end.addChild(join);
    }
    branchTasks.remove(start);
    if (join != null) {
        branchTasks.remove(join);
    }
    for (InternalTask it : elseTasks) {
        EligibleTaskDescriptorImpl td = (EligibleTaskDescriptorImpl) branchTasks.remove(it.getId());
        LinkedList<EligibleTaskDescriptorImpl> q = new LinkedList<>();
        if (td != null) {
            q.clear();
            q.offer(td);
            while (q.size() > 0) {
                EligibleTaskDescriptorImpl ptr = q.poll();
                ptr.setChildrenCount(0);
                ptr.setCount(0);
                if (ptr.getChildren() != null) {
                    for (TaskDescriptor child : ptr.getChildren()) {
                        q.offer((EligibleTaskDescriptorImpl) child);
                    }
                }
            }
        }
    }
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) LinkedList(java.util.LinkedList)

Example 7 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor in project scheduling by ow2-proactive.

the class JobDescriptorImpl method restoreRunningTasks.

/**
 * {@inheritDoc}
 */
public void restoreRunningTasks() {
    final String performanceTestOngoing = System.getProperty("performanceTestOngoing");
    if (performanceTestOngoing != null && performanceTestOngoing.equalsIgnoreCase("true")) {
        logger.info(STARTING_TASK_RECOVERY_FOR_JOB + jobId);
    }
    final Iterator<Entry<TaskId, EligibleTaskDescriptor>> iterator = eligibleTasks.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<TaskId, EligibleTaskDescriptor> entry = iterator.next();
        TaskId taskId = entry.getKey();
        EligibleTaskDescriptor task = entry.getValue();
        if (((EligibleTaskDescriptorImpl) task).getInternal().getStatus() == TaskStatus.RUNNING) {
            logger.debug("Move task " + taskId + " from eligible tasks to running tasks");
            runningTasks.put(taskId, task);
            iterator.remove();
        }
    }
}
Also used : Entry(java.util.Map.Entry) TaskId(org.ow2.proactive.scheduler.common.task.TaskId)

Example 8 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor 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 9 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor 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 10 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor 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)

Aggregations

EligibleTaskDescriptor (org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor)25 JobDescriptor (org.ow2.proactive.scheduler.common.JobDescriptor)18 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)16 JobId (org.ow2.proactive.scheduler.common.job.JobId)12 Test (org.junit.Test)10 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)9 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)8 JobDescriptorImpl (org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl)7 EligibleTaskDescriptorImpl (org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl)6 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)3 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Entry (java.util.Map.Entry)2 TopologyDisabledException (org.ow2.proactive.resourcemanager.frontend.topology.TopologyDisabledException)2 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)2 RMProxyCreationException (org.ow2.proactive.scheduler.core.rmproxies.RMProxyCreationException)2