use of org.ow2.proactive.scheduler.common.TaskDescriptor 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.common.TaskDescriptor in project scheduling by ow2-proactive.
the class InternalJob method terminateTask.
/**
* Terminate a task, change status, managing dependencies
* <p>
* Also, apply a Control Flow Action if provided. This may alter the number
* of tasks in the job, events have to be sent accordingly.
*
* @param errorOccurred has an error occurred for this termination
* @param taskId the task to terminate.
* @param frontend Used to notify all listeners of the replication of tasks,
* triggered by the FlowAction
* @param action a Control Flow Action that will potentially create new tasks
* inside the job
* @return the taskDescriptor that has just been terminated.
*/
public ChangedTasksInfo terminateTask(boolean errorOccurred, TaskId taskId, SchedulerStateUpdate frontend, FlowAction action, TaskResultImpl result, boolean taskIsPaused) {
final InternalTask descriptor = tasks.get(taskId);
if (!errorOccurred) {
decreaseNumberOfFaultyTasks(taskId);
}
descriptor.setFinishedTime(System.currentTimeMillis());
descriptor.setStatus(errorOccurred ? TaskStatus.FAULTY : TaskStatus.FINISHED);
descriptor.setExecutionDuration(result.getTaskDuration());
if (taskIsPaused) {
setNumberOfInErrorTasks(getNumberOfInErrorTasks() - 1);
} else {
setNumberOfRunningTasks(getNumberOfRunningTasks() - 1);
}
setNumberOfFinishedTasks(getNumberOfFinishedTasks() + 1);
if ((getStatus() == JobStatus.RUNNING) && (getNumberOfRunningTasks() == 0) && !taskIsPaused) {
setStatus(JobStatus.STALLED);
}
ChangedTasksInfo changesInfo = new ChangedTasksInfo();
changesInfo.taskUpdated(descriptor);
boolean didAction = false;
if (action != null) {
InternalTask initiator = tasks.get(taskId);
switch(action.getType()) {
/*
* LOOP action
*/
case LOOP:
{
didAction = terminateLoopHandler.terminateLoopTask(action, initiator, changesInfo, frontend);
break;
}
/*
* IF action
*/
case IF:
{
didAction = terminateIfTaskHandler.terminateIfTask(action, initiator, changesInfo, frontend, descriptor, taskId);
break;
}
/*
* REPLICATE action
*/
case REPLICATE:
{
didAction = terminateReplicateTaskHandler.terminateReplicateTask(action, initiator, changesInfo, frontend, taskId);
break;
}
/*
* CONTINUE action : - continue taskflow as if no action was provided
*/
case CONTINUE:
LOGGER.debug("Task flow Action CONTINUE on task " + initiator.getId().getReadableName());
break;
default:
LOGGER.warn("There are inconsistency between InternalJob and FlowActionType classes.");
break;
}
/**
* System.out.println("******** task dump ** " +
* this.getJobInfo().getJobId() + " " + initiator.getName() +
* " does " + action.getType() + " " + ((action.getTarget() == null)
* ? "." : action.getTarget()) + " " + ((action.getTargetElse() ==
* null) ? "." : action.getTargetElse()) + " " +
* ((action.getTargetJoin() == null) ? "." :
* action.getTargetJoin())); for (InternalTask it :
* this.tasks.values()) { System.out.print(it.getName() + " "); if
* (it.getIDependences() != null) { System.out.print("deps "); for
* (InternalTask parent : it.getIDependences()) {
* System.out.print(parent.getName() + " "); } } if
* (it.getIfBranch() != null) { System.out.print("if " +
* it.getIfBranch().getName() + " "); } if (it.getJoinedBranches()
* != null && it.getJoinedBranches().size() == 2) {
* System.out.print("join " +
* it.getJoinedBranches().get(0).getName() + " " +
* it.getJoinedBranches().get(1).getName()); } System.out.println();
* } System.out.println("******** task dump ** " +
* this.getJobInfo().getJobId()); System.out.println();
*/
}
// terminate this task
if (!didAction) {
getJobDescriptor().terminate(taskId, taskIsPaused);
}
return changesInfo;
}
use of org.ow2.proactive.scheduler.common.TaskDescriptor 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.common.TaskDescriptor in project scheduling by ow2-proactive.
the class SchedulerTasksStateRecoverIntegrationTest method testRecover.
@Test
public void testRecover() throws Exception {
SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
RecoveredSchedulerState state = recoverHelper.recover(-1);
Assert.assertEquals(0, state.getFinishedJobs().size());
Assert.assertEquals(0, state.getRunningJobs().size());
Assert.assertEquals(0, state.getPendingJobs().size());
TaskFlowJob job1 = new TaskFlowJob();
JavaTask task1 = createDefaultTask("task1");
JavaTask task2 = createDefaultTask("task2");
JavaTask task3 = createDefaultTask("task3");
task1.addDependence(task2);
task1.addDependence(task3);
task2.addDependence(task3);
job1.addTask(task1);
job1.addTask(task2);
job1.addTask(task3);
InternalJob job = defaultSubmitJob(job1);
JobStateMatcher expectedJob;
expectedJob = job(job.getId(), JobStatus.PENDING).withPending(task("task1", TaskStatus.SUBMITTED), false).withPending(task("task2", TaskStatus.SUBMITTED), false).withPending(task("task3", TaskStatus.SUBMITTED), false).withEligible("task3");
state = checkRecoveredState(recoverHelper.recover(-1), state().withPending(expectedJob));
job = state.getPendingJobs().get(0);
TaskDescriptor task = job.getJobDescriptor().getEligibleTasks().iterator().next();
Assert.assertEquals(2, task.getChildren().size());
Assert.assertEquals(0, task.getParents().size());
job.terminate();
dbManager.updateAfterTaskFinished(job, null, null);
expectedJob = job(job.getId(), JobStatus.FINISHED).withPending(task("task1", TaskStatus.SUBMITTED), false).withPending(task("task2", TaskStatus.SUBMITTED), false).withPending(task("task3", TaskStatus.SUBMITTED), false).withEligible("task3");
state = checkRecoveredState(recoverHelper.recover(-1), state().withFinished(expectedJob));
job = state.getFinishedJobs().get(0);
task = job.getJobDescriptor().getEligibleTasks().iterator().next();
Assert.assertEquals(2, task.getChildren().size());
Assert.assertEquals(0, task.getParents().size());
}
use of org.ow2.proactive.scheduler.common.TaskDescriptor 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);
}
Aggregations