use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class JobDescriptorImpl method terminate.
/**
* Update the eligible list of task and dependencies if necessary.
* This function considered that the taskId is in eligible task list.
* Visibility is package because user cannot use this method.
*
* @param taskId the task to remove from running task.
*/
public void terminate(TaskId taskId, boolean inErrorTask) {
Map<TaskId, ? extends TaskDescriptor> currentTasks = inErrorTask ? pausedTasks : runningTasks;
List<TaskId> taskIdsToSkip = new ArrayList<>();
if (getInternal().getType() == JobType.TASKSFLOW) {
TaskDescriptor taskToTerminate = currentTasks.get(taskId);
if (taskToTerminate != null) {
for (TaskDescriptor childTask : taskToTerminate.getChildren()) {
decreaseParentCount(childTask);
if (((EligibleTaskDescriptorImpl) childTask).getCount() == 0) {
if (internalJob.getStatus() == JobStatus.PAUSED) {
pausedTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
} else if (internalJob.getStatus() == JobStatus.IN_ERROR && ((EligibleTaskDescriptorImpl) childTask).getInternal().getStatus() == TaskStatus.PAUSED) {
pausedTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
} else if (((EligibleTaskDescriptorImpl) childTask).getInternal().getStatus() == TaskStatus.SKIPPED) {
runningTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
taskIdsToSkip.add(childTask.getTaskId());
} else {
eligibleTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
}
}
}
decreaseChildrenCountForAllParents(taskToTerminate);
}
}
currentTasks.remove(taskId);
for (TaskId taskIdToSkip : taskIdsToSkip) {
terminate(taskIdToSkip);
}
}
use of org.ow2.proactive.scheduler.common.task.TaskId 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.common.task.TaskId 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.task.TaskId 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.common.task.TaskId in project scheduling by ow2-proactive.
the class InternalJob method finishInErrorTask.
public ChangedTasksInfo finishInErrorTask(TaskId taskId, TaskResultImpl result, SchedulerStateUpdate frontend) {
FlowAction action = result.getAction();
ChangedTasksInfo changedTasksInfo = terminateTask(false, taskId, frontend, action, result, true);
setUnPause();
return changedTasksInfo;
}
Aggregations