Search in sources :

Example 16 with JobData

use of org.ow2.proactive.scheduler.core.db.JobData in project scheduling by ow2-proactive.

the class LiveJobs method restartAllInErrorTasks.

public Boolean restartAllInErrorTasks(JobId jobId) {
    JobData jobData = lockJob(jobId);
    if (jobData == null) {
        return false;
    }
    try {
        InternalJob job = jobData.job;
        for (TaskState taskState : job.getTasks()) {
            try {
                restartInErrorTask(jobId, taskState.getName());
            } catch (UnknownTaskException e) {
                logger.error("", e);
                jlogger.error(jobId, "", e);
                tlogger.error(taskState.getId(), "", e);
            }
        }
        setJobStatusToInErrorIfNotPaused(job);
        dbManager.updateJobAndTasksState(job);
        updateJobInSchedulerState(job, SchedulerEvent.JOB_RESTARTED_FROM_ERROR);
        return Boolean.TRUE;
    } finally {
        jobData.unlock();
    }
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 17 with JobData

use of org.ow2.proactive.scheduler.core.db.JobData in project scheduling by ow2-proactive.

the class LiveJobs method jobRecovered.

void jobRecovered(InternalJob job) {
    jobs.put(job.getId(), new JobData(job));
    for (InternalTask task : job.getITasks()) {
        if (task.getStatus() == TaskStatus.RUNNING) {
            logger.info("Recover task " + task.getId() + " (" + task.getName() + ") of job " + job.getId() + " (" + job.getName() + ")");
            runningTasksData.put(TaskIdWrapper.wrap(task.getId()), new RunningTaskData(task, job.getOwner(), job.getCredentials(), task.getExecuterInformation().getLauncher()));
        }
    }
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Example 18 with JobData

use of org.ow2.proactive.scheduler.core.db.JobData 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 19 with JobData

use of org.ow2.proactive.scheduler.core.db.JobData in project scheduling by ow2-proactive.

the class LiveJobs method lockJobsToSchedule.

Map<JobId, JobDescriptor> lockJobsToSchedule() {
    TreeSet<JobPriority> prioritiesScheduled = new TreeSet<>();
    TreeSet<JobPriority> prioritiesNotScheduled = new TreeSet<>();
    Map<JobId, JobDescriptor> result = new HashMap<>();
    for (Map.Entry<JobId, JobData> entry : jobs.entrySet()) {
        JobData value = entry.getValue();
        if (value.jobLock.tryLock()) {
            InternalJob job = entry.getValue().job;
            result.put(job.getId(), job.getJobDescriptor());
            prioritiesScheduled.add(job.getPriority());
            if (unlockIfConflict(prioritiesScheduled, prioritiesNotScheduled, result))
                return new HashMap<>(0);
        } else {
            prioritiesNotScheduled.add(value.job.getPriority());
            if (unlockIfConflict(prioritiesScheduled, prioritiesNotScheduled, result))
                return new HashMap<>(0);
        }
    }
    return result;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeSet(java.util.TreeSet) JobPriority(org.ow2.proactive.scheduler.common.job.JobPriority) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 20 with JobData

use of org.ow2.proactive.scheduler.core.db.JobData in project scheduling by ow2-proactive.

the class LiveJobs method killTask.

TerminationData killTask(JobId jobId, String taskName) 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(), "killing task " + task.getId());
        if (!task.getStatus().isTaskAlive()) {
            tlogger.warn(task.getId(), "task isn't alive: " + task.getStatus());
            return emptyResult(task.getId());
        }
        RunningTaskData taskData = runningTasksData.remove(TaskIdWrapper.wrap(task.getId()));
        if (taskData == null) {
            // the task is not in running state
            taskData = new RunningTaskData(task, jobData.job.getOwner(), jobData.job.getCredentials(), null);
        }
        TaskResultImpl taskResult = taskResultCreator.getTaskResult(dbManager, jobData.job, task, new TaskAbortedException("The task has been manually killed."), new SimpleTaskLogs("", "The task has been manually killed."));
        TerminationData terminationData = createAndFillTerminationData(taskResult, taskData, jobData.job, TerminationData.TerminationStatus.ABORTED);
        if (onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
            endJob(jobData, terminationData, task, taskResult, "The task has been manually killed. " + "You also ask to cancel the job in such a situation!", JobStatus.CANCELED);
        } else {
            terminateTask(jobData, task, true, taskResult, terminationData);
        }
        return terminationData;
    } finally {
        jobData.unlock();
    }
}
Also used : SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskAbortedException(org.ow2.proactive.scheduler.common.exception.TaskAbortedException)

Aggregations

InternalJob (org.ow2.proactive.scheduler.job.InternalJob)20 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)10 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)8 Test (org.junit.Test)7 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)7 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)5 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)5 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 JobId (org.ow2.proactive.scheduler.common.job.JobId)4 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)4 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)4 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 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 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)2 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)2