use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class ForkedTaskExecutorRunAsMeTest method runAsMe_PasswordMethod.
@Test
public void runAsMe_PasswordMethod() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
Decrypter decrypter = createCredentials(USERNAME, PASSWORD);
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("whoami", "native")));
container.setRunAsUser(true);
TaskContext taskContext = new TaskContext(container, initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", ""), decrypter);
TaskResultImpl result = taskExecutor.execute(taskContext, taskOutput.outputStream, taskOutput.error);
assertTaskResultOk(result);
assertEquals("admin\n", taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method scriptArgumentsReplacements.
@Test
public void scriptArgumentsReplacements() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
String printArgs = "println(args[0] + args[1]);";
initializer.setPreScript(new SimpleScript(printArgs, "groovy", new Serializable[] { "$credentials_PASSWORD", "$PA_JOB_ID" }));
initializer.setPostScript(new SimpleScript(printArgs, "groovy", new Serializable[] { "$credentials_PASSWORD", "$PA_JOB_ID" }));
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
Decrypter decrypter = createCredentials("somebody_that_does_not_exists");
TaskContext taskContext = new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(printArgs, "groovy", new Serializable[] { "$credentials_PASSWORD", "${PA_JOB_ID}" }))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", ""), decrypter);
new InProcessTaskExecutor().execute(taskContext, taskOutput.outputStream, taskOutput.error);
// pre, task and post
assertEquals(String.format("p4ssw0rd1000%np4ssw0rd1000%np4ssw0rd1000%n"), taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method storePreScriptAbsolute.
@Test
public void storePreScriptAbsolute() 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<>();
File file = File.createTempFile("test", ".py");
genericInfo.put("PRE_SCRIPT_AS_FILE", file.getAbsolutePath());
file.delete();
initializer.setGenericInformation(genericInfo);
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println('hello'); java.lang.Thread.sleep(5); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), 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
assertTrue(file.exists());
String content = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
assertEquals("println('pre')", content);
file.delete();
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method storePreScriptWithoutExtension.
@Test
public void storePreScriptWithoutExtension() 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<>();
File file = File.createTempFile("test", "");
genericInfo.put("PRE_SCRIPT_AS_FILE", file.getAbsolutePath());
file.delete();
initializer.setGenericInformation(genericInfo);
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println('hello'); java.lang.Thread.sleep(5); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), 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
file = new File(file.getAbsolutePath() + ".groovy");
assertTrue(file.exists());
String content = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
assertEquals("println('pre')", content);
file.delete();
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method contextVariables_index.
@Test
public void contextVariables_index() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setReplicationIndex(7);
initializer.setIterationIndex(6);
String script = "result = variables.get('PA_TASK_ITERATION') * variables.get('PA_TASK_REPLICATION')";
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(script, "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals(42, result.value());
}
Aggregations