use of org.ow2.proactive.db.DatabaseManagerException in project scheduling by ow2-proactive.
the class TaskResultCreatorTest method testThatJobVariablesAreUsedIfTaskHasNoParents.
@Test
public void testThatJobVariablesAreUsedIfTaskHasNoParents() throws UnknownTaskException {
TaskResultCreator taskResultCreator = new TaskResultCreator();
SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenThrow(new DatabaseManagerException());
InternalJob mockedInternalJob = this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTaskWithoutParent());
Map<String, JobVariable> fakeVariableMap = new HashMap<>();
fakeVariableMap.put("TestVar", new JobVariable("TestVar", "h234"));
when(mockedInternalJob.getVariables()).thenReturn(fakeVariableMap);
Map<String, String> fakeReplacementVariableMap = new HashMap<>();
fakeReplacementVariableMap.put("TestVar", "h234");
when(mockedInternalJob.getVariablesAsReplacementMap()).thenReturn(fakeReplacementVariableMap);
TaskResult taskResult = taskResultCreator.getTaskResult(mockedschedulerDbManager, mockedInternalJob, this.getMockedInternalTask());
verify(mockedInternalJob, atLeastOnce()).getVariablesAsReplacementMap();
assertThat(new String(taskResult.getPropagatedVariables().get("TestVar")), is("h234"));
}
use of org.ow2.proactive.db.DatabaseManagerException in project scheduling by ow2-proactive.
the class SchedulerFrontend method getTaskResultFromIncarnation.
/**
* {@inheritDoc}
*/
@Override
@ImmediateService
public TaskResult getTaskResultFromIncarnation(JobId jobId, String taskName, int inc) throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
// checking permissions
frontendState.checkPermissions("getTaskResultFromIncarnation", frontendState.getIdentifiedJob(jobId), YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_TASK_RESULT_OF_THIS_JOB);
if (inc < 0) {
throw new IllegalArgumentException("Incarnation must be 0 or greater.");
}
jlogger.debug(jobId, "trying to get the task result, incarnation " + inc);
if (inc < 0) {
throw new IllegalArgumentException("Incarnation must be 0 or greater.");
}
try {
TaskResult result = dbManager.loadTaskResult(jobId, taskName, inc);
// handling special statuses
TaskState ts = frontendState.getTaskState(jobId, taskName);
switch(ts.getStatus()) {
case NOT_STARTED:
if (result == null) {
return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskCouldNotStartException(), new SimpleTaskLogs("", "The task could not start due to dependency failure"), 0);
} else {
Throwable newException = new TaskCouldNotStartException("The task could not start due to dependency failure", result.getException());
((TaskResultImpl) result).setException(newException);
}
break;
case NOT_RESTARTED:
if (result == null) {
return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskCouldNotRestartException(), new SimpleTaskLogs("", "The task could not be restarted after an error during the previous execution"), 0);
} else {
Throwable newException = new TaskCouldNotRestartException("The task could not be restarted after an error during the previous execution", result.getException());
((TaskResultImpl) result).setException(newException);
}
break;
case SKIPPED:
// result should always be null
return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskSkippedException(), new SimpleTaskLogs("", "The task was skipped in the workflow"), 0);
}
if (result == null) {
// otherwise the task is not finished
jlogger.info(jobId, taskName + " is not finished");
return null;
} else {
return result;
}
} catch (DatabaseManagerException e) {
throw new UnknownTaskException("Unknown task " + taskName + ", job: " + jobId);
}
}
use of org.ow2.proactive.db.DatabaseManagerException in project scheduling by ow2-proactive.
the class SchedulerDBManager method toInternalTasks.
private Collection<InternalTask> toInternalTasks(boolean loadFullState, InternalJob internalJob, List<TaskData> taskRuntimeDataList) {
Map<DBTaskId, InternalTask> tasks = new HashMap<>(taskRuntimeDataList.size());
try {
for (TaskData taskData : taskRuntimeDataList) {
InternalTask internalTask = taskData.toInternalTask(internalJob, loadFullState);
if (loadFullState) {
internalTask.setParallelEnvironment(taskData.getParallelEnvironment());
internalTask.setGenericInformation(taskData.getGenericInformation());
for (SelectionScriptData scriptData : taskData.getSelectionScripts()) {
internalTask.addSelectionScript(scriptData.createSelectionScript());
}
if (taskData.getCleanScript() != null) {
internalTask.setCleaningScript(taskData.getCleanScript().createSimpleScript());
}
if (taskData.getPreScript() != null) {
internalTask.setPreScript(taskData.getPreScript().createSimpleScript());
}
if (taskData.getPostScript() != null) {
internalTask.setPostScript(taskData.getPostScript().createSimpleScript());
}
if (taskData.getFlowScript() != null) {
internalTask.setFlowScript(taskData.getFlowScript().createFlowScript());
}
for (SelectorData selectorData : taskData.getDataspaceSelectors()) {
if (selectorData.isInput()) {
InputSelector selector = selectorData.createInputSelector();
internalTask.addInputFiles(selector.getInputFiles(), selector.getMode());
} else {
OutputSelector selector = selectorData.createOutputSelector();
internalTask.addOutputFiles(selector.getOutputFiles(), selector.getMode());
}
}
}
tasks.put(taskData.getId(), internalTask);
}
} catch (InvalidScriptException e) {
throw new DatabaseManagerException("Failed to initialize loaded script", e);
}
for (TaskData taskData : taskRuntimeDataList) {
InternalTask internalTask = tasks.get(taskData.getId());
if (!taskData.getDependentTasks().isEmpty()) {
for (DBTaskId dependent : taskData.getDependentTasks()) {
internalTask.addDependence(tasks.get(dependent));
}
}
if (loadFullState) {
if (taskData.getIfBranch() != null) {
internalTask.setIfBranch(tasks.get(taskData.getIfBranch().getId()));
}
if (!taskData.getJoinedBranches().isEmpty()) {
List<InternalTask> branches = new ArrayList<>(taskData.getJoinedBranches().size());
for (DBTaskId joinedBranch : taskData.getJoinedBranches()) {
branches.add(tasks.get(joinedBranch));
}
internalTask.setJoinedBranches(branches);
}
internalTask.setName(internalTask.getName());
}
}
return tasks.values();
}
use of org.ow2.proactive.db.DatabaseManagerException in project scheduling by ow2-proactive.
the class TestTaskResultData method testInvalidTask.
@Test
public void testInvalidTask() throws Throwable {
TaskFlowJob jobDef = new TaskFlowJob();
jobDef.addTask(createDefaultTask("testTask"));
InternalJob job = defaultSubmitJob(jobDef);
// try to call when task exists but there is no result
Assert.assertNull(dbManager.loadTaskResult(job.getId(), "testTask", 0));
Assert.assertNull(dbManager.loadTaskResult(job.getId(), "testTask", 1));
// try to call with invalid task name and invalid jobId
try {
dbManager.loadTaskResult(job.getId(), "testTask1", 1);
Assert.fail();
} catch (DatabaseManagerException e) {
// expected
}
try {
dbManager.loadTaskResult(JobIdImpl.makeJobId("12345789"), "testTask", 1);
Assert.fail();
} catch (DatabaseManagerException e) {
// expected
}
}
Aggregations