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