use of org.ow2.proactive.scheduler.task.internal.InternalTask 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.findTaskUp(action.getTarget(), initiator);
}
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;
}
use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.
the class TerminateReplicateTaskHandler method terminateReplicateTask.
public boolean terminateReplicateTask(FlowAction action, InternalTask initiator, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend, TaskId taskId) {
int runs = action.getDupNumber();
logger.info("Control Flow Action REPLICATE (runs:" + runs + ")");
List<InternalTask> toReplicate = new ArrayList<>();
// find the tasks that need to be replicated
for (InternalTask internalTask : internalJob.getIHMTasks().values()) {
List<InternalTask> internalTaskDependencies = internalTask.getIDependences() == null ? new ArrayList<InternalTask>() : internalTask.getIDependences();
for (InternalTask internalTaskDependency : internalTaskDependencies) {
if (isTheInitiatorTask(initiator, toReplicate, internalTask, internalTaskDependency)) {
if (runs < 1) {
skipReplication(initiator, changesInfo, internalTask);
break;
} else {
toReplicate.add(internalTask);
}
}
}
}
// for each initial task to replicate
for (InternalTask internalTaskToReplicate : toReplicate) {
// determine the target of the replication whether it is a block or
// a single task
InternalTask target = null;
// target is a task block start : replication of the block
if (internalTaskToReplicate.getFlowBlock().equals(FlowBlock.START)) {
String tg = internalTaskToReplicate.getMatchingBlock();
for (InternalTask internalTask : internalJob.getIHMTasks().values()) {
if (tg.equals(internalTask.getName()) && !(internalTask.getStatus().equals(TaskStatus.FINISHED) || internalTask.getStatus().equals(TaskStatus.SKIPPED)) && internalTask.dependsOn(internalTaskToReplicate)) {
target = internalTask;
break;
}
}
if (target == null) {
logger.error("REPLICATE: could not find matching block '" + tg + "'");
continue;
}
} else // target is not a block : replication of the task
{
target = internalTaskToReplicate;
}
// for each number of parallel run
for (int i = 1; i < runs; i++) {
// accumulates the tasks between the initiator and the target
Map<TaskId, InternalTask> tasksBetweenInitiatorAndTarget = new HashMap<>();
// replicate the tasks between the initiator and the target
try {
target.replicateTree(tasksBetweenInitiatorAndTarget, internalTaskToReplicate.getId(), false, initiator.getReplicationIndex() * runs, 0);
} catch (Exception e) {
logger.error("REPLICATE: could not replicate tree", e);
break;
}
((JobInfoImpl) internalJob.getJobInfo()).setNumberOfPendingTasks(((JobInfoImpl) internalJob.getJobInfo()).getNumberOfPendingTasks() + tasksBetweenInitiatorAndTarget.size());
// pointers to the new replicated tasks corresponding the begin
// and
// the end of the block ; can be the same
InternalTask newTarget = null;
InternalTask newEnd = null;
// configure the new tasks
for (InternalTask internalTask : tasksBetweenInitiatorAndTarget.values()) {
internalTask.setJobInfo(((JobInfoImpl) internalJob.getJobInfo()));
int dupIndex = getNextReplicationIndex(InternalTask.getInitialName(internalTask.getName()), internalTask.getIterationIndex());
internalJob.addTask(internalTask);
internalTask.setReplicationIndex(dupIndex);
assignReplicationTag(internalTask, initiator, false, action);
}
changesInfo.newTasksAdded(tasksBetweenInitiatorAndTarget.values());
// find the beginning and the ending of the replicated block
for (Entry<TaskId, InternalTask> tasksBetweenInitiatorAndTargetEntry : tasksBetweenInitiatorAndTarget.entrySet()) {
InternalTask internalBlockTask = tasksBetweenInitiatorAndTargetEntry.getValue();
// initiator
if (internalTaskToReplicate.getId().equals(tasksBetweenInitiatorAndTargetEntry.getKey())) {
newTarget = internalBlockTask;
newTarget.addDependence(initiator);
// no need to add newTarget to modifiedTasks
// because newTarget is among dup.values(), and we
// have added them all
}
// connect the last task of the block with the merge task(s)
if (target.getId().equals(tasksBetweenInitiatorAndTargetEntry.getKey())) {
newEnd = internalBlockTask;
List<InternalTask> toAdd = new ArrayList<>();
// find the merge tasks ; can be multiple
for (InternalTask internalTask : internalJob.getIHMTasks().values()) {
List<InternalTask> pdeps = internalTask.getIDependences();
if (pdeps != null) {
for (InternalTask parent : pdeps) {
if (parent.getId().equals(target.getId())) {
toAdd.add(internalTask);
}
}
}
}
// connect the merge tasks
for (InternalTask internalTask : toAdd) {
internalTask.addDependence(newEnd);
changesInfo.taskUpdated(internalTask);
}
}
}
// propagate the changes on the JobDescriptor
internalJob.getJobDescriptor().doReplicate(taskId, tasksBetweenInitiatorAndTarget, newTarget, target.getId(), newEnd.getId());
}
}
// notify frontend that tasks were added to the job
((JobInfoImpl) internalJob.getJobInfo()).setTasksChanges(changesInfo, internalJob);
if (frontend != null) {
frontend.jobStateUpdated(internalJob.getOwner(), new NotificationData<>(SchedulerEvent.TASK_REPLICATED, internalJob.getJobInfo()));
frontend.jobStateUpdated(internalJob.getOwner(), new NotificationData<>(SchedulerEvent.TASK_SKIPPED, internalJob.getJobInfo()));
frontend.jobUpdatedFullData(internalJob);
}
((JobInfoImpl) internalJob.getJobInfo()).clearTasksChanges();
// no jump is performed ; now that the tasks have been replicated and
// configured, the flow can continue its normal operation
internalJob.getJobDescriptor().terminate(taskId);
return true;
}
use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.
the class RecoveredSchedulerStateTest method createJob.
public InternalJob createJob(JobStatus jobStatus, int id) {
InternalTaskFlowJob job = new InternalTaskFlowJob("MyJob", JobPriority.HIGH, OnTaskError.CANCEL_JOB, "Description");
InternalScriptTask internalScriptTask = new InternalScriptTask(job);
job.addTasks(ImmutableList.<InternalTask>of(internalScriptTask));
job.setId(JobIdImpl.makeJobId("" + id));
JobInfoImpl jobInfo = (JobInfoImpl) job.getJobInfo();
jobInfo.setStatus(jobStatus);
return job;
}
use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.
the class SchedulerStateRecoverHelperTest method changeTasksState.
private void changeTasksState(InternalJob job, Map<String, TaskStatus> newStatuses) {
int nbPending = 0;
int nbRunning = 0;
int nbFinished = 0;
for (InternalTask internalTask : job.getITasks()) {
TaskStatus newStatus = newStatuses.get(internalTask.getName());
if (newStatus != null) {
internalTask.setStatus(newStatus);
}
switch(internalTask.getStatus()) {
case PENDING:
nbPending++;
break;
case RUNNING:
nbRunning++;
break;
case FINISHED:
nbFinished++;
break;
}
}
updateJobCounters(job, nbPending, nbRunning, nbFinished);
}
use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.
the class SchedulerStateRecoverHelperTest method testRecoverWithCopyAndSortThrowingRuntimeException.
@Test
public void testRecoverWithCopyAndSortThrowingRuntimeException() throws KeyException, JobCreationException {
RecoveredSchedulerState recoveredState = new Scenario(createJob(JobStatus.RUNNING)).execute(new SchedulerStateRecoverHelperSupplier() {
@Override
public SchedulerStateRecoverHelper get(SchedulerDBManager dbManager) {
return new SchedulerStateRecoverHelper(dbManager) {
@Override
protected List<InternalTask> copyAndSort(List<InternalTask> tasks) {
throw new RuntimeException("bouh!");
}
};
}
}, false);
assertThat(recoveredState.getFinishedJobs()).hasSize(1);
assertThat(recoveredState.getPendingJobs()).hasSize(0);
assertThat(recoveredState.getRunningJobs()).hasSize(0);
assertThat(recoveredState.getFinishedJobs().get(0).getStatus()).isEqualTo(JobStatus.CANCELED);
}
Aggregations