use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.
the class TerminationData method terminateRunningTask.
private void terminateRunningTask(SchedulingService service, TaskTerminationData taskToTerminate, RunningTaskData taskData) {
Map<String, String> genericInformation = new HashMap<>();
VariablesMap variables = null;
if (taskToTerminate.internalJob != null) {
genericInformation = taskData.getTask().getRuntimeGenericInformation();
}
try {
variables = getStringSerializableMap(service, taskToTerminate);
} catch (Exception e) {
logger.error("Exception occurred, fail to get variables into the cleaning script: ", e);
}
try {
if (taskToTerminate.terminationStatus == ABORTED) {
taskData.getLauncher().kill();
}
} catch (Throwable t) {
logger.info("Cannot terminate task launcher for task '" + taskData.getTask().getId() + "'", t);
try {
logger.info("Task launcher that cannot be terminated is identified by " + taskData.getLauncher().toString());
} catch (Throwable ignore) {
logger.info("Getting information about Task launcher failed (remote object not accessible?)");
}
}
try {
logger.debug("Releasing nodes for task '" + taskData.getTask().getId() + "'");
RMProxiesManager proxiesManager = service.getInfrastructure().getRMProxiesManager();
proxiesManager.getUserRMProxy(taskData.getUser(), taskData.getCredentials()).releaseNodes(taskData.getNodes(), taskToTerminate.terminationStatus != NODEFAILED ? taskData.getTask().getCleaningScript() : null, variables, genericInformation, taskToTerminate.taskData.getTask().getId(), service.addThirdPartyCredentials(taskData.getCredentials()));
} catch (Throwable t) {
logger.info("Failed to release nodes for task '" + taskData.getTask().getId() + "'", t);
}
}
use of org.ow2.proactive.scheduler.core.db.TaskData 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.core.db.TaskData in project scheduling by ow2-proactive.
the class JobData method toJobUsage.
JobUsage toJobUsage() {
JobIdImpl jobId = new JobIdImpl(getId(), getJobName());
JobUsage jobUsage = new JobUsage(getOwner(), getProjectName(), jobId.value(), getJobName(), getFinishedTime() - getStartTime());
for (TaskData taskData : getTasks()) {
TaskUsage taskUsage = taskData.toTaskUsage(jobId);
jobUsage.add(taskUsage);
}
return jobUsage;
}
use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.
the class SchedulerDBManager method batchLoadJobs.
// Executed in a transaction from the caller
private void batchLoadJobs(Session session, boolean fullState, Query jobQuery, List<Long> ids, Collection<InternalJob> jobs) {
Map<Long, List<TaskData>> tasksMap = loadJobsTasks(session, ids);
jobQuery.setParameterList("ids", ids);
List<JobData> jobsList = (List<JobData>) jobQuery.list();
for (JobData jobData : jobsList) {
InternalJob internalJob = jobData.toInternalJob();
internalJob.setTasks(toInternalTasks(fullState, internalJob, tasksMap.get(jobData.getId())));
jobs.add(internalJob);
}
}
use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.
the class SchedulerDBManager method saveSingleTaskDependencies.
private void saveSingleTaskDependencies(Session session, InternalTask task, TaskData taskRuntimeData) {
if (task.hasDependences()) {
List<DBTaskId> dependencies = new ArrayList<>(task.getDependences().size());
for (Task dependency : task.getDependences()) {
dependencies.add(taskId((InternalTask) dependency));
}
taskRuntimeData.setDependentTasks(dependencies);
} else {
taskRuntimeData.setDependentTasks(Collections.<DBTaskId>emptyList());
}
if (task.getIfBranch() != null) {
InternalTask ifBranch = task.getIfBranch();
taskRuntimeData.setIfBranch(getTaskReference(session, ifBranch));
} else {
taskRuntimeData.setIfBranch(null);
}
if (task.getJoinedBranches() != null && !task.getJoinedBranches().isEmpty()) {
List<DBTaskId> joinedBranches = new ArrayList<>(task.getJoinedBranches().size());
for (InternalTask joinedBranch : task.getJoinedBranches()) {
joinedBranches.add(taskId(joinedBranch));
}
taskRuntimeData.setJoinedBranches(joinedBranches);
} else {
taskRuntimeData.setJoinedBranches(Collections.<DBTaskId>emptyList());
}
}
Aggregations