Search in sources :

Example 1 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer 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());
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TestTaskOutput(org.ow2.proactive.scheduler.task.TestTaskOutput) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 2 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer 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());
}
Also used : Serializable(java.io.Serializable) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 3 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer 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();
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) File(java.io.File) Test(org.junit.Test)

Example 4 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer 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();
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) File(java.io.File) Test(org.junit.Test)

Example 5 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer 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());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Aggregations

ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)84 Test (org.junit.Test)71 SimpleScript (org.ow2.proactive.scripting.SimpleScript)67 TaskScript (org.ow2.proactive.scripting.TaskScript)67 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)46 NodeInfo (org.ow2.proactive.scheduler.task.context.NodeInfo)46 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)46 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)29 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)22 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)18 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)17 File (java.io.File)12 Serializable (java.io.Serializable)11 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)10 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)9 HashMap (java.util.HashMap)8 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)8