Search in sources :

Example 21 with TaskData

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

the class TerminationDataTest method testHandleTerminationForTaskNormalTermination.

@Test
public void testHandleTerminationForTaskNormalTermination() throws RMProxyCreationException, IOException, ClassNotFoundException {
    InternalJob job = new InternalTaskFlowJob("test-name", JobPriority.NORMAL, OnTaskError.CANCEL_JOB, "description");
    JobId jobId = new JobIdImpl(666, "readableName");
    InternalTask internalTask = new InternalScriptTask(job);
    TaskId taskId = TaskIdImpl.createTaskId(jobId, "task-name", 777L);
    internalTask.setId(taskId);
    internalTask.setName("task-name");
    internalTask.setStatus(TaskStatus.RUNNING);
    internalTask.setExecuterInformation(Mockito.mock(ExecuterInformation.class));
    RunningTaskData taskData = new RunningTaskData(internalTask, "user", null, launcher);
    terminationData.addTaskData(null, taskData, TerminationData.TerminationStatus.NORMAL, null);
    terminationData.handleTermination(service);
    Mockito.verify(proxiesManager, Mockito.times(1)).getUserRMProxy("user", null);
    Mockito.verify(rmProxy, Mockito.times(1)).releaseNodes(org.mockito.Matchers.any(NodeSet.class), org.mockito.Matchers.any(org.ow2.proactive.scripting.Script.class), Mockito.any(VariablesMap.class), Mockito.any(HashMap.class), Mockito.any(TaskId.class), Mockito.any(Credentials.class));
}
Also used : ExecuterInformation(org.ow2.proactive.scheduler.task.internal.ExecuterInformation) NodeSet(org.ow2.proactive.utils.NodeSet) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) JobId(org.ow2.proactive.scheduler.common.job.JobId) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Example 22 with TaskData

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

the class TerminationDataTest method testHandleTerminationForTaskAbortedTermination.

@Test
public void testHandleTerminationForTaskAbortedTermination() throws IOException, ClassNotFoundException {
    InternalJob job = new InternalTaskFlowJob("test-name", JobPriority.NORMAL, OnTaskError.CANCEL_JOB, "description");
    JobId jobId = new JobIdImpl(666, "readableName");
    InternalTask internalTask = new InternalScriptTask(job);
    TaskId taskId = TaskIdImpl.createTaskId(jobId, "task-name", 777L);
    internalTask.setId(taskId);
    internalTask.setName("task-name");
    internalTask.setStatus(TaskStatus.RUNNING);
    internalTask.setExecuterInformation(Mockito.mock(ExecuterInformation.class));
    RunningTaskData taskData = new RunningTaskData(internalTask, "user", null, launcher);
    terminationData.addTaskData(null, taskData, TerminationData.TerminationStatus.ABORTED, null);
    terminationData.handleTermination(service);
    Mockito.verify(launcher, Mockito.times(1)).kill();
}
Also used : ExecuterInformation(org.ow2.proactive.scheduler.task.internal.ExecuterInformation) InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 23 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData 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)

Example 24 with TaskData

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

the class SchedulingService method getProgressAndPingTaskNode.

void getProgressAndPingTaskNode(RunningTaskData taskData) {
    if (!jobs.canPingTask(taskData) || taskData.getPingAttempts() > PASchedulerProperties.SCHEDULER_NODE_PING_ATTEMPTS.getValueAsInt()) {
        return;
    }
    InternalTask task = taskData.getTask();
    try {
        // (2)
        int progress = taskData.getLauncher().getProgress();
        // get previous inside td
        if (progress != task.getProgress()) {
            // (1)
            task.setProgress(progress);
            // if progress != previously set progress (0 by default) -> update
            listener.taskStateUpdated(taskData.getUser(), new NotificationData<TaskInfo>(SchedulerEvent.TASK_PROGRESS, new TaskInfoImpl((TaskInfoImpl) task.getTaskInfo())));
        }
    } catch (Throwable t) {
        tlogger.debug(task.getId(), "TaskLauncher is not accessible, checking if the node can be reached.", t);
        pingTaskNodeAndInitiateRestart(task);
    }
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl)

Example 25 with TaskData

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

the class SchedulerDBManager method toInternalTasks.

private Collection<InternalTask> toInternalTasks(boolean loadFullState, InternalJob internalJob, List<TaskData> taskRuntimeDataList) {
    Map<DBTaskId, InternalTask> tasks = new HashMap<>(taskRuntimeDataList.size());
    try {
        for (TaskData taskData : taskRuntimeDataList) {
            InternalTask internalTask = taskData.toInternalTask(internalJob, loadFullState);
            if (loadFullState) {
                internalTask.setParallelEnvironment(taskData.getParallelEnvironment());
                internalTask.setGenericInformation(taskData.getGenericInformation());
                for (SelectionScriptData scriptData : taskData.getSelectionScripts()) {
                    internalTask.addSelectionScript(scriptData.createSelectionScript());
                }
                if (taskData.getCleanScript() != null) {
                    internalTask.setCleaningScript(taskData.getCleanScript().createSimpleScript());
                }
                if (taskData.getPreScript() != null) {
                    internalTask.setPreScript(taskData.getPreScript().createSimpleScript());
                }
                if (taskData.getPostScript() != null) {
                    internalTask.setPostScript(taskData.getPostScript().createSimpleScript());
                }
                if (taskData.getFlowScript() != null) {
                    internalTask.setFlowScript(taskData.getFlowScript().createFlowScript());
                }
                for (SelectorData selectorData : taskData.getDataspaceSelectors()) {
                    if (selectorData.isInput()) {
                        InputSelector selector = selectorData.createInputSelector();
                        internalTask.addInputFiles(selector.getInputFiles(), selector.getMode());
                    } else {
                        OutputSelector selector = selectorData.createOutputSelector();
                        internalTask.addOutputFiles(selector.getOutputFiles(), selector.getMode());
                    }
                }
            }
            tasks.put(taskData.getId(), internalTask);
        }
    } catch (InvalidScriptException e) {
        throw new DatabaseManagerException("Failed to initialize loaded script", e);
    }
    for (TaskData taskData : taskRuntimeDataList) {
        InternalTask internalTask = tasks.get(taskData.getId());
        if (!taskData.getDependentTasks().isEmpty()) {
            for (DBTaskId dependent : taskData.getDependentTasks()) {
                internalTask.addDependence(tasks.get(dependent));
            }
        }
        if (loadFullState) {
            if (taskData.getIfBranch() != null) {
                internalTask.setIfBranch(tasks.get(taskData.getIfBranch().getId()));
            }
            if (!taskData.getJoinedBranches().isEmpty()) {
                List<InternalTask> branches = new ArrayList<>(taskData.getJoinedBranches().size());
                for (DBTaskId joinedBranch : taskData.getJoinedBranches()) {
                    branches.add(tasks.get(joinedBranch));
                }
                internalTask.setJoinedBranches(branches);
            }
            internalTask.setName(internalTask.getName());
        }
    }
    return tasks.values();
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) ArrayList(java.util.ArrayList) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector)

Aggregations

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)20 Test (org.junit.Test)12 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)7 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)7 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)5 JobId (org.ow2.proactive.scheduler.common.job.JobId)5 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)5 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)4 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)4 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)4 Query (org.hibernate.Query)3 DBTaskId (org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId)3 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