Search in sources :

Example 26 with TaskId

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

the class LiveJobs method endJob.

private void endJob(JobData jobData, TerminationData terminationData, InternalTask task, TaskResultImpl taskResult, String errorMsg, JobStatus jobStatus) {
    JobId jobId = jobData.job.getId();
    jobs.remove(jobId);
    terminationData.addJobToTerminate(jobId);
    InternalJob job = jobData.job;
    SchedulerEvent event;
    if (job.getStatus() == JobStatus.PENDING) {
        event = SchedulerEvent.JOB_PENDING_TO_FINISHED;
    } else {
        event = SchedulerEvent.JOB_RUNNING_TO_FINISHED;
    }
    if (task != null) {
        jlogger.info(job.getId(), "ending request caused by task " + task.getId());
    } else {
        jlogger.info(job.getId(), "ending request");
    }
    for (Iterator<RunningTaskData> i = runningTasksData.values().iterator(); i.hasNext(); ) {
        RunningTaskData taskData = i.next();
        if (taskData.getTask().getJobId().equals(jobId)) {
            i.remove();
            // remove previous read progress
            taskData.getTask().setProgress(0);
            terminationData.addTaskData(job, taskData, TerminationData.TerminationStatus.ABORTED, taskResult);
        }
    }
    // if job has been killed
    if (jobStatus == JobStatus.KILLED) {
        Set<TaskId> tasksToUpdate = job.failed(null, jobStatus);
        dbManager.updateAfterJobKilled(job, tasksToUpdate);
        updateTasksInSchedulerState(job, tasksToUpdate);
    } else {
        // finished state (failed/canceled)
        if (jobStatus != JobStatus.FINISHED) {
            Set<TaskId> tasksToUpdate = job.failed(task.getId(), jobStatus);
            // store the exception into jobResult / To prevent from empty
            // task result (when job canceled), create one
            boolean noResult = (jobStatus == JobStatus.CANCELED && taskResult == null);
            if (jobStatus == JobStatus.FAILED || noResult) {
                taskResult = new TaskResultImpl(task.getId(), new Exception(errorMsg), new SimpleTaskLogs("", errorMsg), -1);
            }
            dbManager.updateAfterJobFailed(job, task, taskResult, tasksToUpdate);
            updateTasksInSchedulerState(job, tasksToUpdate);
        }
    }
    // update job and tasks events list and send it to front-end
    updateJobInSchedulerState(job, event);
    jlogger.info(job.getId(), "finished (" + jobStatus + ")");
}
Also used : SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId) TaskAbortedException(org.ow2.proactive.scheduler.common.exception.TaskAbortedException) TaskPreemptedException(org.ow2.proactive.scheduler.common.exception.TaskPreemptedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskRestartedException(org.ow2.proactive.scheduler.common.exception.TaskRestartedException) SchedulerEvent(org.ow2.proactive.scheduler.common.SchedulerEvent)

Example 27 with TaskId

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

the class LiveJobs method restartWaitingTask.

void restartWaitingTask(TaskId taskId) {
    JobData jobData = lockJob(taskId.getJobId());
    if (jobData == null) {
        return;
    }
    try {
        InternalTask task = jobData.job.getTask(taskId);
        if (!task.getStatus().isTaskAlive()) {
            tlogger.warn(taskId, "task to be restarted isn't alive " + task.getStatus());
            return;
        }
        jobData.job.reStartTask(task);
    } catch (UnknownTaskException e) {
        logger.error("Unexpected exception", e);
    } finally {
        jobData.unlock();
    }
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Example 28 with TaskId

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

the class LiveJobs method resumeJob.

boolean resumeJob(JobId jobId) {
    JobData jobData = lockJob(jobId);
    if (jobData == null) {
        return false;
    }
    try {
        InternalJob job = jobData.job;
        Set<TaskId> updatedTasks = job.setUnPause();
        if (!updatedTasks.isEmpty()) {
            jlogger.info(jobId, "has just been resumed.");
            dbManager.updateJobAndTasksState(job);
            updateTasksInSchedulerState(job, updatedTasks);
        }
        // update tasks events list and send it to front-end
        updateJobInSchedulerState(job, SchedulerEvent.JOB_RESUMED);
        return !updatedTasks.isEmpty();
    } finally {
        jobData.unlock();
    }
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId)

Example 29 with TaskId

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

the class LiveJobs method restartTaskOnNodeFailure.

TerminationData restartTaskOnNodeFailure(InternalTask task) {
    JobData jobData = lockJob(task.getJobId());
    if (jobData == null) {
        return emptyResult(task.getId());
    }
    try {
        TaskId taskId = task.getId();
        if (task.getStatus() != TaskStatus.RUNNING) {
            return emptyResult(taskId);
        }
        RunningTaskData taskData = runningTasksData.remove(TaskIdWrapper.wrap(taskId));
        if (taskData == null) {
            throw new IllegalStateException("Task " + task.getId() + " is not running.");
        }
        TerminationData result = TerminationData.newTerminationData();
        result.addTaskData(jobData.job, taskData, TerminationData.TerminationStatus.NODEFAILED, null);
        restartTaskOnNodeFailure(task, jobData, result);
        return result;
    } finally {
        jobData.unlock();
    }
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId)

Example 30 with TaskId

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

the class LiveJobs method updateTasksInSchedulerState.

private void updateTasksInSchedulerState(InternalJob job, Set<TaskId> tasksToUpdate) {
    for (TaskId tid : tasksToUpdate) {
        try {
            InternalTask t = job.getTask(tid);
            TaskInfo ti = new TaskInfoImpl((TaskInfoImpl) t.getTaskInfo());
            listener.taskStateUpdated(job.getOwner(), new NotificationData<>(SchedulerEvent.TASK_RUNNING_TO_FINISHED, ti));
        } catch (UnknownTaskException e) {
            logger.error(e);
        }
    }
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl)

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