use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer 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.containers.ScriptExecutableContainer 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);
}
use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method ensureForkedJvmContainTaskForkProperty.
@Test
public void ensureForkedJvmContainTaskForkProperty() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "sample", 1000L)));
ForkedTaskExecutor forkedTaskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
TaskResultImpl result = forkedTaskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("result=System.getProperty('" + PASchedulerProperties.TASK_FORK.getKey() + "')", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
Assert.assertEquals("true", result.value());
}
use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method result_and_variables.
@Test
public void result_and_variables() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
TaskResultImpl result = taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); variables.put('var','foo'); result='hello'", "javascript"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals(String.format("hello%n"), taskOutput.output());
assertEquals("hello", result.value());
assertEquals("foo", SerializationUtil.deserializeVariableMap(result.getPropagatedVariables()).get("var"));
}
use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method runAsMe_userDoesNotExist.
@Test
public void runAsMe_userDoesNotExist() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
Decrypter decrypter = createCredentials("somebody_that_does_not_exists");
ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
ScriptExecutableContainer container = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
container.setRunAsUser(true);
TaskContext taskContext = new TaskContext(container, initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", ""), decrypter);
TaskResultImpl result = taskExecutor.execute(taskContext, taskOutput.outputStream, taskOutput.error);
assertNotNull(result.getException());
}
Aggregations