Search in sources :

Example 1 with JobResultImpl

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

the class SchedulerStateRestJobLogsTest method createJobResult.

private JobResultImpl createJobResult(String taskOutput, String taskErrput) {
    JobResultImpl jobResult = new JobResultImpl();
    jobResult.addTaskResult("OneTask", new TaskResultImpl(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("123"), "OneTask", 1), "result", new SimpleTaskLogs(taskOutput, taskErrput), 100), false);
    return jobResult;
}
Also used : JobResultImpl(org.ow2.proactive.scheduler.job.JobResultImpl) SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl)

Example 2 with JobResultImpl

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

the class SchedulerStateRestJobLogsTest method jobLogs_finished.

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

Example 3 with JobResultImpl

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

the class SchedulerDBManager method loadAndAddTaskResultsToJobResult.

private void loadAndAddTaskResultsToJobResult(Session session, Query query, JobId jobId, JobResultImpl jobResult) {
    List<Object[]> resultList = (List<Object[]>) query.list();
    if (resultList.isEmpty()) {
        return;
    }
    DBTaskId currentTaskId = null;
    int counter = 0;
    for (Object[] result : resultList) {
        TaskResultData resultData = (TaskResultData) result[0];
        DBTaskId dbTaskId = (DBTaskId) result[1];
        String taskName = (String) result[2];
        Boolean preciousResult = (Boolean) result[3];
        boolean nextTask = !dbTaskId.equals(currentTaskId);
        if (nextTask) {
            TaskId taskId = TaskIdImpl.createTaskId(jobId, taskName, dbTaskId.getTaskId());
            jobResult.addTaskResult(taskName, resultData.toTaskResult(taskId), preciousResult);
            currentTaskId = dbTaskId;
        }
        if (++counter % 100 == 0) {
            session.clear();
        }
    }
}
Also used : DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId)

Example 4 with JobResultImpl

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

the class SchedulerDBManager method loadTasksResults.

@SuppressWarnings("unchecked")
public Map<TaskId, TaskResult> loadTasksResults(final JobId jobId, final List<TaskId> taskIds) {
    if (taskIds.isEmpty()) {
        throw new IllegalArgumentException("TaskIds list is empty");
    }
    return executeReadOnlyTransaction(session -> {
        JobData job = session.get(JobData.class, jobId(jobId));
        if (job == null) {
            throw new DatabaseManagerException("Invalid job id: " + jobId);
        }
        List<DBTaskId> dbTaskIds = taskIds.stream().map(SchedulerDBManager::taskId).collect(Collectors.toList());
        JobResultImpl jobResult = new JobResultImpl();
        jobResult.setJobInfo(job.createJobInfo(jobId));
        try {
            jobResult.getResultMap().putAll(ObjectByteConverter.mapOfByteArrayToSerializable(job.getResultMap()));
        } catch (Exception e) {
            logger.error("error ", e);
        }
        List<List<DBTaskId>> dbTaskIdsSubSets = Lists.partition(dbTaskIds, MAX_ITEMS_IN_LIST);
        for (List<DBTaskId> dbTaskIdsSubList : dbTaskIdsSubSets) {
            Query query = session.getNamedQuery("loadTasksResults").setParameterList("tasksIds", dbTaskIdsSubList);
            loadAndAddTaskResultsToJobResult(session, query, jobId, jobResult);
        }
        Map<TaskId, TaskResult> resultsMap = new HashMap<>(taskIds.size());
        for (TaskId taskId : taskIds) {
            TaskResult taskResult = null;
            for (TaskResult result : jobResult.getAllResults().values()) {
                if (result.getTaskId().equals(taskId)) {
                    taskResult = result;
                    break;
                }
            }
            if (taskResult == null) {
                // a null result indicates a skipped task
                TaskResult emptyResult = new TaskResultImpl(taskId);
                resultsMap.put(taskId, emptyResult);
                jobResult.addTaskResult(taskId.getReadableName(), emptyResult, false);
            } else {
                resultsMap.put(taskId, taskResult);
            }
        }
        if (jobResult.getAllResults().size() != taskIds.size()) {
            throw new DatabaseManagerException("Results: " + jobResult.getAllResults().size() + " " + taskIds.size());
        }
        return resultsMap;
    });
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) Query(org.hibernate.Query) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HibernateException(org.hibernate.HibernateException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) IOException(java.io.IOException) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) JobResultImpl(org.ow2.proactive.scheduler.job.JobResultImpl) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult)

Example 5 with JobResultImpl

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

the class SchedulerDBManager method loadJobResult.

@SuppressWarnings("unchecked")
private JobResultImpl loadJobResult(Session session, Query query, JobData job, JobId jobId) {
    JobResultImpl jobResult = new JobResultImpl();
    jobResult.setJobInfo(job.createJobInfo(jobId));
    DBTaskId currentTaskId = null;
    List<Object[]> resultList = (List<Object[]>) query.list();
    if (resultList.isEmpty()) {
        return jobResult;
    }
    int counter = 0;
    for (Object[] result : resultList) {
        TaskResultData resultData = (TaskResultData) result[0];
        DBTaskId dbTaskId = (DBTaskId) result[1];
        String taskName = (String) result[2];
        Boolean preciousResult = (Boolean) result[3];
        boolean nextTask = !dbTaskId.equals(currentTaskId);
        if (nextTask) {
            TaskId taskId = TaskIdImpl.createTaskId(jobId, taskName, dbTaskId.getTaskId());
            jobResult.addTaskResult(taskName, resultData.toTaskResult(taskId), preciousResult);
            currentTaskId = dbTaskId;
        }
        if (++counter % 100 == 0) {
            session.clear();
        }
    }
    return jobResult;
}
Also used : JobResultImpl(org.ow2.proactive.scheduler.job.JobResultImpl) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

JobResultImpl (org.ow2.proactive.scheduler.job.JobResultImpl)7 Test (org.junit.Test)4 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)4 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)3 DBTaskId (org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HibernateException (org.hibernate.HibernateException)1 Query (org.hibernate.Query)1 DatabaseManagerException (org.ow2.proactive.db.DatabaseManagerException)1 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)1 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)1 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)1 JobInfoImpl (org.ow2.proactive.scheduler.job.JobInfoImpl)1 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)1 JobResultData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobResultData)1 TaskResultData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData)1