use of org.ow2.proactive.scheduler.common.task.TaskResult 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.common.task.TaskResult 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.common.task.TaskResult in project scheduling by ow2-proactive.
the class TaskLauncherDataSpacesTest method input_file_using_variable_in_its_selector.
@Test
public void input_file_using_variable_in_its_selector() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("println new File('.').listFiles();", "groovy")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
initializer.setJobVariables(singletonMap("aVar", new JobVariable("aVar", "foo")));
initializer.setTaskInputFiles(singletonList(new InputSelector(new FileSelector("input_${aVar}_${aResultVar}.txt"), InputAccessMode.TransferFromInputSpace)));
File inputFile = new File(taskLauncherFactory.getDataSpaces().getInputURI(), "input_foo_bar.txt");
assertTrue(inputFile.createNewFile());
TaskResultImpl previousTaskResult = taskResult(Collections.<String, Serializable>singletonMap("aResultVar", "bar"));
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, taskLauncherFactory), executableContainer, previousTaskResult);
assertTaskResultOk(taskResult);
assertTrue(taskResult.getOutput().getAllLogs(false).contains("input_foo_bar.txt"));
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class TaskLauncherDataSpacesTest method output_file_using_variable_in_its_selector.
@Test
public void output_file_using_variable_in_its_selector() throws Throwable {
ScriptExecutableContainer createAFileAndWriteVariable = new ScriptExecutableContainer(new TaskScript(new SimpleScript("new File('output_foo_bar.txt').text = 'hello'; variables.put('aVar', 'foo')", "groovy")));
TaskLauncherInitializer copyOutputFile = new TaskLauncherInitializer();
copyOutputFile.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
copyOutputFile.setTaskOutputFiles(singletonList(new OutputSelector(new FileSelector("output_${aVar}_${aResultVar}.txt"), OutputAccessMode.TransferToGlobalSpace)));
TaskResultImpl previousTaskResult = taskResult(Collections.<String, Serializable>singletonMap("aResultVar", "bar"));
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(copyOutputFile, taskLauncherFactory), createAFileAndWriteVariable, previousTaskResult);
assertTaskResultOk(taskResult);
assertTrue(new File(taskLauncherFactory.getDataSpaces().getGlobalURI(), "output_foo_bar.txt").exists());
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class TaskLauncherDataSpacesTest method input_file_using_job_id_in_its_selector.
@Test
public void input_file_using_job_id_in_its_selector() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("println new File('.').listFiles();", "groovy")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
initializer.setTaskInputFiles(singletonList(new InputSelector(new FileSelector("input_$PA_JOB_ID.txt"), InputAccessMode.TransferFromInputSpace)));
File inputFile = new File(taskLauncherFactory.getDataSpaces().getInputURI(), "input_1000.txt");
assertTrue(inputFile.createNewFile());
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, taskLauncherFactory), executableContainer);
assertFalse(taskResult.hadException());
assertTrue(taskResult.getOutput().getAllLogs(false).contains("input_1000.txt"));
}
Aggregations