use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.
the class SchedulingMethodImpl method getNextcompatibleTasks.
/**
* Extract the n first compatible tasks from the first argument list,
* and return them according that the extraction is stopped when the maxResource number is reached.<br>
* Two tasks are compatible if and only if they have the same list of selection script and
* the same list of node exclusion.
* The check of compliance is currently done by the {@link SchedulingTaskComparator} class.<br>
* This method has two side effects : extracted tasks are removed from the bagOfTasks and put in the toFill list
*
* @param bagOfTasks the list of tasks form which to extract tasks
* @param maxResource the limit number of resources that the extraction should not exceed
* @param toFill the list that will contains the task to schedule at the end. This list must not be null but must be empty.<br>
* this list will be filled with the n first compatible tasks according that the number of resources needed
* by these tasks does not exceed the given max resource number.
* @return the number of nodes needed to start every task present in the 'toFill' argument at the end of the method.
*/
protected int getNextcompatibleTasks(Map<JobId, JobDescriptor> jobsMap, LinkedList<EligibleTaskDescriptor> bagOfTasks, int maxResource, LinkedList<EligibleTaskDescriptor> toFill) {
if (toFill == null || bagOfTasks == null) {
throw new IllegalArgumentException("The two given lists must not be null !");
}
int neededResource = 0;
if (!PASchedulerProperties.SCHEDULER_REST_URL.isSet()) {
Iterator<EligibleTaskDescriptor> it = bagOfTasks.iterator();
EligibleTaskDescriptor etd;
while (it.hasNext()) {
etd = it.next();
if (checkEligibleTaskDescriptorScript.isTaskContainsAPIBinding(etd)) {
// skip task here
it.remove();
}
}
}
if (maxResource > 0 && !bagOfTasks.isEmpty()) {
EligibleTaskDescriptor etd = bagOfTasks.removeFirst();
((EligibleTaskDescriptorImpl) etd).addAttempt();
InternalJob currentJob = ((JobDescriptorImpl) jobsMap.get(etd.getJobId())).getInternal();
InternalTask internalTask = currentJob.getIHMTasks().get(etd.getTaskId());
int neededNodes = internalTask.getNumberOfNodesNeeded();
SchedulingTaskComparator referent = new SchedulingTaskComparator(internalTask, currentJob);
boolean firstLoop = true;
do {
if (!firstLoop) {
// if bagOfTasks is not empty
if (!bagOfTasks.isEmpty()) {
etd = bagOfTasks.removeFirst();
((EligibleTaskDescriptorImpl) etd).addAttempt();
currentJob = ((JobDescriptorImpl) jobsMap.get(etd.getJobId())).getInternal();
internalTask = currentJob.getIHMTasks().get(etd.getTaskId());
neededNodes = internalTask.getNumberOfNodesNeeded();
}
} else {
firstLoop = false;
}
if (neededNodes > maxResource) {
// no instruction is important :
// in this case, a multi node task leads the search to be stopped and the
// the current task would be retried on the next step
// we continue to start the maximum number of task in a single scheduling loop.
// this case will focus on starting single node task first if lot of resources are busy.
// (multi-nodes starvation may occurs)
} else {
// check if the task is compatible with the other previous one
if (referent.equals(new SchedulingTaskComparator(internalTask, currentJob))) {
tlogger.debug(internalTask.getId(), "scheduling");
neededResource += neededNodes;
maxResource -= neededNodes;
toFill.add(etd);
} else {
bagOfTasks.addFirst(etd);
break;
}
}
} while (maxResource > 0 && !bagOfTasks.isEmpty());
}
return neededResource;
}
use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.
the class SchedulingTaskComparator method computeHashForSelectionScripts.
private void computeHashForSelectionScripts(InternalTask task, InternalJob job) {
List<SelectionScript> scriptList = SchedulingMethodImpl.resolveScriptVariables(task.getSelectionScripts(), task.getRuntimeVariables());
for (SelectionScript script : scriptList) {
SelectionScript modifiedScript = script;
try {
Map<String, Serializable> bindings = SchedulingMethodImpl.createBindingsForSelectionScripts(job, task);
modifiedScript = SchedulingMethodImpl.replaceBindingsInsideScript(script, bindings);
} catch (Exception e) {
logger.error("Error while replacing selection script bindings for task " + task.getId(), e);
}
try {
digests.add(new String(modifiedScript.digest()));
} catch (Exception e) {
logger.error("Error while replacing selection script bindings for task " + task.getId(), e);
}
}
}
use of org.ow2.proactive.scheduler.job.InternalJob 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.job.InternalJob in project scheduling by ow2-proactive.
the class JobData method toInternalJob.
InternalJob toInternalJob() {
JobId jobIdInstance = new JobIdImpl(getId(), getJobName());
JobInfoImpl jobInfo = createJobInfo(jobIdInstance);
InternalJob internalJob = new InternalTaskFlowJob();
internalJob.setCredentials(getCredentials());
internalJob.setJobInfo(jobInfo);
internalJob.setGenericInformation(getGenericInformation());
internalJob.setVariables(variablesToJobVariables());
internalJob.setProjectName(getProjectName());
internalJob.setOwner(getOwner());
internalJob.setDescription(getDescription());
internalJob.setInputSpace(getInputSpace());
internalJob.setOutputSpace(getOutputSpace());
internalJob.setGlobalSpace(getGlobalSpace());
internalJob.setUserSpace(getGlobalSpace());
internalJob.setMaxNumberOfExecution(getMaxNumberOfExecution());
internalJob.setOnTaskError(OnTaskError.getInstance(this.onTaskErrorString));
internalJob.setScheduledTimeForRemoval(getScheduledTimeForRemoval());
return internalJob;
}
use of org.ow2.proactive.scheduler.job.InternalJob 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);
}
}
Aggregations