Search in sources :

Example 21 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class SchedulerStateRest method jobLogs.

/**
 * Returns all the logs generated by the job (either stdout and stderr)
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @return all the logs generated by the job (either stdout and stderr) or
 *         an empty string if the result is not yet available
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/result/log/all")
@Produces("application/json")
public String jobLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/result/log/all");
        JobResult jobResult = s.getJobResult(jobId);
        if (jobResult == null) {
            return "";
        }
        StringBuilder jobOutput = new StringBuilder();
        for (TaskResult tr : jobResult.getAllResults().values()) {
            if ((tr != null) && (tr.getOutput() != null)) {
                jobOutput.append(tr.getOutput().getAllLogs(true));
            }
        }
        return jobOutput.toString();
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) 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) 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 22 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class SchedulerStateRest method jobResultValue.

/**
 * Returns all the task results of this job as a map whose the key is the
 * name of the task and its task result.<br>
 * If the result cannot be instantiated, the content is replaced by the
 * string 'Unknown value type'. To get the serialized form of a given
 * result, one has to call the following restful service
 * jobs/{jobid}/tasks/{taskname}/result/serializedvalue
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            a job id
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/result/value")
@Produces("application/json")
public Map<String, String> jobResultValue(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, PermissionRestException, UnknownJobRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/result/value");
        JobResult jobResult = PAFuture.getFutureValue(s.getJobResult(jobId));
        if (jobResult == null) {
            return null;
        }
        Map<String, TaskResult> allResults = jobResult.getAllResults();
        Map<String, String> res = new HashMap<>(allResults.size());
        for (final Entry<String, TaskResult> entry : allResults.entrySet()) {
            TaskResult taskResult = entry.getValue();
            String value = getTaskResultValueAsStringOrExceptionStackTrace(taskResult);
            res.put(entry.getKey(), value);
        }
        return res;
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) HashMap(java.util.HashMap) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 23 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class SchedulerStateRestJobLogsTest method jobLogs_finished_with_errput.

@Test
public void jobLogs_finished_with_errput() throws Exception {
    JobResultImpl jobResult = createJobResult("Hello", "World");
    when(mockScheduler.getJobResult("123")).thenReturn(jobResult);
    String jobLogs = restScheduler.jobLogs(validSessionId, "123");
    assertEquals("HelloWorld", jobLogs);
}
Also used : JobResultImpl(org.ow2.proactive.scheduler.job.JobResultImpl) Test(org.junit.Test)

Example 24 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class SchedulerStateRestJobTaskResultTest method testValueOfJobResult.

@Test
public void testValueOfJobResult() throws Throwable {
    TaskResultImpl taskResult = new TaskResultImpl(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("42"), "mytask", 1), ObjectToByteConverter.ObjectStream.convert("hello"), null, null, false);
    JobResultImpl jobResultWithValue = new JobResultImpl();
    JobInfoImpl jobInfo = new JobInfoImpl();
    jobInfo.setJobId(new JobIdImpl(12, "myjob"));
    jobResultWithValue.setJobInfo(jobInfo);
    jobResultWithValue.addTaskResult("mytask", taskResult, false);
    when(mockOfScheduler.getJobResult("42")).thenReturn(jobResultWithValue);
    JobResultData jobResultData = restInterface.jobResult(sessionId, "42");
    TaskResultData taskResultData = jobResultData.getAllResults().get("mytask");
    assertNotNull(taskResultData);
    assertNotNull(taskResultData.getValue());
    assertEquals("hello", taskResultData.getValue());
    Map<String, String> jobResult = restInterface.jobResultValue(sessionId, "42");
    String result = jobResult.get("mytask");
    assertNotNull(result);
    assertEquals("hello", result);
}
Also used : JobResultImpl(org.ow2.proactive.scheduler.job.JobResultImpl) JobResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobResultData) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl) Test(org.junit.Test)

Example 25 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class SchedulerStateRestJobTaskResultTest method testValueOfJobResult_ExceptionNoMessage.

@Test
public void testValueOfJobResult_ExceptionNoMessage() throws Throwable {
    TaskResultImpl taskResultWithException = new TaskResultImpl(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("42"), "mytask", 1), null, new byte[0], null, false);
    JobResultImpl jobResultWithException = new JobResultImpl();
    jobResultWithException.addTaskResult("mytask", taskResultWithException, false);
    when(mockOfScheduler.getJobResult("42")).thenReturn(jobResultWithException);
    Map<String, String> jobResult = restInterface.jobResultValue(sessionId, "42");
    String exceptionStackTrace = jobResult.get("mytask");
    assertNotNull(exceptionStackTrace);
}
Also used : JobResultImpl(org.ow2.proactive.scheduler.job.JobResultImpl) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) Test(org.junit.Test)

Aggregations

JobResult (org.ow2.proactive.scheduler.common.job.JobResult)39 JobId (org.ow2.proactive.scheduler.common.job.JobId)26 Test (org.junit.Test)25 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)24 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)22 File (java.io.File)16 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)9 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)7 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)6 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)6 JobResultImpl (org.ow2.proactive.scheduler.job.JobResultImpl)6 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)6 Job (org.ow2.proactive.scheduler.common.job.Job)4 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)4 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)4 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)4 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)3 SimpleJob (functionaltests.jobs.SimpleJob)3 HashMap (java.util.HashMap)3 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)3