Search in sources :

Example 1 with TaskIdWrapper

use of org.ow2.proactive.utils.TaskIdWrapper in project scheduling by ow2-proactive.

the class LiveJobs method taskTerminatedWithResult.

public TerminationData taskTerminatedWithResult(TaskId taskId, TaskResultImpl result) {
    JobData jobData = lockJob(taskId.getJobId());
    if (jobData == null) {
        return emptyResult(taskId);
    }
    try {
        InternalTask task;
        try {
            task = jobData.job.getTask(taskId);
        } catch (UnknownTaskException e) {
            logger.error("Unexpected exception", e);
            return emptyResult(taskId);
        }
        if (task.getStatus() != TaskStatus.RUNNING) {
            tlogger.info(taskId, "task isn't running anymore");
            return emptyResult(taskId);
        }
        TaskIdWrapper taskIdWrapper = TaskIdWrapper.wrap(taskId);
        RunningTaskData taskData = runningTasksData.remove(taskIdWrapper);
        if (taskData == null) {
            tlogger.info(taskId, "Task " + taskId + " terminates after a recovery of the scheduler");
            taskData = new RunningTaskData(task, jobData.job.getOwner(), jobData.job.getCredentials(), task.getExecuterInformation().getLauncher());
        }
        TerminationData terminationData = createAndFillTerminationData(result, taskData, jobData.job, TerminationData.TerminationStatus.NORMAL);
        boolean errorOccurred = result.hadException();
        tlogger.info(taskId, "finished with" + (errorOccurred ? "" : "out") + " errors");
        if (errorOccurred) {
            tlogger.error(taskId, "task has terminated with an error", result.getException());
            task.decreaseNumberOfExecutionLeft();
            boolean requiresPauseJobOnError = onErrorPolicyInterpreter.requiresPauseJobOnError(task);
            int numberOfExecutionLeft = task.getNumberOfExecutionLeft();
            if (numberOfExecutionLeft <= 0 && onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
                tlogger.info(taskId, "no retry left and task is tagged with cancel job on error");
                jobData.job.increaseNumberOfFaultyTasks(taskId);
                endJob(jobData, terminationData, task, result, "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);
                jlogger.info(taskId.getJobId(), "job has been canceled");
                return terminationData;
            } else if (numberOfExecutionLeft > 0) {
                tlogger.info(taskId, "number of execution left is " + numberOfExecutionLeft);
                long waitTime = 0l;
                if (task.getTaskRetryDelayProperty().isSet()) {
                    waitTime = task.getTaskRetryDelay();
                } else {
                    waitTime = jobData.job.getNextWaitingTime(task.getMaxNumberOfExecution() - numberOfExecutionLeft);
                }
                if (onErrorPolicyInterpreter.requiresPauseTaskOnError(task) || requiresPauseJobOnError) {
                    restartTaskOnError(jobData, task, TaskStatus.WAITING_ON_ERROR, result, waitTime, terminationData);
                    tlogger.info(taskId, "new restart is scheduled");
                    return terminationData;
                } else {
                    jobData.job.increaseNumberOfFaultyTasks(taskId);
                    restartTaskOnError(jobData, task, TaskStatus.WAITING_ON_ERROR, result, waitTime, terminationData);
                    tlogger.info(taskId, "new restart is scheduled");
                    return terminationData;
                }
            } else if (numberOfExecutionLeft <= 0) {
                if (!onErrorPolicyInterpreter.requiresPauseTaskOnError(task) && !onErrorPolicyInterpreter.requiresPauseJobOnError(task) && !onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
                    jobData.job.increaseNumberOfFaultyTasks(taskId);
                    // remove the parent tasks results if task fails and job is canceled
                    task.removeParentTasksResults();
                } else if (onErrorPolicyInterpreter.requiresPauseTaskOnError(task)) {
                    suspendTaskOnError(jobData, task, result.getTaskDuration(), result);
                    tlogger.info(taskId, "Task still contains errors after restart, so it stays in InError state");
                    return terminationData;
                } else if (requiresPauseJobOnError) {
                    suspendTaskOnError(jobData, task, result.getTaskDuration(), result);
                    pauseJob(task.getJobId());
                    tlogger.info(taskId, "Task still contains errors after automatic restart, the Job is configured to pause on error");
                    return terminationData;
                }
                if (requiresPauseJobOnError) {
                    pauseJob(task.getJobId());
                }
            }
        } else {
            // remove the parent tasks results if task finished with no error
            task.removeParentTasksResults();
            task.setInErrorTime(-1);
        }
        terminateTask(jobData, task, errorOccurred, result, terminationData);
        return terminationData;
    } finally {
        jobData.unlock();
    }
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskIdWrapper(org.ow2.proactive.utils.TaskIdWrapper) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ExternalEndpoint(org.ow2.proactive.scheduler.job.ExternalEndpoint)

Example 2 with TaskIdWrapper

use of org.ow2.proactive.utils.TaskIdWrapper 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)

Example 3 with TaskIdWrapper

use of org.ow2.proactive.utils.TaskIdWrapper in project scheduling by ow2-proactive.

the class SchedulerMonitorsHandler method removeTaskEvent.

/**
 * Remove, if exist a TaskEventMonitor to the list of memorized tasks events
 * @param id
 * @param taskName
 * @param event
 * @return
 */
private TaskEventMonitor removeTaskEvent(JobId id, String taskName, SchedulerEvent event) {
    TaskEventMonitor tmp = new TaskEventMonitor(event, id, taskName);
    for (Entry<TaskIdWrapper, List<TaskEventMonitor>> entry : tasksEvents.entrySet()) {
        TaskId taskId = entry.getKey().getTaskId();
        List<TaskEventMonitor> value = entry.getValue();
        if (taskId.getJobId().equals(id) && taskId.getReadableName().equals(taskName) && value.contains(tmp)) {
            return value.remove(value.indexOf(tmp));
        }
    }
    return null;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskIdWrapper(org.ow2.proactive.utils.TaskIdWrapper) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with TaskIdWrapper

use of org.ow2.proactive.utils.TaskIdWrapper in project scheduling by ow2-proactive.

the class SchedulerMonitorsHandler method addTaskEvent.

/**
 * Add a Task Event to the list of occurred events (memorize it).
 * @param event type of task event
 * @param taskInfo TaskEvent object associated to Event
 */
private void addTaskEvent(SchedulerEvent event, TaskInfo taskInfo) {
    TaskIdWrapper taskId = TaskIdWrapper.wrap(taskInfo.getTaskId());
    List<TaskEventMonitor> taskEventMonitors = tasksEvents.get(taskId);
    if (taskEventMonitors == null) {
        taskEventMonitors = new ArrayList<>();
        tasksEvents.put(taskId, taskEventMonitors);
    }
    taskEventMonitors.add(new TaskEventMonitor(event, taskInfo));
}
Also used : TaskIdWrapper(org.ow2.proactive.utils.TaskIdWrapper)

Example 5 with TaskIdWrapper

use of org.ow2.proactive.utils.TaskIdWrapper in project scheduling by ow2-proactive.

the class EligibleTaskDescriptorImpl method equals.

/**
 * @see java.lang.Object#equals(java.lang.Object)
 */
@Override
public boolean equals(Object obj) {
    if (obj instanceof TaskDescriptor) {
        final TaskIdWrapper wrapObj = TaskIdWrapper.wrap(((TaskDescriptor) obj).getTaskId());
        final TaskIdWrapper wrapThis = TaskIdWrapper.wrap(this.getTaskId());
        return wrapObj.equals(wrapThis);
    }
    return false;
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) TaskIdWrapper(org.ow2.proactive.utils.TaskIdWrapper)

Aggregations

TaskIdWrapper (org.ow2.proactive.utils.TaskIdWrapper)5 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)1 TaskRestartedException (org.ow2.proactive.scheduler.common.exception.TaskRestartedException)1 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)1 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)1 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)1 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)1 ExternalEndpoint (org.ow2.proactive.scheduler.job.ExternalEndpoint)1 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)1