use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.
the class StartAtUpdater method updateStartAtAndTasksScheduledTime.
private Set<TaskId> updateStartAtAndTasksScheduledTime(InternalJob job, String startAt, long scheduledTime) {
List<InternalTask> internalTasks = job.getITasks();
Set<TaskId> updatedTasks = new HashSet<>(internalTasks.size());
if (resetJobGenericInformation(job, startAt)) {
for (InternalTask td : internalTasks) {
td.setScheduledTime(scheduledTime);
updatedTasks.add(td.getId());
job.getJobDescriptor().updateTaskScheduledTime(td.getId(), scheduledTime);
}
}
return updatedTasks;
}
use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.
the class TaskResultCreator method getTaskResult.
public TaskResultImpl getTaskResult(SchedulerDBManager dbManager, InternalJob job, InternalTask task, Throwable exception, TaskLogs output) throws UnknownTaskException {
if (task == null) {
throw new UnknownTaskException();
}
JobDescriptor jobDescriptor = job.getJobDescriptor();
EligibleTaskDescriptor eligibleTaskDescriptor = null;
if (jobDescriptor.getPausedTasks().get(task.getId()) != null) {
eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getPausedTasks().get(task.getId());
} else if (jobDescriptor.getRunningTasks().get(task.getId()) != null) {
eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getRunningTasks().get(task.getId());
}
TaskResultImpl taskResult = getEmptyTaskResult(task, exception, output);
taskResult.setPropagatedVariables(getPropagatedVariables(dbManager, eligibleTaskDescriptor, job, task));
return taskResult;
}
use of org.ow2.proactive.scheduler.task.internal.InternalTask 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.task.internal.InternalTask 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.task.internal.InternalTask in project scheduling by ow2-proactive.
the class InternalJob method replicateForNextLoopIteration.
public boolean replicateForNextLoopIteration(InternalTask initiator, InternalTask target, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend, FlowAction action) {
LOGGER.info("LOOP (init:" + initiator.getId() + "; target:" + target.getId() + ")");
// accumulates the tasks between the initiator and the target
Map<TaskId, InternalTask> dup = new HashMap<>();
// replicate the tasks between the initiator and the target
try {
initiator.replicateTree(dup, target.getId(), true, initiator.getReplicationIndex(), initiator.getIterationIndex());
} catch (ExecutableCreationException e) {
LOGGER.error("", e);
return false;
}
((JobInfoImpl) this.getJobInfo()).setNumberOfPendingTasks(this.getJobInfo().getNumberOfPendingTasks() + dup.size());
// time-consuming but safe
for (InternalTask nt : dup.values()) {
boolean ok;
do {
ok = true;
for (InternalTask task : tasks.values()) {
if (nt.getName().equals(task.getName())) {
nt.setIterationIndex(nt.getIterationIndex() + 1);
ok = false;
}
}
} while (!ok);
}
// configure the new tasks
InternalTask newTarget = null;
InternalTask newInit = null;
for (Entry<TaskId, InternalTask> it : dup.entrySet()) {
InternalTask nt = it.getValue();
if (target.getId().equals(it.getKey())) {
newTarget = nt;
}
if (initiator.getId().equals(it.getKey())) {
newInit = nt;
}
nt.setJobInfo(getJobInfo());
this.addTask(nt);
assignReplicationTag(nt, initiator, true, action);
}
changesInfo.newTasksAdded(dup.values());
// connect replicated tree
newTarget.addDependence(initiator);
changesInfo.taskUpdated(newTarget);
// connect mergers
List<InternalTask> mergers = new ArrayList<>();
for (InternalTask t : this.tasks.values()) {
if (t.getIDependences() != null) {
for (InternalTask p : t.getIDependences()) {
if (p.getId().equals(initiator.getId())) {
if (!t.equals(newTarget)) {
mergers.add(t);
}
}
}
}
}
for (InternalTask t : mergers) {
t.getIDependences().remove(initiator);
t.addDependence(newInit);
changesInfo.taskUpdated(t);
}
// propagate the changes in the job descriptor
getJobDescriptor().doLoop(initiator.getId(), dup, newTarget, newInit);
this.jobInfo.setTasksChanges(changesInfo, this);
// notify frontend that tasks were added and modified
frontend.jobStateUpdated(this.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.TASK_REPLICATED, new JobInfoImpl(jobInfo)));
frontend.jobUpdatedFullData(this);
this.jobInfo.clearTasksChanges();
return true;
}
Aggregations