Search in sources :

Example 6 with SimpleScript

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

the class InstallPackageCommand method executeScript.

private ScriptResult executeScript(Map<String, Object> schedulerProperties, String packageDirPath) throws InvalidScriptException {
    ByteArrayOutputStream outputStream = null;
    PrintStream printStream = null;
    File scriptFile = new File(PASchedulerProperties.getAbsolutePath(SCRIPT_PATH));
    String[] param = { packageDirPath };
    ScriptResult scriptResult = null;
    if (scriptFile.exists()) {
        outputStream = new ByteArrayOutputStream();
        printStream = new PrintStream(outputStream, true);
        scriptResult = new SimpleScript(scriptFile, param).execute(schedulerProperties, printStream, printStream);
        logger.info(outputStream.toString());
        outputStream.reset();
    } else {
        logger.warn("Load package script " + scriptFile.getPath() + " not found");
    }
    if (outputStream != null) {
        try {
            outputStream.close();
        } catch (IOException e) {
        // ignore
        }
    }
    if (printStream != null) {
        printStream.close();
    }
    return scriptResult;
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) PrintStream(java.io.PrintStream) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 7 with SimpleScript

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

the class SchedulerClientTest method nodeClientJob.

protected Job nodeClientJob(String groovyScript, String forkScript) throws Exception {
    URL scriptURL = SchedulerClientTest.class.getResource(groovyScript);
    URL forkScriptURL = SchedulerClientTest.class.getResource(forkScript);
    TaskFlowJob job = new TaskFlowJob();
    job.setName("NodeClientJob");
    ScriptTask task = new ScriptTask();
    task.setName("NodeClientTask");
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.setEnvScript(new SimpleScript(IOUtils.toString(forkScriptURL.toURI()), "groovy"));
    task.setForkEnvironment(forkEnvironment);
    task.setScript(new TaskScript(new SimpleScript(IOUtils.toString(scriptURL.toURI()), "groovy")));
    // add CleanScript to test external APIs
    task.setCleaningScript(new SimpleScript("" + "schedulerapi.connect();\n" + "print(\"SCHEDULERAPI_URI_LIST_NOT_NULL=\"+(schedulerapi.getGlobalSpaceURIs()!=null));\n" + "\n" + "userspaceapi.connect();\n" + "print(\"USERSPACE_FILE_LIST_NOT_NULL=\"+(userspaceapi.listFiles(\".\", \"*\")!=null));\n" + "\n" + "globalspaceapi.connect();\n" + "print(\"GLOBALSPACE_FILE_LIST_NOT_NULL=\"+(globalspaceapi.listFiles(\".\", \"*\")!=null));\n" + "print(\"TEST_CREDS=\"+(credentials.get(\"TEST_CREDS\")));\n", "js"));
    job.addTask(task);
    return job;
}
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) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) URL(java.net.URL)

Example 8 with SimpleScript

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

the class TestForkEnvironment method testScript.

@Test
public void testScript() throws InvalidScriptException {
    forkEnvironment.setEnvScript(new SimpleScript("var a=1;", "js"));
    Assert.assertTrue(forkEnvironment.getEnvScript() != null);
    forkEnvironment.setEnvScript(null);
    Assert.assertTrue(forkEnvironment.getEnvScript() == null);
}
Also used : SimpleScript(org.ow2.proactive.scripting.SimpleScript) Test(org.junit.Test)

Example 9 with SimpleScript

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

the class InProcessTaskExecutorTest method variablesPropagation_fromParentTask.

@Test
public void variablesPropagation_fromParentTask() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
    Map<String, Serializable> variablesFromParent = new HashMap<>();
    variablesFromParent.put("var", "parent");
    variablesFromParent.put(SchedulerVars.PA_TASK_ID.toString(), "1234");
    TaskResult[] previousTasksResults = { new TaskResultImpl(null, null, null, null, null, SerializationUtil.serializeVariableMap(variablesFromParent), false) };
    new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('var'));print(variables.get('PA_TASK_ID'))", "groovy"))), initializer, previousTasksResults, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals("parent42", 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) 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) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 10 with SimpleScript

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

the class InProcessTaskExecutorTest method nodesFileIsCreated.

@Test
public void nodesFileIsCreated() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    ScriptExecutableContainer printNodesFileTask = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print new File(variables.get('PA_NODESFILE')).text", "groovy")));
    printNodesFileTask.setNodes(mockedNodeSet());
    TaskContext context = new TaskContext(printNodesFileTask, initializer, null, new NodeDataSpacesURIs(tmpFolder.newFolder().getAbsolutePath(), "", "", "", "", ""), "", "thisHost");
    TaskResultImpl taskResult = new InProcessTaskExecutor().execute(context, taskOutput.outputStream, taskOutput.error);
    assertTaskResultOk(taskResult);
    assertEquals(String.format("thisHost%ndummyhost%n"), taskOutput.output());
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) 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)

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