use of org.ow2.proactive.scheduler.common.exception.UnknownTaskException in project scheduling by ow2-proactive.
the class SchedulerStateRest method taskResult.
/**
* Returns the task result of the task <code>taskName</code> of the job
* <code>jobId</code>
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job
* @param taskname
* the name of the task
* @return the task result of the task <code>taskName</code>
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result")
@Produces("application/json")
public TaskResultData taskResult(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname + "/result");
TaskResult taskResult = s.getTaskResult(jobId, taskname);
if (taskResult == null) {
TaskIdData taskIdData = new TaskIdData();
taskIdData.setReadableName(taskname);
TaskResultData taskResultData = new TaskResultData();
taskResultData.setId(taskIdData);
return taskResultData;
}
return buildTaskResultData(taskResult);
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (UnknownTaskException e) {
throw new UnknownTaskRestException(e);
}
}
use of org.ow2.proactive.scheduler.common.exception.UnknownTaskException in project scheduling by ow2-proactive.
the class SchedulerClient method getTaskResult.
@Override
public TaskResult getTaskResult(String jobId, String taskName) throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
TaskResultImpl taskResult = null;
try {
TaskResultData taskResultData = restApi().taskResult(sid, jobId, taskName);
taskResult = (TaskResultImpl) toTaskResult(JobIdImpl.makeJobId(jobId), taskResultData);
if (taskResult.value() == null) {
Serializable value = restApi().valueOfTaskResult(sid, jobId, taskName);
if (value != null) {
taskResult.setValue(value);
}
}
} catch (Throwable t) {
throwUJEOrNCEOrPEOrUTE(exception(t));
}
return taskResult;
}
use of org.ow2.proactive.scheduler.common.exception.UnknownTaskException in project scheduling by ow2-proactive.
the class TaskResultCreatorTest method testThatGetPropagatedVariablesAreExtractedFromParents.
@Test
public void testThatGetPropagatedVariablesAreExtractedFromParents() throws UnknownTaskException {
TaskResultCreator taskResultCreator = new TaskResultCreator();
TaskResultImpl mockedTaskResultImpl = mock(TaskResultImpl.class);
Map<TaskId, TaskResult> loadTaskResultsValue = new HashMap<>();
loadTaskResultsValue.put(this.createTaskID(), mockedTaskResultImpl);
when(mockedTaskResultImpl.getPropagatedVariables()).thenReturn(new HashMap<String, byte[]>());
SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenReturn(loadTaskResultsValue);
taskResultCreator.getTaskResult(mockedschedulerDbManager, this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTask()), this.getMockedInternalTask());
verify(mockedTaskResultImpl, atLeastOnce()).getPropagatedVariables();
}
use of org.ow2.proactive.scheduler.common.exception.UnknownTaskException in project scheduling by ow2-proactive.
the class TaskResultCreatorTest method testThatPropagatedVariablesAreExtractedFromParents.
@Test
public void testThatPropagatedVariablesAreExtractedFromParents() throws UnknownTaskException {
Map<String, byte[]> fakeVariableMap = new HashMap<>();
fakeVariableMap.put("ParentVar", "5623g".getBytes());
TaskResultCreator taskResultCreator = new TaskResultCreator();
TaskResultImpl mockedParentTaskResultImpl = mock(TaskResultImpl.class);
Map<TaskId, TaskResult> loadParentTaskResultsValue = new HashMap<>();
loadParentTaskResultsValue.put(this.createTaskID(), mockedParentTaskResultImpl);
when(mockedParentTaskResultImpl.getPropagatedVariables()).thenReturn(fakeVariableMap);
SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenReturn(loadParentTaskResultsValue);
TaskResult taskResult = taskResultCreator.getTaskResult(mockedschedulerDbManager, this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTask()), this.getMockedInternalTask());
when(taskResult.getPropagatedVariables()).thenCallRealMethod();
assertThat(new String(taskResult.getPropagatedVariables().get("ParentVar")), is("5623g"));
}
use of org.ow2.proactive.scheduler.common.exception.UnknownTaskException in project scheduling by ow2-proactive.
the class TaskResultCreatorTest method testRunningTasksAreCheckedForATaskId.
@Test
public void testRunningTasksAreCheckedForATaskId() throws UnknownTaskException {
TaskResultCreator taskResultCreator = new TaskResultCreator();
TaskResultImpl mockedTaskResultImpl = mock(TaskResultImpl.class);
Map<TaskId, TaskResult> loadTaskResultsValue = new HashMap<>();
loadTaskResultsValue.put(this.createTaskID(), mockedTaskResultImpl);
SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenReturn(loadTaskResultsValue);
JobDescriptorImpl mockedJobDescriptorHasRunningTask = this.getMockedJobDescriptorWithRunningTask();
taskResultCreator.getTaskResult(mockedschedulerDbManager, this.getMockedInternalJob(mockedJobDescriptorHasRunningTask), this.getMockedInternalTask());
verify(mockedJobDescriptorHasRunningTask, atLeastOnce()).getRunningTasks();
}
Aggregations