use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.
the class TaskData method toInternalTask.
InternalTask toInternalTask(InternalJob internalJob, boolean loadFullState) throws InvalidScriptException {
TaskId taskId = createTaskId(internalJob);
InternalTask internalTask;
if (taskType.equals(SCRIPT_TASK)) {
internalTask = new InternalScriptTask(internalJob);
} else if (taskType.equals(FORKED_SCRIPT_TASK)) {
internalTask = new InternalForkedScriptTask(internalJob);
} else {
throw new IllegalStateException("Unexpected stored task type: " + taskType);
}
internalTask.setId(taskId);
internalTask.setDescription(getDescription());
internalTask.setTag(this.getTag());
internalTask.setStatus(getTaskStatus());
internalTask.setJobInfo(internalJob.getJobInfo());
internalTask.setName(getTaskName());
internalTask.setExecutionDuration(getExecutionDuration());
internalTask.setFinishedTime(getFinishedTime());
internalTask.setInErrorTime(getInErrorTime());
internalTask.setStartTime(getStartTime());
internalTask.setScheduledTime(getScheduledTime());
internalTask.setExecutionHostName(getExecutionHostName());
internalTask.setOnTaskError(OnTaskError.getInstance(this.onTaskErrorString));
internalTask.setPreciousLogs(isPreciousLogs());
internalTask.setPreciousResult(isPreciousResult());
internalTask.setRunAsMe(isRunAsMe());
internalTask.setWallTime(getWallTime());
internalTask.setMaxNumberOfExecution(getMaxNumberOfExecution());
internalTask.setNumberOfExecutionLeft(getNumberOfExecutionLeft());
internalTask.setNumberOfExecutionOnFailureLeft(getNumberOfExecutionOnFailureLeft());
internalTask.setRestartTaskOnError(getRestartMode());
internalTask.setFlowBlock(getFlowBlock());
internalTask.setIterationIndex(getIteration());
internalTask.setReplicationIndex(getReplication());
internalTask.setMatchingBlock(getMatchingBlock());
internalTask.setVariables(variablesToTaskVariables());
if (hasAliveTaskLauncher() && getExecuterInformationData() != null) {
internalTask.setExecuterInformation(getExecuterInformationData().toExecuterInformation(loadFullState));
}
ForkEnvironment forkEnv = createForkEnvironment();
internalTask.setForkEnvironment(forkEnv);
return internalTask;
}
use of org.ow2.proactive.scheduler.common.task.Task 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;
}
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 JobDescriptorImpl method terminate.
/**
* Update the eligible list of task and dependencies if necessary.
* This function considered that the taskId is in eligible task list.
* Visibility is package because user cannot use this method.
*
* @param taskId the task to remove from running task.
*/
public void terminate(TaskId taskId, boolean inErrorTask) {
Map<TaskId, ? extends TaskDescriptor> currentTasks = inErrorTask ? pausedTasks : runningTasks;
List<TaskId> taskIdsToSkip = new ArrayList<>();
if (getInternal().getType() == JobType.TASKSFLOW) {
TaskDescriptor taskToTerminate = currentTasks.get(taskId);
if (taskToTerminate != null) {
for (TaskDescriptor childTask : taskToTerminate.getChildren()) {
decreaseParentCount(childTask);
if (((EligibleTaskDescriptorImpl) childTask).getCount() == 0) {
if (internalJob.getStatus() == JobStatus.PAUSED) {
pausedTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
} else if (internalJob.getStatus() == JobStatus.IN_ERROR && ((EligibleTaskDescriptorImpl) childTask).getInternal().getStatus() == TaskStatus.PAUSED) {
pausedTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
} else if (((EligibleTaskDescriptorImpl) childTask).getInternal().getStatus() == TaskStatus.SKIPPED) {
runningTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
taskIdsToSkip.add(childTask.getTaskId());
} else {
eligibleTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
}
}
}
decreaseChildrenCountForAllParents(taskToTerminate);
}
}
currentTasks.remove(taskId);
for (TaskId taskIdToSkip : taskIdsToSkip) {
terminate(taskIdToSkip);
}
}
use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.
the class JobDescriptorImpl method doLoop.
/**
* Complete LOOP action on JobDescriptor side
*
* @param initiator Task initiating the LOOP action
* @param tree InternalTask tree of replicated tasks
* @param target Target task of the LOOP action
*/
public void doLoop(TaskId initiator, Map<TaskId, InternalTask> tree, InternalTask target, InternalTask newInit) {
Map<TaskId, EligibleTaskDescriptorImpl> acc = new HashMap<>();
// create new EligibleTasks and accumulate it
for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
TaskId itId = it.getValue().getId();
EligibleTaskDescriptorImpl td = new EligibleTaskDescriptorImpl(it.getValue());
acc.put(itId, td);
}
EligibleTaskDescriptorImpl oldEnd = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
EligibleTaskDescriptorImpl newStart = acc.get(target.getId());
EligibleTaskDescriptorImpl newEnd = acc.get(newInit.getId());
// plug the end of the old tree (initiator) to the beginning of the new (target)
for (TaskDescriptor ot : oldEnd.getChildren()) {
newEnd.addChild(ot);
ot.getParents().remove(oldEnd);
ot.getParents().add(newEnd);
}
oldEnd.clearChildren();
// recreate the dependencies
for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
TaskId itId = it.getValue().getTaskInfo().getTaskId();
EligibleTaskDescriptorImpl down = acc.get(itId);
List<InternalTask> ideps = new ArrayList<>();
int deptype = 0;
if (it.getValue().hasDependences()) {
ideps.addAll(it.getValue().getIDependences());
}
if (it.getValue().getIfBranch() != null) {
deptype = 1;
ideps.add(it.getValue().getIfBranch());
}
if (it.getValue().getJoinedBranches() != null) {
deptype = 2;
ideps.addAll(it.getValue().getJoinedBranches());
}
if (ideps.size() > 0 && !target.equals(itId)) {
for (InternalTask parent : ideps) {
if (parent == null) {
continue;
}
EligibleTaskDescriptorImpl up = acc.get(parent.getTaskInfo().getTaskId());
switch(deptype) {
case 0:
if (parent.getId().equals(initiator)) {
up = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
}
up.addChild(down);
down.addParent(up);
break;
case 1:
case 2:
// 'weak' dependencies from FlowAction#IF are not
// represented in TaskDescriptor
branchTasks.put(down.getTaskId(), down);
break;
}
}
}
}
// EligibleTaskDescriptorImpl newTask = (EligibleTaskDescriptorImpl) acc.get(target.getId());
setNewLoopTaskToPausedIfJobIsPaused(newStart);
putNewLoopTaskIntoPausedOrEligableList(target.getId(), newStart);
runningTasks.remove(initiator);
}
Aggregations