use of org.ow2.proactive.scheduler.common.exception.UnknownTaskException 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.common.exception.UnknownTaskException in project scheduling by ow2-proactive.
the class LiveJobsTest method testResumeStartedJob.
@Test(timeout = 60000)
public void testResumeStartedJob() throws UnknownJobException, 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);
internalTask.setName("task-name");
tasksList.add(internalTask);
job.setTasks(tasksList);
liveJobs.jobSubmitted(job);
liveJobs.pauseJob(id);
assertThat(liveJobs.resumeJob(id), is(true));
}
use of org.ow2.proactive.scheduler.common.exception.UnknownTaskException 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.common.exception.UnknownTaskException in project scheduling by ow2-proactive.
the class SchedulingServiceTest4 method testTaskRestart1.
@Test
public void testTaskRestart1() throws Exception {
service.submitJob(createJob(createTestJob()));
listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
JobDescriptor jobDesc = startTask();
try {
service.restartTask(jobDesc.getJobId(), "invalid task name", 100);
Assert.fail();
} catch (UnknownTaskException e) {
}
try {
service.restartTask(JobIdImpl.makeJobId("1234567"), "javaTask", 100);
Assert.fail();
} catch (UnknownJobException e) {
}
service.restartTask(jobDesc.getJobId(), "javaTask", 100);
listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_WAITING_FOR_RESTART);
infrastructure.assertRequests(1);
startTask();
TaskId taskId = ((JobDescriptorImpl) jobDesc).getInternal().getTask("javaTask").getId();
service.taskTerminatedWithResult(taskId, new TaskResultImpl(taskId, "OK", null, 0));
listener.assertEvents(SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_UPDATED);
infrastructure.assertRequests(1);
}
use of org.ow2.proactive.scheduler.common.exception.UnknownTaskException in project scheduling by ow2-proactive.
the class SchedulerFrontend method getTaskResultsByTag.
@Override
@ImmediateService
public List<TaskResult> getTaskResultsByTag(JobId jobId, String taskTag) throws NotConnectedException, UnknownJobException, PermissionException {
frontendState.checkPermission("getTaskResultByTag", YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_TASK_RESULT_OF_THIS_JOB);
List<TaskState> taskStates = getJobState(jobId).getTasksByTag(taskTag);
ArrayList<TaskResult> results = new ArrayList<TaskResult>(taskStates.size());
for (TaskState currentState : taskStates) {
String taskName = currentState.getTaskInfo().getName();
try {
TaskResult currentResult = getTaskResult(jobId, taskName);
results.add(currentResult);
} catch (UnknownTaskException ex) {
// never occurs because tasks are filtered by tag so they cannot
// be unknown.
logger.warn("Unknown task.", ex);
}
}
return results;
}
Aggregations