use of org.ow2.proactive.scheduler.core.db.TaskResultData in project scheduling by ow2-proactive.
the class OutputCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
File outFile = new File(pathname);
if (outFile.exists()) {
outFile.delete();
}
Stack resultStack = resultStack(currentContext);
if (!resultStack.isEmpty()) {
Object result = resultStack.peek();
if (result instanceof String) {
FileUtility.writeStringToFile(outFile, (String) result);
} else if (result instanceof TaskResultData) {
FileUtility.writeByteArrayToFile(ObjectByteConverter.base64StringToByteArray(((TaskResultData) result).getSerializedValue()), outFile);
} else {
FileUtility.writeObjectToFile(result, outFile);
}
} else {
writeLine(currentContext, "No result available to write.");
}
}
use of org.ow2.proactive.scheduler.core.db.TaskResultData in project scheduling by ow2-proactive.
the class TaskResultData method createTaskResultData.
static TaskResultData createTaskResultData(TaskData taskRuntimeData, TaskResultImpl result) {
TaskResultData resultData = new TaskResultData();
resultData.setTaskRuntimeData(taskRuntimeData);
resultData.setLogs(result.getOutput());
resultData.setPreviewerClassName(result.getPreviewerClassName());
resultData.setMetadata(result.getMetadata());
resultData.setPropagatedVariables(result.getPropagatedVariables());
resultData.setSerializedException(result.getSerializedException());
resultData.setSerializedValue(result.getSerializedValue());
resultData.setResultTime(System.currentTimeMillis());
resultData.setRaw(result.isRaw());
FlowAction flowAction = result.getAction();
if (flowAction != null) {
FlowActionData actionData = new FlowActionData();
actionData.setDupNumber(flowAction.getDupNumber());
actionData.setTarget(flowAction.getTarget());
actionData.setTargetContinuation(flowAction.getTargetContinuation());
actionData.setTargetElse(flowAction.getTargetElse());
actionData.setType(flowAction.getType());
resultData.setFlowAction(actionData);
}
return resultData;
}
use of org.ow2.proactive.scheduler.core.db.TaskResultData in project scheduling by ow2-proactive.
the class SchedulerStateRest method taskResultByTag.
/**
* Returns the task results of the set of task filtered by a given tag and
* owned by the job <code>jobId</code>
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job
* @param taskTag
* the tag used to filter the tasks.
* @return the task results of the set of tasks filtered by the given tag.
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result")
@Produces("application/json")
public List<TaskResultData> taskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskTag + "/result");
List<TaskResult> taskResults = s.getTaskResultsByTag(jobId, taskTag);
ArrayList<TaskResultData> results = new ArrayList<TaskResultData>(taskResults.size());
for (TaskResult current : taskResults) {
TaskResultData r = buildTaskResultData(PAFuture.getFutureValue(current));
results.add(r);
}
return results;
} 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.core.db.TaskResultData 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.core.db.TaskResultData 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);
}
Aggregations