Search in sources :

Example 36 with UnknownTaskException

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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskIdData) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 37 with UnknownTaskException

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;
}
Also used : Serializable(java.io.Serializable) TaskResultImpl(org.ow2.proactive.scheduler.rest.data.TaskResultImpl) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData)

Example 38 with UnknownTaskException

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();
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) List(java.util.List) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 39 with UnknownTaskException

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"));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) List(java.util.List) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 40 with UnknownTaskException

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();
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) List(java.util.List) JobDescriptorImpl(org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Aggregations

UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)28 Test (org.junit.Test)27 JobId (org.ow2.proactive.scheduler.common.job.JobId)25 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)25 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)21 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)21 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)21 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)18 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)18 ArrayList (java.util.ArrayList)16 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)16 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)14 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)14 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)10 HashMap (java.util.HashMap)8 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)8 SchedulerDBManager (org.ow2.proactive.scheduler.core.db.SchedulerDBManager)8 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)8 List (java.util.List)7 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)7