Search in sources :

Example 36 with TaskContext

use of org.ow2.proactive.scheduler.task.context.TaskContext in project scheduling by ow2-proactive.

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsCacheURI.

@Test
public void testAddBindingsToScriptHandlerContainsCacheURI() 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, testSetString, 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_CACHE_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 37 with TaskContext

use of org.ow2.proactive.scheduler.task.context.TaskContext in project scheduling by ow2-proactive.

the class ForkedTaskVariablesManagerTest method initializeForkedTaskVariableManager.

private Map<String, Object> initializeForkedTaskVariableManager(ScriptHandler scriptHandler, TaskContext taskContext, VariablesMap variables, Map<String, String> credentials, Map<String, String> resultMetadata) throws IllegalAccessException, NoSuchFieldException {
    // Create class
    ForkedTaskVariablesManager forkedTaskVariablesManager = new ForkedTaskVariablesManager();
    // Replace additionalBindings to hold a reference to it
    Map<String, Object> scriptHandlerBindings = new HashMap<>();
    setPrivateField(ScriptHandler.class.getDeclaredField("additionalBindings"), scriptHandler, scriptHandlerBindings);
    SchedulerNodeClient schedulerNodeClient = forkedTaskVariablesManager.createSchedulerNodeClient(taskContext);
    // Execute method which adds bindings
    forkedTaskVariablesManager.addBindingsToScriptHandler(scriptHandler, taskContext, variables, credentials, schedulerNodeClient, forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.USER), forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.GLOBAL), resultMetadata);
    return scriptHandlerBindings;
}
Also used : HashMap(java.util.HashMap) SchedulerNodeClient(org.ow2.proactive.scheduler.task.client.SchedulerNodeClient) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 38 with TaskContext

use of org.ow2.proactive.scheduler.task.context.TaskContext in project scheduling by ow2-proactive.

the class ForkedTaskVariablesManagerTest method testExtractThirdPartyCredentialsThrowsExceptionIfTaskLauncherInitializerIsNull.

@Test(expected = Exception.class)
public void testExtractThirdPartyCredentialsThrowsExceptionIfTaskLauncherInitializerIsNull() throws Exception {
    ScriptExecutableContainer scriptContainer = createScriptContainer();
    TaskContext taskContext = new TaskContext(scriptContainer, null, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
    ForkedTaskVariablesManager forkedTaskVariablesManager = new ForkedTaskVariablesManager();
    forkedTaskVariablesManager.extractThirdPartyCredentials(taskContext);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 39 with TaskContext

use of org.ow2.proactive.scheduler.task.context.TaskContext in project scheduling by ow2-proactive.

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsForkEnvironment.

@Test
public void testAddBindingsToScriptHandlerContainsForkEnvironment() throws InvalidScriptException, NodeException, NoSuchFieldException, IllegalAccessException {
    TaskContext taskContext = createTaskContext(null);
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    taskContext.getInitializer().setForkEnvironment(forkEnvironment);
    // Expect taskResultArray to be inside the map
    validateThatScriptHandlerBindingsContain(new ScriptHandler(), taskContext, new VariablesMap(), new HashMap<String, String>(), new HashMap<String, String>(), SchedulerConstants.FORK_ENVIRONMENT_BINDING_NAME, forkEnvironment);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler) Test(org.junit.Test)

Example 40 with TaskContext

use of org.ow2.proactive.scheduler.task.context.TaskContext in project scheduling by ow2-proactive.

the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsUserAndGlobalSpaceApiVariable.

@Test
public void testAddBindingsToScriptHandlerContainsUserAndGlobalSpaceApiVariable() throws InvalidScriptException, NodeException, NoSuchFieldException, IllegalAccessException, KeyException, NoSuchAlgorithmException {
    ScriptExecutableContainer scriptContainer = createScriptContainer();
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setForkEnvironment(new ForkEnvironment());
    taskLauncherInitializer.setSchedulerRestUrl("http://localhost:8080/rest");
    Decrypter decrypter = createCredentials(testUser, testPass);
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null, decrypter);
    // variable should belong to the expected class
    validateThatScriptHandlerBindingsInstanceOf(new ScriptHandler(), taskContext, new VariablesMap(), new HashMap<String, String>(), new HashMap<String, String>(), SchedulerConstants.DS_USER_API_BINDING_NAME, DataSpaceNodeClient.class);
    // variable should belong to the expected class
    validateThatScriptHandlerBindingsInstanceOf(new ScriptHandler(), taskContext, new VariablesMap(), new HashMap<String, String>(), new HashMap<String, String>(), SchedulerConstants.DS_GLOBAL_API_BINDING_NAME, DataSpaceNodeClient.class);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) 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

ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)52 Test (org.junit.Test)51 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)51 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)43 SimpleScript (org.ow2.proactive.scripting.SimpleScript)40 TaskScript (org.ow2.proactive.scripting.TaskScript)40 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)30 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)20 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)17 Serializable (java.io.Serializable)16 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)14 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)13 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)12 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)10 HashMap (java.util.HashMap)9 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 File (java.io.File)7 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)6 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)5