Search in sources :

Example 76 with ScriptExecutableContainer

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

the class ForkedTaskExecutorTest method forkEnvironment_failingEnvScript.

@Test
public void forkEnvironment_failingEnvScript() throws Exception {
    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)));
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.setEnvScript(new SimpleScript("should fail execution", "groovy"));
    initializer.setForkEnvironment(forkEnvironment);
    TaskResultImpl taskResult = taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
    assertTrue(taskResult.hadException());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) 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) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) 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 77 with ScriptExecutableContainer

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

the class ForkedTaskExecutorTest method failToFindJava.

@Test
public void failToFindJava() throws Throwable {
    System.setProperty("java.home", "does not exist");
    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'); result='hello'", "javascript"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
    assertNotNull(result.getException());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) 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) 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 78 with ScriptExecutableContainer

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

the class ForkedTaskExecutorTest method forkEnvironment.

@Test
public void forkEnvironment() throws Exception {
    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)));
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.addSystemEnvironmentVariable("envVar", "envValue");
    forkEnvironment.addJVMArgument("-DjvmArg=jvmValue");
    initializer.setForkEnvironment(forkEnvironment);
    taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println System.getenv('envVar'); " + "println System.getProperty('jvmArg'); " + "println new File('.').getCanonicalPath()", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
    assertEquals(String.format("envValue%njvmValue%n%s%n", new File(workingDir, ".").getCanonicalPath()), taskOutput.output());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) 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 79 with ScriptExecutableContainer

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

the class ForkedTaskExecutorTest method forkEnvironment_WithVariables.

@Test
public void forkEnvironment_WithVariables() throws Exception {
    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)));
    initializer.setJobVariables(Collections.singletonMap("aVar", new JobVariable("aVar", "aValue")));
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.addSystemEnvironmentVariable("envVar", "$aVar");
    forkEnvironment.addJVMArgument("-DjvmArg=$aVar");
    initializer.setForkEnvironment(forkEnvironment);
    taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println System.getenv('envVar'); " + "println System.getProperty('jvmArg'); " + "println new File('.').getCanonicalPath()", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
    assertEquals(String.format("aValue%naValue%n%s%n", new File(workingDir, ".").getCanonicalPath()), taskOutput.output());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) 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 80 with ScriptExecutableContainer

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

the class KillTaskLauncherTest method kill_while_sleeping_in_task.

@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void kill_while_sleeping_in_task() throws Exception {
    final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("java.lang.Thread.sleep(10000)", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    Semaphore taskRunning = new Semaphore(0);
    final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory(taskRunning));
    final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
    taskLauncherPA.doTask(executableContainer, null, null);
    taskRunning.acquire();
    taskLauncherPA.kill();
    assertTaskLauncherIsTerminated(taskLauncherPA);
    PAActiveObject.terminateActiveObject(taskLauncherPA, true);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) Repeat(org.ow2.proactive.utils.Repeat)

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