use of org.ow2.proactive.scheduler.task.TaskLauncherInitializer in project scheduling by ow2-proactive.
the class TaskContextVariableExtractor method extractSystemVariables.
/**
* Extract default scheduller context variables, for a complete list see the documentation.
* https://doc.activeeon.com/latest/user/ProActiveUserGuide.html#_proactive_system_variables
*
* @param taskContext object that contains job information to extract the desired variables.
* @return map containing variables with values set.
*/
private Map<String, Serializable> extractSystemVariables(TaskContext taskContext, String nodesFile) {
TaskLauncherInitializer initializer = taskContext.getInitializer();
Map<String, Serializable> variables = new HashMap<>();
variables.put(SchedulerVars.PA_JOB_ID.toString(), initializer.getTaskId().getJobId().value());
variables.put(SchedulerVars.PA_JOB_NAME.toString(), initializer.getTaskId().getJobId().getReadableName());
variables.put(SchedulerVars.PA_TASK_ID.toString(), initializer.getTaskId().value());
variables.put(SchedulerVars.PA_TASK_NAME.toString(), initializer.getTaskId().getReadableName());
variables.put(SchedulerVars.PA_TASK_ITERATION.toString(), initializer.getIterationIndex());
variables.put(SchedulerVars.PA_TASK_REPLICATION.toString(), initializer.getReplicationIndex());
variables.put(SchedulerVars.PA_TASK_PROGRESS_FILE.toString(), taskContext.getProgressFilePath());
variables.put(SchedulerVars.PA_SCHEDULER_HOME.toString(), taskContext.getSchedulerHome());
variables.put(SchedulerVars.PA_USER.toString(), initializer.getJobOwner());
variables.put(SchedulerVars.PA_NODESFILE.toString(), nodesFile);
variables.put(SchedulerVars.PA_NODESNUMBER.toString(), taskContext.getOtherNodesURLs().size() + 1);
variables.put(SchedulerVars.PA_SCHEDULER_REST_URL.toString(), initializer.getSchedulerRestUrl());
variables.put(SchedulerVars.PA_CATALOG_REST_URL.toString(), initializer.getCatalogRestUrl());
return variables;
}
use of org.ow2.proactive.scheduler.task.TaskLauncherInitializer in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method variablesPropagation_fromParentTask.
@Test
public void variablesPropagation_fromParentTask() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
Map<String, Serializable> variablesFromParent = new HashMap<>();
variablesFromParent.put("var", "parent");
variablesFromParent.put(SchedulerVars.PA_TASK_ID.toString(), "1234");
TaskResult[] previousTasksResults = { new TaskResultImpl(null, null, null, null, null, SerializationUtil.serializeVariableMap(variablesFromParent), false) };
new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('var'));print(variables.get('PA_TASK_ID'))", "groovy"))), initializer, previousTasksResults, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals("parent42", taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.TaskLauncherInitializer in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method nodesFileIsCreated.
@Test
public void nodesFileIsCreated() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
ScriptExecutableContainer printNodesFileTask = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print new File(variables.get('PA_NODESFILE')).text", "groovy")));
printNodesFileTask.setNodes(mockedNodeSet());
TaskContext context = new TaskContext(printNodesFileTask, initializer, null, new NodeDataSpacesURIs(tmpFolder.newFolder().getAbsolutePath(), "", "", "", "", ""), "", "thisHost");
TaskResultImpl taskResult = new InProcessTaskExecutor().execute(context, taskOutput.outputStream, taskOutput.error);
assertTaskResultOk(taskResult);
assertEquals(String.format("thisHost%ndummyhost%n"), taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.TaskLauncherInitializer in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method variablesPropagation.
@Test
public void variablesPropagation() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'pre')", "groovy"));
initializer.setPostScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'post')", "groovy"));
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
initializer.setJobVariables(Collections.singletonMap("var", new JobVariable("var", "value")));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'task')", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals("valuepretask", taskOutput.output());
assertEquals("post", SerializationUtil.deserializeVariableMap(result.getPropagatedVariables()).get("var"));
}
use of org.ow2.proactive.scheduler.task.TaskLauncherInitializer in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method failingPrescript.
@Test
public void failingPrescript() throws Exception {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript("return 10/0", "groovy"));
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals("", taskOutput.output());
assertNotEquals("", taskOutput.error());
assertNotNull(result.getException());
}
Aggregations