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);
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations