use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method failingFlowScript.
@Test
public void failingFlowScript() throws Exception {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setControlFlowScript(FlowScript.createReplicateFlowScript(""));
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("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals("hello", taskOutput.output());
assertNotEquals("", taskOutput.error());
assertNotNull(result.getException());
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method result_from_parent_task.
@Test
public void result_from_parent_task() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
TaskResult[] previousTasksResults = { new TaskResultImpl(null, "aresult", null, 0) };
new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(results[0]);", "groovy"))), initializer, previousTasksResults, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals("aresult", taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method schedulerHomeIsInVariables.
@Test
public void schedulerHomeIsInVariables() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('PA_SCHEDULER_HOME'))", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals(ClasspathUtils.findSchedulerHome(), taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method testPaUserVariableAvailabilityFromScriptEngine.
@Test
public void testPaUserVariableAvailabilityFromScriptEngine() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
String jobOwner = "JohnDoe";
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setJobOwner(jobOwner);
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print variables.get('PA_USER')", "python"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals(jobOwner, taskOutput.output().trim());
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method storePreScriptRelative.
@Test
public void storePreScriptRelative() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript("println('pre')", "groovy"));
initializer.setPostScript(new SimpleScript("println('post')", "groovy"));
Map<String, String> genericInfo = new HashMap<>();
genericInfo.put("PRE_SCRIPT_AS_FILE", "test.py");
initializer.setGenericInformation(genericInfo);
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
Path p = Files.createTempDirectory("");
TaskContext taskContext = new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println('hello'); java.lang.Thread.sleep(5); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs(p.toString(), "", "", "", "", ""), "", new NodeInfo("", "", "", ""));
TaskResultImpl result = new InProcessTaskExecutor().execute(taskContext, taskOutput.outputStream, taskOutput.error);
// Make sure that the execution of the pre-script is skipped
assertEquals(String.format("hello%npost%n"), taskOutput.output());
assertEquals("hello", result.value());
// Make sure that the pre-script is stored in a file
String uri = taskContext.getNodeDataSpaceURIs().getScratchURI();
File file = new File(uri, "test.py");
assertTrue(file.exists());
String content = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
assertEquals("println('pre')", content);
file.delete();
Files.delete(p);
}
Aggregations