use of org.ow2.proactive.scheduler.common.task.Task 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.common.task.Task 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());
}
}
use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.
the class RMProxyActiveObject method handleCleaningScript.
/**
* Execute the given script on the given node.
* Also register a callback on {@link #cleanCallBack(Future, NodeSet)} method when script has returned.
* @param nodes the nodeset on which to start the script
* @param cleaningScript the script to be executed
* @param variables
* @param genericInformation
* @param taskId
* @param creds credentials with CredData containing third party credentials
*/
private void handleCleaningScript(NodeSet nodes, Script<?> cleaningScript, VariablesMap variables, Map<String, String> genericInformation, TaskId taskId, Credentials creds) {
TaskLogger instance = TaskLogger.getInstance();
try {
this.nodesTaskId.put(nodes, taskId);
// create a decrypter to access scheduler and retrieve Third Party User Credentials
String privateKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PRIVKEY_PATH.getValueAsString());
Decrypter decrypter = new Decrypter(Credentials.getPrivateKey(privateKeyPath));
decrypter.setCredentials(creds);
HashMap<String, Serializable> dictionary = new HashMap<>();
dictionary.putAll(variables.getScriptMap());
dictionary.putAll(variables.getInheritedMap());
dictionary.putAll(variables.getPropagatedVariables());
dictionary.putAll(variables.getScopeMap());
// start handler for binding
ScriptHandler handler = ScriptLoader.createHandler(nodes.get(0));
VariablesMap resolvedMap = new VariablesMap();
resolvedMap.setInheritedMap(VariableSubstitutor.resolveVariables(variables.getInheritedMap(), dictionary));
resolvedMap.setScopeMap(VariableSubstitutor.resolveVariables(variables.getScopeMap(), dictionary));
handler.addBinding(SchedulerConstants.VARIABLES_BINDING_NAME, (Serializable) resolvedMap);
handler.addBinding(SchedulerConstants.GENERIC_INFO_BINDING_NAME, (Serializable) genericInformation);
// retrieve scheduler URL to bind with schedulerapi, globalspaceapi, and userspaceapi
String schedulerUrl = PASchedulerProperties.SCHEDULER_REST_URL.getValueAsString();
logger.debug("Binding schedulerapi...");
SchedulerNodeClient client = new SchedulerNodeClient(decrypter, schedulerUrl);
handler.addBinding(SchedulerConstants.SCHEDULER_CLIENT_BINDING_NAME, (Serializable) client);
logger.debug("Binding globalspaceapi...");
RemoteSpace globalSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.GLOBAL, schedulerUrl);
handler.addBinding(SchedulerConstants.DS_GLOBAL_API_BINDING_NAME, (Serializable) globalSpaceClient);
logger.debug("Binding userspaceapi...");
RemoteSpace userSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.USER, schedulerUrl);
handler.addBinding(SchedulerConstants.DS_USER_API_BINDING_NAME, (Serializable) userSpaceClient);
logger.debug("Binding credentials...");
Map<String, String> resolvedThirdPartyCredentials = VariableSubstitutor.filterAndUpdate(decrypter.decrypt().getThirdPartyCredentials(), dictionary);
handler.addBinding(SchedulerConstants.CREDENTIALS_VARIABLE, (Serializable) resolvedThirdPartyCredentials);
ScriptResult<?> future = handler.handle(cleaningScript);
try {
PAEventProgramming.addActionOnFuture(future, "cleanCallBack", nodes);
} catch (IllegalArgumentException e) {
// TODO - linked to PROACTIVE-936 -> IllegalArgumentException is raised if method name is unknown
// should be replaced by checked exception
instance.error(taskId, "ERROR : Callback method won't be executed, node won't be released. This is a critical state, check the callback method name", e);
}
instance.info(taskId, "Cleaning Script started on node " + nodes.get(0).getNodeInformation().getURL());
} catch (Exception e) {
// if active object cannot be created or script has failed
instance.error(taskId, "Error while starting cleaning script for task " + taskId + " on " + nodes.get(0), e);
releaseNodes(nodes).booleanValue();
}
}
use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.
the class InternalForkedScriptTask method createLauncher.
/**
* {@inheritDoc}
*/
@Override
public TaskLauncher createLauncher(Node node) throws ActiveObjectCreationException, NodeException {
logger.info(getTaskInfo().getTaskId(), "creating forked task launcher");
TaskLauncher launcher = (TaskLauncher) PAActiveObject.newActive(TaskLauncher.class.getName(), new Object[] { getDefaultTaskLauncherInitializer(), new ProActiveForkedTaskLauncherFactory() }, node);
// wait until the task launcher is active
launcher.isActivated();
setExecuterInformation(new ExecuterInformation(launcher, node));
return launcher;
}
use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.
the class InternalScriptTask method createLauncher.
/**
* {@inheritDoc}
*/
@Override
public TaskLauncher createLauncher(Node node) throws ActiveObjectCreationException, NodeException {
logger.info(getTaskInfo().getTaskId(), "creating non forked task launcher");
TaskLauncher launcher = (TaskLauncher) PAActiveObject.newActive(TaskLauncher.class.getName(), new Object[] { getDefaultTaskLauncherInitializer(), new ProActiveNonForkedTaskLauncherFactory() }, node);
// wait until the task launcher is active
launcher.isActivated();
setExecuterInformation(new ExecuterInformation(launcher, node));
return launcher;
}
Aggregations