Search in sources :

Example 1 with TaskContextVariableExtractor

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

the class TaskContextVariableExtractorTest method testExtractThrowsExceptionIfVariablesAreInvalidByteStream.

@Test(expected = Exception.class)
public void testExtractThrowsExceptionIfVariablesAreInvalidByteStream() throws Exception {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
    Map<String, byte[]> taskResultVariables = new HashMap<>();
    // The task result variables are expected to be converted to byte streams.
    taskResultVariables.put(taskResultPropagatedVariables1Key, taskResultPropagatedVariables1Value.getBytes());
    TaskResultImpl taskResult = new TaskResultImpl(taskLauncherInitializer.getTaskId(), new Exception("Exception"));
    taskResult.setPropagatedVariables(taskResultVariables);
    TaskResult[] taskResultArray = { taskResult };
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, taskResultArray, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null));
    new TaskContextVariableExtractor().getAllVariables(taskContext);
}
Also used : 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) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 2 with TaskContextVariableExtractor

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

the class TaskContextVariableExtractorTest method testExtractTaskResultVariablesGetAllNonTaskVariables.

@Test
public void testExtractTaskResultVariablesGetAllNonTaskVariables() 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, new NodeInfo(null, null, null, null));
    Map<String, Serializable> scopeVariables = new TaskContextVariableExtractor().getAllNonTaskVariables(taskContext);
    Assert.assertThat(scopeVariables.toString(), CoreMatchers.containsString("PA_TASK_NAME=TestTaskName"));
}
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 3 with TaskContextVariableExtractor

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

the class ForkedProcessBuilderCreatorTest method setMocks.

private void setMocks(ForkedProcessBuilderCreator forkedProcessBuilderCreator) throws Exception {
    ForkedJvmTaskExecutionCommandCreator forkedJvmTaskExecutionCommandCreator = mock(ForkedJvmTaskExecutionCommandCreator.class);
    TaskContextVariableExtractor taskContextVariableExtractor = mock(TaskContextVariableExtractor.class);
    ForkEnvironmentScriptExecutor forkEnvironmentScriptExecutor = mock(ForkEnvironmentScriptExecutor.class);
    given(forkedJvmTaskExecutionCommandCreator.createForkedJvmTaskExecutionCommand(any(TaskContext.class), any(ScriptResult.class), any(String.class))).willReturn(Arrays.asList(forkEnJavaCommandString));
    given(taskContextVariableExtractor.extractVariablesThirdPartyCredentialsAndSystemEnvironmentVariables(any(TaskContext.class))).willReturn(taskContextExtractedVariables);
    given(forkEnvironmentScriptExecutor.executeForkEnvironmentScript(any(TaskContext.class), any(PrintStream.class), any(PrintStream.class))).willReturn(new ScriptResult<ForkEnvironmentScriptResult>(new ForkEnvironmentScriptResult()));
    setPrivateField(ForkedProcessBuilderCreator.class.getDeclaredField("forkedJvmTaskExecutionCommandCreator"), forkedProcessBuilderCreator, forkedJvmTaskExecutionCommandCreator);
    setPrivateField(ForkedProcessBuilderCreator.class.getDeclaredField("taskContextVariableExtractor"), forkedProcessBuilderCreator, taskContextVariableExtractor);
    setPrivateField(ForkedProcessBuilderCreator.class.getDeclaredField("forkEnvironmentScriptExecutor"), forkedProcessBuilderCreator, forkEnvironmentScriptExecutor);
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) ForkEnvironmentScriptResult(org.ow2.proactive.scripting.ForkEnvironmentScriptResult) ForkedJvmTaskExecutionCommandCreator(org.ow2.proactive.scheduler.task.executors.forked.env.ForkedJvmTaskExecutionCommandCreator) PrintStream(java.io.PrintStream) TaskContextVariableExtractor(org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) ForkEnvironmentScriptResult(org.ow2.proactive.scripting.ForkEnvironmentScriptResult)

Example 4 with TaskContextVariableExtractor

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

the class ForkedTaskExecutor method createTaskResult.

private TaskResultImpl createTaskResult(TaskContext context, Throwable throwable) {
    TaskResultImpl result = new TaskResultImpl(context.getTaskId(), new ForkedJvmProcessException("Failed to execute task in a forked JVM", throwable));
    result.setPropagatedVariables(new TaskContextVariableExtractor().extractPropagatedVariables(context));
    return result;
}
Also used : ForkedJvmProcessException(org.ow2.proactive.scheduler.task.exceptions.ForkedJvmProcessException) TaskContextVariableExtractor(org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl)

Example 5 with TaskContextVariableExtractor

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

the class TaskContextVariableExtractorTest method testExtractWorkflowVariablesFromTaskLauncherInitializerInsideTaskContext.

@Test
public void testExtractWorkflowVariablesFromTaskLauncherInitializerInsideTaskContext() 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, new NodeInfo(null, null, null, null));
    Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllVariables(taskContext);
    assertThat((String) contextVariables.get(testVariable1Key), is(testVariable1Value));
    assertThat((String) contextVariables.get(testVariable2Key), is(testVariable2Value));
}
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)

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 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)4 HashMap (java.util.HashMap)3 TaskContextVariableExtractor (org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor)3 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)2 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 PAPropertyString (org.objectweb.proactive.core.config.PAPropertyString)1 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)1 ForkedJvmProcessException (org.ow2.proactive.scheduler.task.exceptions.ForkedJvmProcessException)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