Search in sources :

Example 26 with InvalidScriptException

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

the class SelectionScriptEvaluator method evaluateScript.

private static void evaluateScript(String selectionScript) {
    try {
        final ScriptHandler localHandler = ScriptLoader.createLocalHandler();
        final ScriptResult<Boolean> result = localHandler.handle(new SelectionScript(new File(selectionScript), null));
        if (result.errorOccured()) {
            result.getException().printStackTrace(System.err);
            System.exit(3);
        }
    } catch (InvalidScriptException e) {
        System.exit(2);
    }
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) File(java.io.File) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 27 with InvalidScriptException

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

the class FlatJobFactory method createNativeTaskFromCommandString.

/**
 * Creates a native task from a string representing a native command to execute.
 * @param command a String representing a native command.
 * @param taskName an eventual name for the task.
 * @param selectionScriptPath path to an existing file containing a selection script code.
 * @return a NativeTask object that can be put in a Job Object.
 * @throws InvalidScriptException if an error occurs in definition of selection script
 * from file path specified.
 */
private NativeTask createNativeTaskFromCommandString(String command, String taskName, String selectionScriptPath) throws InvalidScriptException {
    NativeTask desc = new NativeTask();
    desc.setCommandLine(Tools.parseCommandLine(command));
    desc.setName(taskName);
    if (selectionScriptPath != null) {
        SelectionScript script = new SelectionScript(new SimpleScript(new File(selectionScriptPath), null), true);
        desc.addSelectionScript(script);
    }
    return desc;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) File(java.io.File)

Example 28 with InvalidScriptException

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

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

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsResultMetadata.

@Test
public void testAddBindingsToScriptHandlerContainsResultMetadata() throws InvalidScriptException, NodeException, NoSuchFieldException, IllegalAccessException {
    ScriptHandler scriptHandler = new ScriptHandler();
    Map<String, String> resultMetadata = new HashMap<>();
    validateThatScriptHandlerBindingsContain(scriptHandler, createTaskContext(null), new VariablesMap(), new HashMap<String, String>(), resultMetadata, SchedulerConstants.RESULT_METADATA_VARIABLE, resultMetadata);
}
Also used : HashMap(java.util.HashMap) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler) Test(org.junit.Test)

Example 30 with InvalidScriptException

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

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsScratchURI.

@Test
public void testAddBindingsToScriptHandlerContainsScratchURI() 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(testSetString, null, null, null, null, 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_SCRATCH_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)

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