use of org.ow2.proactive.scheduler.core.SchedulingService in project scheduling by ow2-proactive.
the class SchedulingMethodImpl method updateVariablesForTasksToSchedule.
/**
* Update all variables for the given scheduled tasks
*/
private void updateVariablesForTasksToSchedule(LinkedList<EligibleTaskDescriptor> tasksToSchedule) {
for (EligibleTaskDescriptor taskDescriptor : tasksToSchedule) {
InternalTask internalTask = ((EligibleTaskDescriptorImpl) taskDescriptor).getInternal();
internalTask.updateVariables(schedulingService);
}
}
use of org.ow2.proactive.scheduler.core.SchedulingService in project scheduling by ow2-proactive.
the class SchedulingMethodImpl method createExecution.
/**
* Create launcher and try to start the task.
*
* @param nodeSet the node set containing every available nodes that can be used for execution
* @param node the node on which to start the task
* @param job the job that owns the task to be started
* @param task the task to be started
* @param taskDescriptor the descriptor of the task to be started
*/
protected boolean createExecution(NodeSet nodeSet, Node node, InternalJob job, InternalTask task, TaskDescriptor taskDescriptor) throws Exception {
TaskLauncher launcher = null;
LiveJobs.JobData jobData = null;
try {
jobData = schedulingService.lockJob(job.getId());
// task is not paused
if (nodeSet.size() >= task.getNumberOfNodesNeeded() && (task.getStatus() != TaskStatus.PAUSED) && (jobData != null)) {
// start dataspace app for this job
DataSpaceServiceStarter dsStarter = schedulingService.getInfrastructure().getDataSpaceServiceStarter();
job.startDataSpaceApplication(dsStarter.getNamingService(), ImmutableList.of(task));
NodeSet nodes = new NodeSet();
try {
// create launcher
launcher = task.createLauncher(node);
activeObjectCreationRetryTimeNumber = ACTIVEOBJECT_CREATION_RETRY_TIME_NUMBER;
nodeSet.remove(0);
// we will need to update this code once topology will be allowed for single-node task
if (task.isParallel()) {
nodes = new NodeSet(nodeSet);
task.getExecuterInformation().addNodes(nodes);
nodeSet.clear();
}
// set nodes in the executable container
task.getExecutableContainer().setNodes(nodes);
tlogger.debug(task.getId(), "deploying");
// above 500 parent tasks, it is worth adjusting.
if (taskDescriptor.getParents().size() > 500) {
dotaskActionTimeout = (int) (taskDescriptor.getParents().size() / 500.0 * PASchedulerProperties.SCHEDULER_STARTTASK_TIMEOUT.getValueAsInt());
} else {
// reset the dotaskActionTimeout to its default value otherwise.
dotaskActionTimeout = PASchedulerProperties.SCHEDULER_STARTTASK_TIMEOUT.getValueAsInt();
}
boolean taskRecoverable = getRMProxiesManager().getRmProxy().areNodesRecoverable(nodes);
String terminateNotificationNodeURL = PAActiveObject.getActiveObjectNode(terminateNotification).getNodeInformation().getURL();
TaskRecoveryData taskRecoveryData = new TaskRecoveryData(terminateNotificationNodeURL, taskRecoverable);
threadPool.submitWithTimeout(new TimedDoTaskAction(job, taskDescriptor, launcher, schedulingService, terminateNotification, corePrivateKey, taskRecoveryData), dotaskActionTimeout, TimeUnit.MILLISECONDS);
// we advertise here that the task is started, however
// this is not entirely true: the only thing we are sure
// about at this point is that we submitted to the thread
// pool the action that will call the "doTask" of the task
// launcher. There is thus a small gap here where the task
// is seen as started whereas it is not yet started. We
// cannot easily move the task started notification because
// 1) it makes the job lock acquisition less predictable
// (because the TimeDoTaskAction will have to compete with
// the SchedulingMethodImpl)
// and more importantly 2) the
// SchedulingMethodImpl#createExecution may happen to be
// called a second time for the task that is currently being
// started by the TimedDoTaskAction.
finalizeStarting(job, task, node, launcher);
return true;
} catch (Exception t) {
try {
// if there was a problem, free nodeSet for multi-nodes task
nodes.add(node);
releaseNodes(job, nodes);
} catch (Throwable ni) {
// miam miam
}
throw t;
}
} else {
return false;
}
} finally {
if (jobData != null) {
jobData.unlock();
}
}
}
use of org.ow2.proactive.scheduler.core.SchedulingService 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.SchedulingService 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.SchedulingService in project scheduling by ow2-proactive.
the class BaseServiceTest method init.
@Before
public void init() throws Exception {
dbManager = SchedulerDBManager.createInMemorySchedulerDBManager();
infrastructure = new MockSchedulingInfrastructure(dbManager);
listener = new MockSchedulingListener();
service = new SchedulingService(infrastructure, listener, null, DefaultPolicy.class.getName(), Mockito.mock(SchedulingMethod.class));
}
Aggregations