Search in sources :

Example 81 with TaskResultImpl

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

the class TaskResultCreatorTest method testThatGetEmptyTaskResultWithTaskIdAndExecutionTimeSetsCorrectTime.

@Test
public void testThatGetEmptyTaskResultWithTaskIdAndExecutionTimeSetsCorrectTime() {
    TaskResultCreator taskResultCreator = new TaskResultCreator();
    InternalTask mockedInternalTask = mock(InternalTask.class);
    when(mockedInternalTask.getStartTime()).thenReturn(System.currentTimeMillis() - 1);
    TaskResultImpl taskResult = taskResultCreator.getEmptyTaskResult(mockedInternalTask, null, null);
    // Between 1 millisecond and 1 second.
    assertThat(taskResult.getTaskDuration(), Matchers.greaterThan(0L));
    assertThat(taskResult.getTaskDuration(), Matchers.lessThan(1000L));
}
Also used : TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Example 82 with TaskResultImpl

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

the class SchedulingServiceTest7 method testTaskReplication.

@Test
public void testTaskReplication() throws Exception {
    service.submitJob(createJob(createTestJob()));
    listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
    Map<JobId, JobDescriptor> jobsMap;
    JobDescriptor jobDesc;
    jobsMap = service.lockJobsToSchedule();
    assertEquals(1, jobsMap.size());
    jobDesc = jobsMap.values().iterator().next();
    Assert.assertEquals(1, jobDesc.getEligibleTasks().size());
    for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
        taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
    }
    service.unlockJobsToSchedule(jobsMap.values());
    listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING);
    TaskId taskId;
    taskId = ((JobDescriptorImpl) jobDesc).getInternal().getTask("Main task").getId();
    TaskResultImpl result = new TaskResultImpl(taskId, "OK", null, 0);
    FlowAction action = new FlowAction(FlowActionType.REPLICATE);
    action.setDupNumber(3);
    result.setAction(action);
    service.taskTerminatedWithResult(taskId, result);
    listener.assertEvents(SchedulerEvent.TASK_REPLICATED, SchedulerEvent.TASK_SKIPPED, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_RUNNING_TO_FINISHED);
    jobsMap = service.lockJobsToSchedule();
    assertEquals(1, jobsMap.size());
    jobDesc = jobsMap.values().iterator().next();
    Assert.assertEquals(3, jobDesc.getEligibleTasks().size());
    for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
        taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
    }
    service.unlockJobsToSchedule(jobsMap.values());
    listener.assertEvents(SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING);
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 83 with TaskResultImpl

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

the class LiveJobsTest method testTaskTerminatedWithResultSuspendTaskOnError.

@Test(timeout = 60000)
public void testTaskTerminatedWithResultSuspendTaskOnError() throws UnknownTaskException {
    InternalJob job = new InternalTaskFlowJob("test-name", JobPriority.NORMAL, OnTaskError.CANCEL_JOB, "description");
    JobId id = new JobIdImpl(666L, "test-name");
    job.setId(id);
    List<InternalTask> tasksList = new ArrayList<>();
    InternalTask internalTask = new InternalScriptTask(job);
    TaskId taskId = TaskIdImpl.createTaskId(id, "task-name", 0L);
    internalTask.setId(taskId);
    internalTask.setName("task-name");
    internalTask.setStatus(TaskStatus.RUNNING);
    internalTask.setExecuterInformation(Mockito.mock(ExecuterInformation.class));
    TaskInfoImpl taskInfoImpl = (TaskInfoImpl) internalTask.getTaskInfo();
    taskInfoImpl.setNumberOfExecutionLeft(2);
    internalTask.setOnTaskError(OnTaskError.PAUSE_TASK);
    tasksList.add(internalTask);
    job.setTasks(tasksList);
    liveJobs.jobSubmitted(job);
    liveJobs.lockJobsToSchedule();
    liveJobs.taskStarted(job, job.getTask("task-name"), null);
    TaskResultImpl result = new TaskResultImpl(taskId, new Exception(), null, 330);
    liveJobs.taskTerminatedWithResult(taskId, result);
    assertThat(taskInfoImpl.getNumberOfExecutionLeft(), is(1));
    assertThat(taskInfoImpl.getStatus(), is(TaskStatus.WAITING_ON_ERROR));
    assertThat(job.getStatus(), is(JobStatus.STALLED));
}
Also used : ExecuterInformation(org.ow2.proactive.scheduler.task.internal.ExecuterInformation) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) 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 84 with TaskResultImpl

use of org.ow2.proactive.scheduler.task.TaskResultImpl 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 85 with TaskResultImpl

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

the class TaskResultData method toTaskResult.

TaskResultImpl toTaskResult(TaskId taskId) {
    TaskResultImpl result = new TaskResultImpl(taskId, getSerializedValue(), getSerializedException(), getLogs(), getMetadata(), getPropagatedVariables(), isRaw());
    result.setPreviewerClassName(getPreviewerClassName());
    FlowActionData actionData = getFlowAction();
    if (actionData != null) {
        FlowAction action = new FlowAction(actionData.getType());
        action.setDupNumber(actionData.getDupNumber());
        action.setTarget(actionData.getTarget());
        action.setTargetContinuation(actionData.getTargetContinuation());
        action.setTargetElse(actionData.getTargetElse());
        result.setAction(action);
    }
    return result;
}
Also used : TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction)

Aggregations

TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)73 Test (org.junit.Test)70 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)32 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)30 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)26 SimpleScript (org.ow2.proactive.scripting.SimpleScript)26 TaskScript (org.ow2.proactive.scripting.TaskScript)26 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)25 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)25 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)22 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)21 JobId (org.ow2.proactive.scheduler.common.job.JobId)16 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)16 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)15 HashMap (java.util.HashMap)13 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)13 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)12 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)11 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)10