Search in sources :

Example 21 with InvalidScriptException

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

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsOutputURI.

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

Example 22 with InvalidScriptException

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

the class ForkedTaskVariablesManagerTest method testScriptParametersAreReplaced.

@Test
public void testScriptParametersAreReplaced() throws InvalidScriptException {
    ForkedTaskVariablesManager forkedTaskVariablesManager = new ForkedTaskVariablesManager();
    // Create a variable $[something] inside a python script
    Serializable[] parameters = new Serializable[] { "$" + testVariable1Key };
    Script script = new SimpleScript("print 'hello'", "python", parameters);
    // Create a hash map with key as varialbe name and value as variable value.
    Map<String, Serializable> variables = new HashMap<>();
    variables.put(testVariable1Key, testVariable1Value);
    VariablesMap variablesMap = new VariablesMap();
    variablesMap.setInheritedMap(variables);
    // Replace that variable inside the script parameters with its value in the hash map
    forkedTaskVariablesManager.replaceScriptParameters(script, new HashMap<String, String>(), variablesMap, System.out);
    assertThat((String) parameters[0], is(testVariable1Value));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) Script(org.ow2.proactive.scripting.Script) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Serializable(java.io.Serializable) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) Test(org.junit.Test)

Example 23 with InvalidScriptException

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

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsGlobalURI.

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

Example 24 with InvalidScriptException

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

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsUserURI.

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

Example 25 with InvalidScriptException

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

the class ForkedTaskVariablesManagerTest method testScriptCredentialsAreReplaced.

@Test
public void testScriptCredentialsAreReplaced() throws InvalidScriptException {
    ForkedTaskVariablesManager forkedTaskVariablesManager = new ForkedTaskVariablesManager();
    // Add $credential_[something] variable to new python script
    Serializable[] parameters = new Serializable[] { "$" + ForkedTaskVariablesManager.CREDENTIALS_KEY_PREFIX + testVariable1Key };
    Script script = new SimpleScript("print 'hello'", "python", parameters);
    // Create credentials
    Map<String, String> credentials = new HashMap<>();
    credentials.put(testVariable1Key, testVariable1Value);
    // Replace the credentials inside the script parameters
    forkedTaskVariablesManager.replaceScriptParameters(script, credentials, new VariablesMap(), System.out);
    assertThat((String) parameters[0], is(testVariable1Value));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) Script(org.ow2.proactive.scripting.Script) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Serializable(java.io.Serializable) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) 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