Search in sources :

Example 6 with TaskResultData

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.");
    }
}
Also used : TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) File(java.io.File) Stack(java.util.Stack)

Example 7 with TaskResultData

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;
}
Also used : FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction)

Example 8 with TaskResultData

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);
    }
}
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) 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) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) ArrayList(java.util.ArrayList) 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 9 with TaskResultData

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);
    }
}
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 10 with TaskResultData

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

Aggregations

TaskResultData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData)12 ArrayList (java.util.ArrayList)4 JobResultData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobResultData)4 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)3 SchedulerRestInterface (org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface)3 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)3 File (java.io.File)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 GZIP (org.jboss.resteasy.annotations.GZIP)2 Test (org.junit.Test)2 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)2 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)2 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)2 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)2 DBTaskId (org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId)2 JobResultImpl (org.ow2.proactive.scheduler.job.JobResultImpl)2 CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)2