Search in sources :

Example 16 with InvalidScriptException

use of org.ow2.proactive.scripting.InvalidScriptException 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 17 with InvalidScriptException

use of org.ow2.proactive.scripting.InvalidScriptException 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 18 with InvalidScriptException

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

the class TaskContextTest method createTaskContext.

private TaskContext createTaskContext() throws NodeException, InvalidScriptException {
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1L, "testSerializeContextToFile"), "testSerializeContextToFile", 1L));
    // Invoke method to test it
    return new TaskContext(new ScriptExecutableContainer(new TaskScript(new ForkEnvironmentScript(new SimpleScript("", "python")))), taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) 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) ForkEnvironmentScript(org.ow2.proactive.scripting.ForkEnvironmentScript)

Example 19 with InvalidScriptException

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

the class TaskContextSerializerTest method createTaskContext.

private TaskContext createTaskContext() throws NodeException, InvalidScriptException {
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1L, "testSerializeContextToFile"), "testSerializeContextToFile", 1L));
    // Invoke method to test it
    return new TaskContext(new ScriptExecutableContainer(new TaskScript(new ForkEnvironmentScript(new SimpleScript("", "python")))), taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) ForkEnvironmentScript(org.ow2.proactive.scripting.ForkEnvironmentScript)

Example 20 with InvalidScriptException

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

the class ForkedJvmTaskExecutionCommandCreatorTest method createTaskContext.

private TaskContext createTaskContext() throws InvalidScriptException, NodeException {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariableAndForkEnvironment();
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
    return taskContext;
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer)

Aggregations

Test (org.junit.Test)27 SimpleScript (org.ow2.proactive.scripting.SimpleScript)27 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)15 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)15 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)14 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)14 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)14 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)12 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)12 TaskScript (org.ow2.proactive.scripting.TaskScript)12 FlowScript (org.ow2.proactive.scheduler.common.task.flow.FlowScript)11 Script (org.ow2.proactive.scripting.Script)11 HashMap (java.util.HashMap)6 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)6 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)6 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)6 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)5 File (java.io.File)4 SelectionScript (org.ow2.proactive.scripting.SelectionScript)4 Serializable (java.io.Serializable)3