use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class LiveJobs method endJob.
private void endJob(JobData jobData, TerminationData terminationData, InternalTask task, TaskResultImpl taskResult, String errorMsg, JobStatus jobStatus) {
JobId jobId = jobData.job.getId();
jobs.remove(jobId);
terminationData.addJobToTerminate(jobId);
InternalJob job = jobData.job;
SchedulerEvent event;
if (job.getStatus() == JobStatus.PENDING) {
event = SchedulerEvent.JOB_PENDING_TO_FINISHED;
} else {
event = SchedulerEvent.JOB_RUNNING_TO_FINISHED;
}
if (task != null) {
jlogger.info(job.getId(), "ending request caused by task " + task.getId());
} else {
jlogger.info(job.getId(), "ending request");
}
for (Iterator<RunningTaskData> i = runningTasksData.values().iterator(); i.hasNext(); ) {
RunningTaskData taskData = i.next();
if (taskData.getTask().getJobId().equals(jobId)) {
i.remove();
// remove previous read progress
taskData.getTask().setProgress(0);
terminationData.addTaskData(job, taskData, TerminationData.TerminationStatus.ABORTED, taskResult);
}
}
// if job has been killed
if (jobStatus == JobStatus.KILLED) {
Set<TaskId> tasksToUpdate = job.failed(null, jobStatus);
dbManager.updateAfterJobKilled(job, tasksToUpdate);
updateTasksInSchedulerState(job, tasksToUpdate);
} else {
// finished state (failed/canceled)
if (jobStatus != JobStatus.FINISHED) {
Set<TaskId> tasksToUpdate = job.failed(task.getId(), jobStatus);
// store the exception into jobResult / To prevent from empty
// task result (when job canceled), create one
boolean noResult = (jobStatus == JobStatus.CANCELED && taskResult == null);
if (jobStatus == JobStatus.FAILED || noResult) {
taskResult = new TaskResultImpl(task.getId(), new Exception(errorMsg), new SimpleTaskLogs("", errorMsg), -1);
}
dbManager.updateAfterJobFailed(job, task, taskResult, tasksToUpdate);
updateTasksInSchedulerState(job, tasksToUpdate);
}
}
// update job and tasks events list and send it to front-end
updateJobInSchedulerState(job, event);
jlogger.info(job.getId(), "finished (" + jobStatus + ")");
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class SchedulerClientExample method main.
public static void main(String[] args) throws Exception {
// LOGIN IN
SchedulerRestClient client = new SchedulerRestClient("http://localhost:9191/rest/rest/");
SchedulerRestInterface scheduler = client.getScheduler();
String sessionId = scheduler.login("admin", "admin");
// JOB SUBMISSION
File xmlJobFile = new File("/home/ybonnaffe/src/cloud_service_provider_conectors/cloudstack/vminfo_job.xml");
JobIdData xmlJob;
try (FileInputStream inputStream = new FileInputStream(xmlJobFile)) {
xmlJob = client.submitXml(sessionId, inputStream);
}
System.out.println(xmlJob.getReadableName() + " " + xmlJob.getId());
// FLAT JOB SUBMISSION
JobIdData flatJob = scheduler.submitFlat(sessionId, "echo hello", "test-hello", null, null);
System.out.println("Jobid=" + flatJob);
String serverlog = scheduler.jobServerLog(sessionId, Long.toString(flatJob.getId()));
System.out.println(serverlog);
while (true) {
JobStateData jobState2 = scheduler.listJobs(sessionId, Long.toString(flatJob.getId()));
System.out.println(jobState2);
if (jobState2.getJobInfo().getStatus().name().equals("FINISHED")) {
break;
}
Thread.sleep(100);
}
JobResultData jobResultData = scheduler.jobResult(sessionId, Long.toString(flatJob.getId()));
System.out.println(jobResultData);
TaskResultData taskresult = scheduler.taskResult(sessionId, Long.toString(flatJob.getId()), "task_1");
System.out.println(taskresult);
List<TaskStateData> jobTaskStates = scheduler.getJobTaskStates(sessionId, Long.toString(flatJob.getId())).getList();
System.out.println(jobTaskStates);
TaskStateData task_1 = scheduler.jobTask(sessionId, Long.toString(flatJob.getId()), "task_1");
System.out.println(task_1);
// OTHER CALLS
List<SchedulerUserData> users = scheduler.getUsers(sessionId);
System.out.println(users);
System.out.println(users.size());
RestMapPage<Long, ArrayList<UserJobData>> page = scheduler.revisionAndJobsInfo(sessionId, 0, 50, true, true, true, true);
Map<Long, ArrayList<UserJobData>> map = page.getMap();
System.out.println(map);
System.out.println(scheduler.getSchedulerStatus(sessionId));
System.out.println(scheduler.getUsageOnMyAccount(sessionId, new Date(), new Date()));
// FAILING CALL
try {
JobStateData jobState = scheduler.listJobs(sessionId, "601");
System.out.println(jobState);
} catch (UnknownJobRestException e) {
System.err.println("exception! " + e.getMessage());
e.printStackTrace();
}
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class TerminationData method getStringSerializableMap.
public VariablesMap getStringSerializableMap(SchedulingService service, TaskTerminationData taskToTerminate) throws Exception {
VariablesMap variablesMap = new VariablesMap();
RunningTaskData taskData = taskToTerminate.taskData;
TaskResultImpl taskResult = taskToTerminate.taskResult;
InternalJob internalJob = taskToTerminate.internalJob;
if (taskToTerminate.terminationStatus == ABORTED || taskResult == null) {
List<InternalTask> iDependences = taskData.getTask().getIDependences();
if (iDependences != null) {
Set<TaskId> parentIds = new HashSet<>(iDependences.size());
for (InternalTask parentTask : iDependences) {
parentIds.addAll(InternalTaskParentFinder.getInstance().getFirstNotSkippedParentTaskIds(parentTask));
}
// Batch fetching of parent tasks results
Map<TaskId, TaskResult> taskResults = new HashMap<>();
for (List<TaskId> parentsSubList : ListUtils.partition(new ArrayList<>(parentIds), PASchedulerProperties.SCHEDULER_DB_FETCH_TASK_RESULTS_BATCH_SIZE.getValueAsInt())) {
taskResults.putAll(service.getInfrastructure().getDBManager().loadTasksResults(taskData.getTask().getJobId(), parentsSubList));
}
getResultsFromListOfTaskResults(variablesMap.getInheritedMap(), taskResults);
} else {
if (internalJob != null) {
for (Map.Entry<String, JobVariable> jobVariableEntry : internalJob.getVariables().entrySet()) {
variablesMap.getInheritedMap().put(jobVariableEntry.getKey(), jobVariableEntry.getValue().getValue());
}
}
}
variablesMap.getInheritedMap().put(SchedulerVars.PA_TASK_SUCCESS.toString(), Boolean.toString(false));
} else if (taskResult.hadException()) {
variablesMap.setInheritedMap(fillMapWithTaskResult(taskResult, false));
} else {
variablesMap.setInheritedMap(fillMapWithTaskResult(taskResult, true));
}
variablesMap.setScopeMap(getNonInheritedScopeVariables(variablesMap.getInheritedMap(), taskData.getTask().getScopeVariables(), taskData.getTask().getVariables()));
return variablesMap;
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class TimedDoTaskAction method call.
/**
* {@inheritDoc}
*/
public Void call() throws Exception {
try {
// Set to empty array to emulate varargs behavior (i.e. not defined is
// equivalent to empty array, not null.
TaskResult[] params = new TaskResult[0];
// if job is TASKSFLOW, preparing the list of parameters for this task.
int resultSize = taskDescriptor.getParents().size();
if ((job.getType() == JobType.TASKSFLOW) && (resultSize > 0) && task.handleResultsArguments()) {
Set<TaskId> parentIds = new HashSet<>(resultSize);
for (int i = 0; i < resultSize; i++) {
parentIds.addAll(internalTaskParentFinder.getFirstNotSkippedParentTaskIds(((EligibleTaskDescriptorImpl) taskDescriptor.getParents().get(i)).getInternal()));
}
params = new TaskResult[parentIds.size()];
// If parentTaskResults is null after a system failure (a very rare case)
if (task.getParentTasksResults() == null) {
Map<TaskId, TaskResult> taskResults = new HashMap<>();
// Batch fetching of parent tasks results
for (List<TaskId> parentsSubList : ListUtils.partition(new ArrayList<>(parentIds), PASchedulerProperties.SCHEDULER_DB_FETCH_TASK_RESULTS_BATCH_SIZE.getValueAsInt())) {
taskResults.putAll(schedulingService.getInfrastructure().getDBManager().loadTasksResults(job.getId(), parentsSubList));
}
// store the parent tasks results in InternalTask for future executions.
task.setParentTasksResults(taskResults);
}
int i = 0;
for (TaskId taskId : parentIds) {
params[i] = task.getParentTasksResults().get(taskId);
i++;
}
}
// activate loggers for this task if needed
schedulingService.getListenJobLogsSupport().activeLogsIfNeeded(job.getId(), launcher);
fillContainer();
// try launch the task
launcher.doTask(task.getExecutableContainer(), params, terminateNotification, taskRecoveryData.getTerminateNotificationNodeURL(), taskRecoveryData.isTaskRecoverable());
} catch (Throwable e) {
logger.warn("Failed to start task: " + e.getMessage(), e);
restartTask();
}
return null;
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class TaskResultCreator method getTaskResult.
public TaskResultImpl getTaskResult(SchedulerDBManager dbManager, InternalJob job, InternalTask task, Throwable exception, TaskLogs output) throws UnknownTaskException {
if (task == null) {
throw new UnknownTaskException();
}
JobDescriptor jobDescriptor = job.getJobDescriptor();
EligibleTaskDescriptor eligibleTaskDescriptor = null;
if (jobDescriptor.getPausedTasks().get(task.getId()) != null) {
eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getPausedTasks().get(task.getId());
} else if (jobDescriptor.getRunningTasks().get(task.getId()) != null) {
eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getRunningTasks().get(task.getId());
}
TaskResultImpl taskResult = getEmptyTaskResult(task, exception, output);
taskResult.setPropagatedVariables(getPropagatedVariables(dbManager, eligibleTaskDescriptor, job, task));
return taskResult;
}
Aggregations