Search in sources :

Example 6 with TaskContextVariableExtractor

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

the class TaskContextVariableExtractorTest method testExtractTaskLauncherInitializerVariablesFromTaskContext.

@Test
public void testExtractTaskLauncherInitializerVariablesFromTaskContext() throws Exception {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskContext taskContext = new TaskContext(scriptContainer, createTaskLauncherInitializer(), null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
    Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllVariables(taskContext);
    validateExtractedVariablesFromTaskLauncherInitializer(contextVariables);
}
Also used : Serializable(java.io.Serializable) TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Test(org.junit.Test)

Example 7 with TaskContextVariableExtractor

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

the class TaskContextVariableExtractorTest method testExtractTaskResultVariablesGetScopeVariables.

@Test
public void testExtractTaskResultVariablesGetScopeVariables() throws Exception {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
    Map<String, Serializable> scopeVariables = new TaskContextVariableExtractor().getScopeVariables(taskContext);
    Assert.assertThat(scopeVariables.toString(), CoreMatchers.containsString("{TestVariable2=valueForTest2}"));
}
Also used : Serializable(java.io.Serializable) TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 8 with TaskContextVariableExtractor

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

the class TaskContextVariableExtractorTest method testExtractTaskResultVariablesFromTaskResult.

@Test
public void testExtractTaskResultVariablesFromTaskResult() throws Exception {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
    Map<String, byte[]> taskResultVariables = new HashMap<>();
    // The task result variables are expected to be converted to byte streams.
    taskResultVariables.put(taskResultPropagatedVariables1Key, AllObjects2BytesConverterHandler.convertObject2Byte(taskResultPropagatedVariables1Key, taskResultPropagatedVariables1Value));
    TaskResultImpl taskResult = new TaskResultImpl(taskContext.getTaskId(), new Exception("Exception"));
    taskResult.setPropagatedVariables(taskResultVariables);
    Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllVariablesWithTaskResult(taskContext, taskResult);
    assertThat((String) contextVariables.get(taskResultPropagatedVariables1Key), is(taskResultPropagatedVariables1Value));
}
Also used : Serializable(java.io.Serializable) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 9 with TaskContextVariableExtractor

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

the class TaskContextVariableExtractorTest method testExtractNodefileVariablesAndProgressVariablesWithGivenNodesfile.

@Test
public void testExtractNodefileVariablesAndProgressVariablesWithGivenNodesfile() throws Exception {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
    Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllNonTaskVariablesInjectNodesFile(taskContext, nodesfileContent);
    assertThat("Nodes number must be equal to number of other nodes + 1 (for the own node).", (int) contextVariables.get(SchedulerVars.PA_NODESNUMBER.toString()), is(taskContext.getOtherNodesURLs().size() + 1));
    assertThat("Node file content of passed node file must be represented as a variable.", (String) contextVariables.get(SchedulerVars.PA_NODESFILE.toString()), is(nodesfileContent));
    assertThat("Task progress path must be represented as a variable.", (String) contextVariables.get(SchedulerVars.PA_TASK_PROGRESS_FILE.toString()), is(taskContext.getProgressFilePath()));
}
Also used : Serializable(java.io.Serializable) TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 10 with TaskContextVariableExtractor

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

the class ForkedProcessBuilderCreatorTest method testTaskContextVariableExtractorThrowsExceptionAndIsRethrown.

@Test(expected = IllegalStateException.class)
public void testTaskContextVariableExtractorThrowsExceptionAndIsRethrown() throws Exception {
    ForkedProcessBuilderCreator forkedProcessBuilderCreator = new ForkedProcessBuilderCreator();
    TaskContextVariableExtractor taskContextVariableExtractor = mock(TaskContextVariableExtractor.class);
    given(taskContextVariableExtractor.extractVariablesThirdPartyCredentialsAndSystemEnvironmentVariables(any(TaskContext.class))).willThrow(IllegalArgumentException.class);
    setPrivateField(ForkedProcessBuilderCreator.class.getDeclaredField("taskContextVariableExtractor"), forkedProcessBuilderCreator, taskContextVariableExtractor);
    TaskContext taskContext = createTaskContext();
    forkedProcessBuilderCreator.createForkedProcessBuilder(taskContext, tmpFolder.newFolder(), System.out, System.out, tmpFolder.newFolder());
}
Also used : TaskContextVariableExtractor(org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 Serializable (java.io.Serializable)8 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)8 SimpleScript (org.ow2.proactive.scripting.SimpleScript)8 TaskScript (org.ow2.proactive.scripting.TaskScript)8 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)7 HashMap (java.util.HashMap)3 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)3 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)2 TaskContextVariableExtractor (org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor)2 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)1 ForkedJvmTaskExecutionCommandCreator (org.ow2.proactive.scheduler.task.executors.forked.env.ForkedJvmTaskExecutionCommandCreator)1 ForkEnvironmentScriptResult (org.ow2.proactive.scripting.ForkEnvironmentScriptResult)1 ScriptResult (org.ow2.proactive.scripting.ScriptResult)1