Search in sources :

Example 51 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId 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;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InvalidPatternException(it.sauronsoftware.cron4j.InvalidPatternException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Predictor(it.sauronsoftware.cron4j.Predictor) Date(java.util.Date)

Example 52 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId 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;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Example 53 with TaskId

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

the class InternalTask method loadAuthorizedScriptsSignatures.

private static void loadAuthorizedScriptsSignatures(TaskId id, File folder) {
    authorizedSelectionScripts = new HashSet<>();
    for (File file : folder.listFiles()) {
        if (file.isFile()) {
            try {
                String script = Script.readFile(file);
                logger.debug(id, "Adding authorized script " + file.getAbsolutePath());
                authorizedSelectionScripts.add(Script.digest(script.trim()));
            } catch (Exception e) {
                logger.error(id, e.getMessage(), e);
            }
        }
    }
}
Also used : File(java.io.File) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) NodeException(org.objectweb.proactive.core.node.NodeException) ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException)

Example 54 with TaskId

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

the class ServerJobAndTaskLogs method getJobLog.

public static String getJobLog(JobId jobId, Set<TaskId> tasks) {
    String jobLog = readLog(JobLogger.getJobLogRelativePath(jobId));
    if (jobLog == null) {
        return "Cannot retrieve logs for job " + jobId;
    }
    StringBuilder result = new StringBuilder();
    result.append("================= Job ").append(jobId).append(" logs =================\n");
    result.append(jobLog);
    for (TaskId taskId : tasks) {
        result.append("\n================ Task ").append(taskId).append(" logs =================\n");
        result.append(getTaskLog(taskId));
    }
    return result.toString();
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId)

Example 55 with TaskId

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

the class TestLoadJobsPagination method testSorting.

@Test
public void testSorting() throws Exception {
    // 1
    InternalJob job1 = defaultSubmitJob(createJob("A", JobPriority.IDLE), "user_a");
    // 2
    defaultSubmitJob(createJob("B", JobPriority.LOWEST), "user_b");
    // 3
    InternalJob job3 = defaultSubmitJob(createJob("C", JobPriority.LOW), "user_c");
    // 4
    defaultSubmitJob(createJob("A", JobPriority.NORMAL), "user_d");
    // 5
    InternalJob job5 = defaultSubmitJob(createJob("B", JobPriority.HIGH), "user_e");
    // 6
    defaultSubmitJob(createJob("C", JobPriority.HIGHEST), "user_f");
    // change status for some jobs
    job1.failed(null, JobStatus.KILLED);
    dbManager.updateAfterJobKilled(job1, Collections.<TaskId>emptySet());
    job3.setPaused();
    dbManager.updateJobAndTasksState(job3);
    job5.start();
    InternalTask taskJob5 = startTask(job5, job5.getITasks().get(0));
    dbManager.jobTaskStarted(job5, taskJob5, true);
    List<JobInfo> jobs;
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.ID, SortOrder.DESC))).getList();
    checkJobs(jobs, 6, 5, 4, 3, 2, 1);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.NAME, SortOrder.ASC), new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 4, 2, 5, 3, 6);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.NAME, SortOrder.ASC), new SortParameter<>(JobSortParameter.ID, SortOrder.DESC))).getList();
    checkJobs(jobs, 4, 1, 5, 2, 6, 3);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.OWNER, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.OWNER, SortOrder.DESC))).getList();
    checkJobs(jobs, 6, 5, 4, 3, 2, 1);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.PRIORITY, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.PRIORITY, SortOrder.DESC))).getList();
    checkJobs(jobs, 6, 5, 4, 3, 2, 1);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.STATE, SortOrder.ASC), new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    checkJobs(jobs, 2, 4, 6, 3, 5, 1);
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters(new SortParameter<>(JobSortParameter.STATE, SortOrder.DESC), new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    checkJobs(jobs, 1, 3, 5, 2, 4, 6);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) JobSortParameter(org.ow2.proactive.scheduler.common.JobSortParameter) SortParameter(org.ow2.proactive.db.SortParameter) Test(org.junit.Test)

Aggregations

TaskId (org.ow2.proactive.scheduler.common.task.TaskId)100 Test (org.junit.Test)43 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)43 JobId (org.ow2.proactive.scheduler.common.job.JobId)33 ArrayList (java.util.ArrayList)27 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)25 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)22 HashMap (java.util.HashMap)18 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)18 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)15 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)12 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)12 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)11 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)11 List (java.util.List)10 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)9 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)9