Search in sources :

Example 26 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsUserURI.

@Test
public void testAddBindingsToScriptHandlerContainsUserURI() throws InvalidScriptException, NodeException, NoSuchFieldException, IllegalAccessException {
    ScriptExecutableContainer scriptContainer = createScriptContainer();
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setForkEnvironment(new ForkEnvironment());
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, testSetString, null), null, null);
    // Expect taskResultArray to be inside the map
    validateThatScriptHandlerBindingsContain(new ScriptHandler(), taskContext, new VariablesMap(), new HashMap<String, String>(), new HashMap<String, String>(), SchedulerConstants.DS_USER_BINDING_NAME, testSetString);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler) Test(org.junit.Test)

Example 27 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("", "", "", "", "", ""), "", "", 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) 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 28 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.

the class ForkedTaskExecutorTest method nonDaemonThreadsForkedJVMExit.

/**
 * This test ensures that the forked JVM exited properly when non-daemon threads are created inside the task
 *
 * @throws Exception
 */
@Test(timeout = 30000)
public void nonDaemonThreadsForkedJVMExit() throws Exception {
    String taskScript = CharStreams.toString(new InputStreamReader(getClass().getResourceAsStream("/task-nondaemon-thread.groovy"), Charsets.UTF_8));
    TestTaskOutput taskOutput = new TestTaskOutput();
    File workingDir = tmpFolder.newFolder();
    ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(workingDir);
    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(taskScript, "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    Assert.assertFalse(result.hadException());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InputStreamReader(java.io.InputStreamReader) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TestTaskOutput(org.ow2.proactive.scheduler.task.TestTaskOutput) File(java.io.File) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 29 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.

the class InProcessTaskExecutorTest method simpleScriptTask.

@Test
public void simpleScriptTask() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setPreScript(new SimpleScript("println('pre')", "groovy"));
    initializer.setPostScript(new SimpleScript("println('post')", "groovy"));
    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("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(String.format("pre%nhello%npost%n"), taskOutput.output());
    assertEquals("hello", result.value());
    assertTrue("Task duration should be at least 5", result.getTaskDuration() >= 5);
}
Also used : 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) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 30 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("", "", "", "", "", ""), "", "", 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) 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)80 Test (org.junit.Test)68 SimpleScript (org.ow2.proactive.scripting.SimpleScript)64 TaskScript (org.ow2.proactive.scripting.TaskScript)64 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)42 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)42 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)29 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)18 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)17 Serializable (java.io.Serializable)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)10 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)9 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 File (java.io.File)8 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)8 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)8 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)6 HashMap (java.util.HashMap)5