use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.
the class TestRestoreWorkflowJobs2 method test.
@Test
public void test() throws Exception {
TaskFlowJob jobDef = createJob();
InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
job.start();
InternalTask mainTask = job.getTask("A");
startTask(job, mainTask);
dbManager.jobTaskStarted(job, mainTask, true);
TaskResultImpl result = new TaskResultImpl(mainTask.getId(), "ok", null, 0);
FlowAction action = new FlowAction(FlowActionType.IF);
action.setDupNumber(1);
action.setTarget("B");
action.setTargetElse("C");
ChangedTasksInfo changesInfo = job.terminateTask(false, mainTask.getId(), null, action, result);
dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
RecoveredSchedulerState state = recoverHelper.recover(-1);
job = state.getRunningJobs().get(0);
System.out.println("OK");
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.
the class TestRestoreWorkflowJobs method test.
@Test
public void test() throws Exception {
TaskFlowJob jobDef = createJob();
InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
job.start();
InternalTask mainTask = job.getTask("T");
startTask(job, mainTask);
dbManager.jobTaskStarted(job, mainTask, true);
TaskResultImpl result = new TaskResultImpl(mainTask.getId(), "ok", null, 0);
FlowAction action = new FlowAction(FlowActionType.REPLICATE);
action.setDupNumber(2);
ChangedTasksInfo changesInfo = job.terminateTask(false, mainTask.getId(), null, action, result);
dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
JobStateMatcher expectedJob;
expectedJob = job(job.getId(), JobStatus.STALLED).withFinished(task("T", TaskStatus.FINISHED).checkFinished(), true).withPending(task("T1", TaskStatus.SUBMITTED), true).withPending(task("T1*1", TaskStatus.SUBMITTED), true).withPending(task("T2", TaskStatus.SUBMITTED), true).withPending(task("T3", TaskStatus.SUBMITTED), true).withPending(task("T2*1", TaskStatus.SUBMITTED), true).withPending(task("T3*1", TaskStatus.SUBMITTED), true).withPending(task("T4", TaskStatus.SUBMITTED), true).withEligible("T1", "T1*1");
checkRecoveredState(recoverHelper.recover(-1), state().withRunning(expectedJob));
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.
the class TagTest method execute.
private void execute(InternalTask task) {
task.setExecuterInformation(executerInformationMock);
job.startTask(task);
FlowScript script = task.getFlowScript();
FlowAction action = null;
if (script != null) {
action = task.getFlowScript().execute().getResult();
}
job.terminateTask(false, task.getId(), schedulerStateUpdateMock, action, resultMock);
System.out.println("executed " + task.getName() + " -> " + getTaskNameList(true));
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowAction 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;
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.
the class TerminateLoopHandler method terminateLoopTask.
public boolean terminateLoopTask(FlowAction action, InternalTask initiator, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend) {
// find the target of the loop
InternalTask target = null;
if (action.getTarget().equals(initiator.getName())) {
target = initiator;
} else {
target = internalJob.findTask(action.getTarget());
}
boolean replicateForNextLoopIteration = internalJob.replicateForNextLoopIteration(initiator, target, changesInfo, frontend, action);
if (replicateForNextLoopIteration && action.getCronExpr() != null) {
for (TaskId tid : changesInfo.getNewTasks()) {
InternalTask newTask = internalJob.getIHMTasks().get(tid);
try {
Date startAt = (new Predictor(action.getCronExpr())).nextMatchingDate();
newTask.addGenericInformation(InternalJob.GENERIC_INFO_START_AT_KEY, ISO8601DateUtil.parse(startAt));
newTask.setScheduledTime(startAt.getTime());
} catch (InvalidPatternException e) {
// this will not happen as the cron expression is
// already being validated in FlowScript class.
LOGGER.debug(e.getMessage());
}
}
}
return replicateForNextLoopIteration;
}
Aggregations