Search in sources :

Example 11 with ChangedTasksInfo

use of org.ow2.proactive.scheduler.job.ChangedTasksInfo in project scheduling by ow2-proactive.

the class TestRestoreWorkflowJobs method finishedJobWithScriptsCanBeRecoveredAndLoaded.

@Test
public void finishedJobWithScriptsCanBeRecoveredAndLoaded() throws Exception {
    InternalJob job = defaultSubmitJobAndLoadInternal(true, createJobWithAllKindOfScripts());
    job.start();
    InternalTask mainTask = job.getTask("T");
    startTask(job, mainTask);
    dbManager.jobTaskStarted(job, mainTask, true);
    TaskResultImpl result = new TaskResultImpl(mainTask.getId(), "ok", null, 0);
    ChangedTasksInfo changesInfo = job.terminateTask(false, mainTask.getId(), null, null, result);
    job.setStatus(JobStatus.FINISHED);
    dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
    SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
    JobStateMatcher expectedJob = job(job.getId(), JobStatus.FINISHED).withFinished(task("T", TaskStatus.FINISHED).checkFinished(), true);
    checkRecoveredState(recoverHelper.recover(-1), state().withFinished(expectedJob));
    List<InternalJob> finishedJobs = dbManager.loadFinishedJobs(true, -1);
    assertEquals(1, finishedJobs.size());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) ChangedTasksInfo(org.ow2.proactive.scheduler.job.ChangedTasksInfo) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) Test(org.junit.Test)

Example 12 with ChangedTasksInfo

use of org.ow2.proactive.scheduler.job.ChangedTasksInfo in project scheduling by ow2-proactive.

the class LiveJobs method finishInErrorTask.

TerminationData finishInErrorTask(JobId jobId, String taskName) throws UnknownTaskException, UnknownJobException {
    JobData jobData = lockJob(jobId);
    if (jobData == null) {
        throw new UnknownJobException(jobId);
    }
    InternalJob job = jobData.job;
    try {
        InternalTask task = job.getTask(taskName);
        if (task == null) {
            throw new UnknownTaskException(taskName);
        }
        TaskId taskId = task.getId();
        if (task.getStatus() != TaskStatus.IN_ERROR) {
            tlogger.info(task.getId(), "Task must be in state IN_ERROR: " + task.getStatus());
            return emptyResult(task.getId());
        }
        TaskResultImpl taskResult = taskResultCreator.getTaskResult(dbManager, job, task);
        RunningTaskData data = new RunningTaskData(task, job.getOwner(), job.getCredentials(), task.getExecuterInformation().getLauncher());
        TerminationData terminationData = TerminationData.newTerminationData();
        terminationData.addTaskData(job, data, TerminationData.TerminationStatus.ABORTED, taskResult);
        tlogger.debug(taskId, "result added to job " + job.getId());
        // to be done before terminating the task, once terminated it is not
        // running anymore..
        ChangedTasksInfo changesInfo = job.finishInErrorTask(taskId, taskResult, listener);
        boolean jobFinished = job.isFinished();
        // update job info if it is terminated
        if (jobFinished) {
            // terminating job
            job.terminate();
            jlogger.debug(job.getId(), "terminated");
            jobs.remove(job.getId());
            terminationData.addJobToTerminate(job.getId());
        }
        // Update database
        if (taskResult.getAction() != null) {
            dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, taskResult);
        } else {
            dbManager.updateAfterTaskFinished(job, task, taskResult);
        }
        // send event
        listener.taskStateUpdated(job.getOwner(), new NotificationData<TaskInfo>(SchedulerEvent.TASK_IN_ERROR_TO_FINISHED, new TaskInfoImpl((TaskInfoImpl) task.getTaskInfo())));
        // if this job is finished (every task have finished)
        jlogger.info(job.getId(), "finished tasks " + job.getNumberOfFinishedTasks() + ", total tasks " + job.getTotalNumberOfTasks() + ", finished " + jobFinished);
        if (jobFinished) {
            // send event to client
            listener.jobStateUpdated(job.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.JOB_RUNNING_TO_FINISHED, new JobInfoImpl((JobInfoImpl) job.getJobInfo())));
            listener.jobUpdatedFullData(job);
        }
        return terminationData;
    } finally {
        jobData.unlock();
    }
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ChangedTasksInfo(org.ow2.proactive.scheduler.job.ChangedTasksInfo) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl) TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Example 13 with ChangedTasksInfo

use of org.ow2.proactive.scheduler.job.ChangedTasksInfo in project scheduling by ow2-proactive.

the class LiveJobs method terminateTask.

private void terminateTask(JobData jobData, InternalTask task, boolean errorOccurred, TaskResultImpl result, TerminationData terminationData) {
    InternalJob job = jobData.job;
    TaskId taskId = task.getId();
    tlogger.debug(taskId, "result added to job " + job.getId());
    // to be done before terminating the task, once terminated it is not
    // running anymore..
    job.getRunningTaskDescriptor(taskId);
    ChangedTasksInfo changesInfo = job.terminateTask(errorOccurred, taskId, listener, result.getAction(), result);
    boolean jobFinished = job.isFinished();
    // update job info if it is terminated
    if (jobFinished) {
        // terminating job
        job.terminate();
        jlogger.debug(job.getId(), "terminated");
        terminationData.addJobToTerminate(job.getId());
    }
    // Update database
    if (result.getAction() != null) {
        dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
    } else {
        dbManager.updateAfterTaskFinished(job, task, result);
    }
    // send event
    listener.taskStateUpdated(job.getOwner(), new NotificationData<TaskInfo>(SchedulerEvent.TASK_RUNNING_TO_FINISHED, new TaskInfoImpl((TaskInfoImpl) task.getTaskInfo())));
    // if this job is finished (every task have finished)
    jlogger.info(job.getId(), "finished tasks " + job.getNumberOfFinishedTasks() + ", total tasks " + job.getTotalNumberOfTasks() + ", finished " + jobFinished);
    if (jobFinished) {
        // send event to client
        listener.jobStateUpdated(job.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.JOB_RUNNING_TO_FINISHED, new JobInfoImpl((JobInfoImpl) job.getJobInfo())));
        listener.jobUpdatedFullData(job);
    }
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ChangedTasksInfo(org.ow2.proactive.scheduler.job.ChangedTasksInfo) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Aggregations

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