use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class TestReadSchedulerAccount method finishTask.
private long finishTask(InternalJob job, String taskName) throws Exception {
Thread.sleep(100);
InternalTask task = job.getTask(taskName);
TaskResultImpl res = new TaskResultImpl(null, "ok", null, 0);
job.terminateTask(false, task.getId(), null, null, res);
if (job.isFinished()) {
job.terminate();
}
dbManager.updateAfterTaskFinished(job, task, res);
return task.getFinishedTime() - task.getStartTime();
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class TestRestoreWorkflowJobs method finishedJobWithScriptsCanBeRecoveredAndLoaded.
@Test
public void finishedJobWithScriptsCanBeRecoveredAndLoaded() throws Exception {
InternalJob job = defaultSubmitJobAndLoadInternal(true, createJobWithAllKindOfScripts());
job.start();
InternalTask mainTask = job.getTask("T");
startTask(job, mainTask);
dbManager.jobTaskStarted(job, mainTask, true);
TaskResultImpl result = new TaskResultImpl(mainTask.getId(), "ok", null, 0);
ChangedTasksInfo changesInfo = job.terminateTask(false, mainTask.getId(), null, null, result);
job.setStatus(JobStatus.FINISHED);
dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
JobStateMatcher expectedJob = job(job.getId(), JobStatus.FINISHED).withFinished(task("T", TaskStatus.FINISHED).checkFinished(), true);
checkRecoveredState(recoverHelper.recover(-1), state().withFinished(expectedJob));
List<InternalJob> finishedJobs = dbManager.loadFinishedJobs(true, -1);
assertEquals(1, finishedJobs.size());
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class TestTaskResultData method testResult.
@Test
public void testResult() throws Throwable {
Map<String, String> metadata = ImmutableMap.of("key1", "value1", "key2", "value2");
InternalJob job = saveSingleTask(createDefaultTask("task"));
TaskResultImpl result = new TaskResultImpl(null, new TestResult(10, "12345"), null, 0);
String previewer = "org.ow2.proactive.scheduler.common.org.ow2.proactive.scheduler.common.ClassName";
result.setPreviewerClassName(previewer);
result.setMetadata(metadata);
InternalTask task = (InternalTask) job.getTasks().get(0);
System.out.println("Add task result");
dbManager.updateAfterTaskFinished(job, task, result);
System.out.println("Get last task result");
TaskResultImpl restoredResult = (TaskResultImpl) dbManager.loadLastTaskResult(task.getId());
Assert.assertEquals(task.getId(), restoredResult.getTaskId());
Assert.assertNull(restoredResult.getException());
Assert.assertNull(restoredResult.getOutput());
TestResult value = (TestResult) restoredResult.value();
Assert.assertNotNull(value);
Assert.assertEquals(10, value.getA());
Assert.assertEquals("12345", value.getB());
Assert.assertEquals(previewer, restoredResult.getPreviewerClassName());
Assert.assertNull(restoredResult.getAction());
Assert.assertEquals(metadata, restoredResult.getMetadata());
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class TestTaskResultData method testSimpleLogs.
@Test
public void testSimpleLogs() throws Exception {
InternalJob job = saveSingleTask(createDefaultTask("task"));
InternalTask task = (InternalTask) job.getTasks().get(0);
TaskResultImpl result = new TaskResultImpl(null, "result", new SimpleTaskLogs("stdLogs", "errorLogs"), 0);
dbManager.updateAfterTaskFinished(job, task, result);
TaskResult restoredResult = dbManager.loadLastTaskResult(task.getId());
TaskLogs logs = restoredResult.getOutput();
Assert.assertNotNull(logs);
Assert.assertEquals("stdLogs", logs.getStdoutLogs(false));
Assert.assertEquals("errorLogs", logs.getStderrLogs(false));
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class LiveJobs method restartTask.
TerminationData restartTask(JobId jobId, String taskName, int restartDelay) 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(), "restarting task " + task.getId());
if (!task.getStatus().isTaskAlive()) {
tlogger.warn(task.getId(), "task isn't alive: " + task.getStatus());
return emptyResult(task.getId());
}
TaskIdWrapper taskIdWrapper = TaskIdWrapper.wrap(task.getId());
RunningTaskData taskData = runningTasksData.remove(taskIdWrapper);
if (taskData == null) {
throw new IllegalStateException("Task " + task.getId() + " is not running.");
}
TaskResultImpl taskResult = taskResultCreator.getTaskResult(dbManager, jobData.job, task, new TaskRestartedException("Aborted by user"), new SimpleTaskLogs("", "Aborted by user"));
TerminationData terminationData = createAndFillTerminationData(taskResult, taskData, jobData.job, TerminationData.TerminationStatus.ABORTED);
task.decreaseNumberOfExecutionLeft();
if (task.getNumberOfExecutionLeft() <= 0 && onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
endJob(jobData, terminationData, task, taskResult, "An error occurred in your task and the maximum number of executions has been reached. " + "You also ask to cancel the job in such a situation !", JobStatus.CANCELED);
return terminationData;
} else if (task.getNumberOfExecutionLeft() > 0) {
long waitTime = restartDelay * 1000l;
restartTaskOnError(jobData, task, TaskStatus.WAITING_ON_ERROR, taskResult, waitTime, terminationData);
return terminationData;
}
terminateTask(jobData, task, true, taskResult, terminationData);
return terminationData;
} finally {
jobData.unlock();
}
}
Aggregations