Search in sources :

Example 16 with FlowAction

use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.

the class TerminateIfTaskHandler method terminateIfTask.

public boolean terminateIfTask(FlowAction action, InternalTask initiator, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend, InternalTask descriptor, TaskId taskId) {
    InternalTask[] targets = searchIfElseJoinTasks(action, initiator);
    // the targetIf from action getTarget is the selected branch
    // the IF condition has already been evaluated prior to being put in a
    // FlowAction
    // the targetElse from action getTargetElse is the branch that was NOT
    // selected
    InternalTask targetIf = targets[0];
    InternalTask targetElse = targets[1];
    InternalTask targetJoin = targets[2];
    LOGGER.info("Control Flow Action IF: " + targetIf.getId() + " join: " + ((targetJoin == null) ? "null" : targetJoin.getId()));
    // these 2 tasks delimit the Task Block formed by the IF branch
    InternalTask branchStart = targetIf;
    InternalTask branchEnd = null;
    String match = targetIf.getMatchingBlock();
    if (match != null) {
        for (InternalTask t : internalJob.getIHMTasks().values()) {
            if (match.equals(t.getName()) && !(t.getStatus().equals(TaskStatus.FINISHED) || t.getStatus().equals(TaskStatus.SKIPPED))) {
                branchEnd = t;
            }
        }
    }
    // no matching block: there is no block, the branch is a single task
    if (branchEnd == null) {
        branchEnd = targetIf;
    }
    // plug the branch
    branchStart.addDependence(initiator);
    changesInfo.taskUpdated(branchStart);
    if (targetJoin != null) {
        targetJoin.addDependence(branchEnd);
        changesInfo.taskUpdated(targetJoin);
    }
    // the other branch will not be executed
    // first, find the concerned tasks
    List<InternalTask> elseTasks = new ArrayList<>();
    // elseTasks.add(targetElse);
    for (InternalTask t : internalJob.getIHMTasks().values()) {
        if (t.dependsOn(targetElse)) {
            elseTasks.add(t);
        }
    }
    // even though the targetElse is not going to be executed, a
    // dependency on initiator still makes sense and would help
    // reconstruct the job graph on the client
    targetElse.addDependence(initiator);
    changesInfo.taskUpdated(targetElse);
    for (InternalTask it : elseTasks) {
        it.setFinishedTime(descriptor.getFinishedTime() + 1);
        it.setStatus(TaskStatus.SKIPPED);
        it.setExecutionDuration(0);
        changesInfo.taskSkipped(it);
        internalJob.setNumberOfPendingTasks(internalJob.getNumberOfPendingTasks() - 1);
        internalJob.setNumberOfFinishedTasks(internalJob.getNumberOfFinishedTasks() + 1);
        LOGGER.info("Task " + it.getId() + " will not be executed");
    }
    // plug the branch in the descriptor
    TaskId joinId = null;
    if (targetJoin != null) {
        joinId = targetJoin.getId();
    }
    internalJob.getJobDescriptor().doIf(initiator.getId(), branchStart.getId(), branchEnd.getId(), joinId, targetElse.getId(), elseTasks);
    ((JobInfoImpl) internalJob.getJobInfo()).setTasksChanges(changesInfo, internalJob);
    // notify frontend that tasks were modified
    if (frontend != null) {
        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 plugged
    // the flow can continue its normal operation
    internalJob.getJobDescriptor().terminate(taskId);
    return true;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Example 17 with FlowAction

use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.

the class SchedulingServiceTest7 method testTaskReplication.

@Test
public void testTaskReplication() throws Exception {
    service.submitJob(createJob(createTestJob()));
    listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
    Map<JobId, JobDescriptor> jobsMap;
    JobDescriptor jobDesc;
    jobsMap = service.lockJobsToSchedule();
    assertEquals(1, jobsMap.size());
    jobDesc = jobsMap.values().iterator().next();
    Assert.assertEquals(1, jobDesc.getEligibleTasks().size());
    for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
        taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
    }
    service.unlockJobsToSchedule(jobsMap.values());
    listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING);
    TaskId taskId;
    taskId = ((JobDescriptorImpl) jobDesc).getInternal().getTask("Main task").getId();
    TaskResultImpl result = new TaskResultImpl(taskId, "OK", null, 0);
    FlowAction action = new FlowAction(FlowActionType.REPLICATE);
    action.setDupNumber(3);
    result.setAction(action);
    service.taskTerminatedWithResult(taskId, result);
    listener.assertEvents(SchedulerEvent.TASK_REPLICATED, SchedulerEvent.TASK_SKIPPED, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_RUNNING_TO_FINISHED);
    jobsMap = service.lockJobsToSchedule();
    assertEquals(1, jobsMap.size());
    jobDesc = jobsMap.values().iterator().next();
    Assert.assertEquals(3, jobDesc.getEligibleTasks().size());
    for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
        taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
    }
    service.unlockJobsToSchedule(jobsMap.values());
    listener.assertEvents(SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING);
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 18 with FlowAction

use of org.ow2.proactive.scheduler.common.task.flow.FlowAction in project scheduling by ow2-proactive.

the class TaskResultData method toTaskResult.

TaskResultImpl toTaskResult(TaskId taskId) {
    TaskResultImpl result = new TaskResultImpl(taskId, getSerializedValue(), getSerializedException(), getLogs(), getMetadata(), getPropagatedVariables(), isRaw());
    result.setPreviewerClassName(getPreviewerClassName());
    FlowActionData actionData = getFlowAction();
    if (actionData != null) {
        FlowAction action = new FlowAction(actionData.getType());
        action.setDupNumber(actionData.getDupNumber());
        action.setTarget(actionData.getTarget());
        action.setTargetContinuation(actionData.getTargetContinuation());
        action.setTargetElse(actionData.getTargetElse());
        result.setAction(action);
    }
    return result;
}
Also used : TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction)

Aggregations

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)11 FlowAction (org.ow2.proactive.scheduler.common.task.flow.FlowAction)10 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)6 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)4 HashMap (java.util.HashMap)3 ChangedTasksInfo (org.ow2.proactive.scheduler.job.ChangedTasksInfo)3 InvalidPatternException (it.sauronsoftware.cron4j.InvalidPatternException)2 Predictor (it.sauronsoftware.cron4j.Predictor)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)2 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)2 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)2 JobInfoImpl (org.ow2.proactive.scheduler.job.JobInfoImpl)2 Date (java.util.Date)1 Before (org.junit.Before)1 JobDescriptor (org.ow2.proactive.scheduler.common.JobDescriptor)1 ExecutableCreationException (org.ow2.proactive.scheduler.common.exception.ExecutableCreationException)1