use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.
the class TestTaskAttributes method testGenericInfo.
@Test
public void testGenericInfo() throws Exception {
JavaTask task = createDefaultTask("task");
Map<String, String> genericInfo;
InternalTask taskData;
genericInfo = new HashMap<>();
task.setGenericInformation(genericInfo);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertNotNull(taskData.getGenericInformation());
Assert.assertTrue(taskData.getGenericInformation().isEmpty());
genericInfo = new HashMap<>();
genericInfo.put("p1", "v1");
genericInfo.put("p2", "v2");
task.setGenericInformation(genericInfo);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(2, taskData.getGenericInformation().size());
Assert.assertEquals("v1", taskData.getGenericInformation().get("p1"));
Assert.assertEquals("v2", taskData.getGenericInformation().get("p2"));
StringBuilder longString = buildLongString();
genericInfo = new HashMap<>();
genericInfo.put("longProperty", longString.toString());
task.setGenericInformation(genericInfo);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(1, taskData.getGenericInformation().size());
Assert.assertEquals(longString.toString(), taskData.getGenericInformation().get("longProperty"));
}
use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.
the class TestTaskAttributes method testRestartMode.
@Test
public void testRestartMode() throws Exception {
JavaTask task = createDefaultTask("task1");
task.setRestartTaskOnError(RestartMode.ANYWHERE);
InternalTask taskData = saveSingleTask(task).getTask("task1");
Assert.assertSame(RestartMode.ANYWHERE, taskData.getRestartTaskOnError());
task.setRestartTaskOnError(RestartMode.ELSEWHERE);
taskData = saveSingleTask(task).getTask("task1");
Assert.assertSame(RestartMode.ELSEWHERE, taskData.getRestartTaskOnError());
}
use of org.ow2.proactive.scheduler.core.db.TaskData 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