use of org.ow2.proactive.scheduler.rest.data.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));
}
use of org.ow2.proactive.scheduler.rest.data.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);
}
use of org.ow2.proactive.scheduler.rest.data.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));
}
use of org.ow2.proactive.scheduler.rest.data.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();
}
}
use of org.ow2.proactive.scheduler.rest.data.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;
}
Aggregations