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);
}
}
}
}
}
}
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();
}
}
}
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;
}
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);
}
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");
}
}
Aggregations