use of org.ow2.proactive.scheduler.common.task.flow.FlowAction 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.flow.FlowAction in project scheduling by ow2-proactive.
the class TaskResultData method createTaskResultData.
static TaskResultData createTaskResultData(TaskData taskRuntimeData, TaskResultImpl result) {
TaskResultData resultData = new TaskResultData();
resultData.setTaskRuntimeData(taskRuntimeData);
resultData.setLogs(result.getOutput());
resultData.setPreviewerClassName(result.getPreviewerClassName());
resultData.setMetadata(result.getMetadata());
resultData.setPropagatedVariables(result.getPropagatedVariables());
resultData.setSerializedException(result.getSerializedException());
resultData.setSerializedValue(result.getSerializedValue());
resultData.setResultTime(System.currentTimeMillis());
resultData.setRaw(result.isRaw());
FlowAction flowAction = result.getAction();
if (flowAction != null) {
FlowActionData actionData = new FlowActionData();
actionData.setDupNumber(flowAction.getDupNumber());
actionData.setTarget(flowAction.getTarget());
actionData.setTargetContinuation(flowAction.getTargetContinuation());
actionData.setTargetElse(flowAction.getTargetElse());
actionData.setType(flowAction.getType());
resultData.setFlowAction(actionData);
}
return resultData;
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowAction 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
* @param result result associated with the task
* @param taskIsInError If the task is in in-error state
* @return the taskDescriptor that has just been terminated.
*/
public ChangedTasksInfo terminateTask(boolean errorOccurred, TaskId taskId, SchedulerStateUpdate frontend, FlowAction action, TaskResultImpl result, boolean taskIsInError) {
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 (taskIsInError) {
setNumberOfInErrorTasks(getNumberOfInErrorTasks() - 1);
}
setNumberOfRunningTasks(getNumberOfRunningTasks() - 1);
setNumberOfFinishedTasks(getNumberOfFinishedTasks() + 1);
if ((getStatus() == JobStatus.RUNNING) && (getNumberOfRunningTasks() == 0) && !taskIsInError) {
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, taskIsInError);
}
return changesInfo;
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowAction 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;
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.
the class TerminateReplicateTaskHandlerTest method init.
@Before
public void init() {
action = new FlowAction(FlowActionType.REPLICATE);
action.setDupNumber(0);
MockitoAnnotations.initMocks(this);
when(internalJob.getJobInfo()).thenReturn(jobInfoImpl);
when(internalJob.getJobDescriptor()).thenReturn(jobDescriptorImpl);
terminateReplicateTaskHandler = new TerminateReplicateTaskHandler(internalJob);
}
Aggregations