use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl in project scheduling by ow2-proactive.
the class JobDescriptorImpl method doLoop.
/**
* Complete LOOP action on JobDescriptor side
*
* @param initiator Task initiating the LOOP action
* @param tree InternalTask tree of replicated tasks
* @param target Target task of the LOOP action
*/
public void doLoop(TaskId initiator, Map<TaskId, InternalTask> tree, InternalTask target, InternalTask newInit) {
Map<TaskId, EligibleTaskDescriptorImpl> acc = new HashMap<>();
// create new EligibleTasks and accumulate it
for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
TaskId itId = it.getValue().getId();
EligibleTaskDescriptorImpl td = new EligibleTaskDescriptorImpl(it.getValue());
acc.put(itId, td);
}
EligibleTaskDescriptorImpl oldEnd = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
EligibleTaskDescriptorImpl newStart = acc.get(target.getId());
EligibleTaskDescriptorImpl newEnd = acc.get(newInit.getId());
// plug the end of the old tree (initiator) to the beginning of the new (target)
for (TaskDescriptor ot : oldEnd.getChildren()) {
newEnd.addChild(ot);
ot.getParents().remove(oldEnd);
ot.getParents().add(newEnd);
}
oldEnd.clearChildren();
// recreate the dependencies
for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
TaskId itId = it.getValue().getTaskInfo().getTaskId();
EligibleTaskDescriptorImpl down = acc.get(itId);
List<InternalTask> ideps = new ArrayList<>();
int deptype = 0;
if (it.getValue().hasDependences()) {
ideps.addAll(it.getValue().getIDependences());
}
if (it.getValue().getIfBranch() != null) {
deptype = 1;
ideps.add(it.getValue().getIfBranch());
}
if (it.getValue().getJoinedBranches() != null) {
deptype = 2;
ideps.addAll(it.getValue().getJoinedBranches());
}
if (ideps.size() > 0 && !target.equals(itId)) {
for (InternalTask parent : ideps) {
if (parent == null) {
continue;
}
EligibleTaskDescriptorImpl up = acc.get(parent.getTaskInfo().getTaskId());
switch(deptype) {
case 0:
if (parent.getId().equals(initiator)) {
up = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
}
up.addChild(down);
down.addParent(up);
break;
case 1:
case 2:
// 'weak' dependencies from FlowAction#IF are not
// represented in TaskDescriptor
branchTasks.put(down.getTaskId(), down);
break;
}
}
}
}
// EligibleTaskDescriptorImpl newTask = (EligibleTaskDescriptorImpl) acc.get(target.getId());
setNewLoopTaskToPausedIfJobIsPaused(newStart);
putNewLoopTaskIntoPausedOrEligableList(target.getId(), newStart);
runningTasks.remove(initiator);
}
use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl 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.EligibleTaskDescriptorImpl 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.EligibleTaskDescriptorImpl in project scheduling by ow2-proactive.
the class TaskResultCreatorTest method createParentTaskDescriptor.
private EligibleTaskDescriptorImpl createParentTaskDescriptor() {
EligibleTaskDescriptorImpl mockedEligibleTaskDescriptorImpl = mock(EligibleTaskDescriptorImpl.class);
TaskId parentId = this.createParentTaskID();
doReturn(parentId).when(mockedEligibleTaskDescriptorImpl).getTaskId();
return mockedEligibleTaskDescriptorImpl;
}
use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl in project scheduling by ow2-proactive.
the class JobDescriptorImplTest method testThatDoLoopPausesNewlyCreatedTasksIfJobIsPaused.
@Test
public void testThatDoLoopPausesNewlyCreatedTasksIfJobIsPaused() {
JobDescriptorImpl pausedJob = createEmptyJobDescriptor();
pausedJob.getInternal().setStatus(JobStatus.PAUSED);
// Create mocks for the loop root task
TaskId runningRootTaskId = TaskIdImpl.createTaskId(new JobIdImpl(1L, "Root"), "FirstLoopTask", 1L);
EligibleTaskDescriptorImpl mockLoopStartCurrentlyRunningTask = mock(EligibleTaskDescriptorImpl.class);
InternalTask mockInternalLoopRootTask = mock(InternalTask.class);
when(mockInternalLoopRootTask.getId()).thenReturn(runningRootTaskId);
when(mockLoopStartCurrentlyRunningTask.getTaskId()).thenReturn(runningRootTaskId);
when(mockLoopStartCurrentlyRunningTask.getInternal()).thenReturn(mockInternalLoopRootTask);
when(mockLoopStartCurrentlyRunningTask.getChildren()).thenReturn(new Vector<TaskDescriptor>());
// Create mocks for the new loop task
TaskId newLoopTaskId = TaskIdImpl.createTaskId(new JobIdImpl(1L, "Root"), "SecondLoopTask", 2L);
EligibleTaskDescriptorImpl mockLoopNewCreatedTaskForLoop = mock(EligibleTaskDescriptorImpl.class);
InternalTask mockInternalNewLoopTask = mock(InternalTask.class);
TaskInfo mockNewTaskTaskInfo = mock(TaskInfo.class);
when(mockNewTaskTaskInfo.getTaskId()).thenReturn(newLoopTaskId);
when(mockInternalNewLoopTask.getId()).thenReturn(newLoopTaskId);
when(mockInternalNewLoopTask.getStatus()).thenReturn(TaskStatus.SUBMITTED);
when(mockInternalNewLoopTask.getTaskInfo()).thenReturn(mockNewTaskTaskInfo);
when(mockLoopNewCreatedTaskForLoop.getTaskId()).thenReturn(newLoopTaskId);
when(mockLoopNewCreatedTaskForLoop.getInternal()).thenReturn(mockInternalNewLoopTask);
// Put the root loop task into running tasks, because it just terminated
pausedJob.getRunningTasks().put(mockLoopStartCurrentlyRunningTask.getTaskId(), mockLoopStartCurrentlyRunningTask);
// Put the new loop task into the Map, this is clue so that the test works
HashMap<TaskId, InternalTask> workflowTree = new HashMap<>();
workflowTree.put(newLoopTaskId, mockInternalNewLoopTask);
pausedJob.doLoop(mockLoopStartCurrentlyRunningTask.getTaskId(), workflowTree, mockLoopNewCreatedTaskForLoop.getInternal(), mockLoopNewCreatedTaskForLoop.getInternal());
verify(mockInternalNewLoopTask).setStatus(TaskStatus.PAUSED);
}
Aggregations