Search in sources :

Example 56 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class TestExecRemote method processBuilderScript.

private void processBuilderScript(String miscDir, boolean isLinux, String valueToEcho, HashSet<String> nodesUrls) throws Exception {
    File sFile = new File(miscDir + "processBuilder.groovy");
    RMTHelper.log("Test 4 - Test " + sFile);
    String[] cmd = (isLinux) ? new String[] { "/bin/bash", "-c", "echo " + valueToEcho } : new String[] { "cmd.exe", "/c", "@(echo " + valueToEcho + ")" };
    SimpleScript script = new SimpleScript(sFile, cmd);
    List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script, TargetType.NODE_URL.toString(), nodesUrls);
    assertFalse("The results must not be empty", results.size() == 0);
    for (ScriptResult<Object> res : results) {
        String output = res.getOutput();
        assertTrue("The script output must contains " + valueToEcho, output.contains(valueToEcho));
    }
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) SimpleScript(org.ow2.proactive.scripting.SimpleScript) File(java.io.File)

Example 57 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class FlowScript method createContinueFlowScript.

public static FlowScript createContinueFlowScript() throws InvalidScriptException {
    FlowScript fs = new FlowScript(new SimpleScript("", "javascript"));
    fs.setActionType(FlowActionType.CONTINUE);
    return fs;
}
Also used : SimpleScript(org.ow2.proactive.scripting.SimpleScript)

Example 58 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class Job2XMLTransformerTest method argumentsInScript.

@Test
public void argumentsInScript() throws Exception {
    File xmlFile = tmpFolder.newFile();
    TaskFlowJob job = new TaskFlowJob();
    job.setName("simpleJob");
    String[] params = { "param1", "param2" };
    SimpleScript script = new SimpleScript("\nprint('arguments[0]='+arguments[0])\n", "javascript", params);
    ScriptTask task = new ScriptTask();
    task.setName("testTask");
    task.setScript(new TaskScript(script));
    job.addTask(task);
    new Job2XMLTransformer().job2xmlFile(job, xmlFile);
    TaskFlowJob recreatedJob = (TaskFlowJob) (JobFactory.getFactory().createJob(xmlFile.getAbsolutePath()));
    Assert.assertEquals("param1", ((ScriptTask) recreatedJob.getTask("testTask")).getScript().getParameters()[0].toString());
    Assert.assertEquals("param2", ((ScriptTask) recreatedJob.getTask("testTask")).getScript().getParameters()[1].toString());
}
Also used : ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) File(java.io.File) Test(org.junit.Test)

Example 59 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript 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));
    new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print variables.get('PA_USER')", "python"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(jobOwner, taskOutput.output().trim());
}
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 60 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class KillTaskLauncherTest method finished_but_terminate_not_called_back.

@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void finished_but_terminate_not_called_back() throws Throwable {
    final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("result='done'", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory(new Semaphore(0)));
    final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
    TaskResultWaiter taskResultWaiter = new TaskResultWaiter();
    WaitForResultNotification waitForResultNotification = new WaitForResultNotification(taskResultWaiter);
    waitForResultNotification = PAActiveObject.turnActive(waitForResultNotification);
    taskLauncherPA.doTask(executableContainer, null, waitForResultNotification);
    assertEquals("done", taskResultWaiter.getTaskResult().value());
    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

SimpleScript (org.ow2.proactive.scripting.SimpleScript)99 TaskScript (org.ow2.proactive.scripting.TaskScript)78 Test (org.junit.Test)68 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)64 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)31 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)31 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)21 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)19 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)18 File (java.io.File)16 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)13 Serializable (java.io.Serializable)12 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)10 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 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)8 HashMap (java.util.HashMap)7 JobId (org.ow2.proactive.scheduler.common.job.JobId)7