Search in sources :

Example 11 with SimpleTaskLogs

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

the class LiveJobs method restartTask.

TerminationData restartTask(JobId jobId, String taskName, int restartDelay) throws UnknownJobException, UnknownTaskException {
    JobData jobData = lockJob(jobId);
    if (jobData == null) {
        throw new UnknownJobException(jobId);
    }
    try {
        InternalTask task = jobData.job.getTask(taskName);
        tlogger.info(task.getId(), "restarting task " + task.getId());
        if (!task.getStatus().isTaskAlive()) {
            tlogger.warn(task.getId(), "task isn't alive: " + task.getStatus());
            return emptyResult(task.getId());
        }
        TaskIdWrapper taskIdWrapper = TaskIdWrapper.wrap(task.getId());
        RunningTaskData taskData = runningTasksData.remove(taskIdWrapper);
        if (taskData == null) {
            throw new IllegalStateException("Task " + task.getId() + " is not running.");
        }
        TaskResultImpl taskResult = taskResultCreator.getTaskResult(dbManager, jobData.job, task, new TaskRestartedException("Aborted by user"), new SimpleTaskLogs("", "Aborted by user"));
        TerminationData terminationData = createAndFillTerminationData(taskResult, taskData, jobData.job, TerminationData.TerminationStatus.ABORTED);
        task.decreaseNumberOfExecutionLeft();
        if (task.getNumberOfExecutionLeft() <= 0 && onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
            endJob(jobData, terminationData, task, taskResult, "An error occurred in your task and the maximum number of executions has been reached. " + "You also ask to cancel the job in such a situation !", JobStatus.CANCELED);
            return terminationData;
        } else if (task.getNumberOfExecutionLeft() > 0) {
            long waitTime = restartDelay * 1000l;
            restartTaskOnError(jobData, task, TaskStatus.WAITING_ON_ERROR, taskResult, waitTime, terminationData);
            return terminationData;
        }
        terminateTask(jobData, task, true, taskResult, terminationData);
        return terminationData;
    } finally {
        jobData.unlock();
    }
}
Also used : SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) TaskIdWrapper(org.ow2.proactive.utils.TaskIdWrapper) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskRestartedException(org.ow2.proactive.scheduler.common.exception.TaskRestartedException)

Aggregations

SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)11 Test (org.junit.Test)5 InetSocketAddress (java.net.InetSocketAddress)4 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)4 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)4 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)4 TaskAbortedException (org.ow2.proactive.scheduler.common.exception.TaskAbortedException)2 TaskPreemptedException (org.ow2.proactive.scheduler.common.exception.TaskPreemptedException)2 TaskRestartedException (org.ow2.proactive.scheduler.common.exception.TaskRestartedException)2 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)2 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)2 ImmediateService (org.objectweb.proactive.annotation.ImmediateService)1 DatabaseManagerException (org.ow2.proactive.db.DatabaseManagerException)1 SchedulerEvent (org.ow2.proactive.scheduler.common.SchedulerEvent)1 TaskCouldNotRestartException (org.ow2.proactive.scheduler.common.exception.TaskCouldNotRestartException)1 TaskCouldNotStartException (org.ow2.proactive.scheduler.common.exception.TaskCouldNotStartException)1 TaskSkippedException (org.ow2.proactive.scheduler.common.exception.TaskSkippedException)1 JobId (org.ow2.proactive.scheduler.common.job.JobId)1