Search in sources :

Example 41 with TaskContext

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

the class ForkedTaskVariablesManagerTest method createTaskContext.

private TaskContext createTaskContext(TaskResult[] previousTasksResults) throws InvalidScriptException, NodeException {
    ScriptExecutableContainer scriptContainer = createScriptContainer();
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setForkEnvironment(new ForkEnvironment());
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, previousTasksResults, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
    return taskContext;
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer)

Example 42 with TaskContext

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

the class InProcessTaskExecutorTest method testPaUserVariableAvailabilityFromScriptEngine.

@Test
public void testPaUserVariableAvailabilityFromScriptEngine() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    String jobOwner = "JohnDoe";
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setJobOwner(jobOwner);
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print variables.get('PA_USER')", "python"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(jobOwner, taskOutput.output().trim());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 43 with TaskContext

use of org.ow2.proactive.scheduler.task.context.TaskContext 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, 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)

Example 44 with TaskContext

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

the class TaskContextVariableExtractorTest method testExtractTaskResultVariablesFromPreviousTaskResultsInsideTheTaskContext.

@Test
public void testExtractTaskResultVariablesFromPreviousTaskResultsInsideTheTaskContext() 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, AllObjects2BytesConverterHandler.convertObject2Byte(taskResultPropagatedVariables1Key, taskResultPropagatedVariables1Value));
    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, null);
    Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllVariables(taskContext);
    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) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 45 with TaskContext

use of org.ow2.proactive.scheduler.task.context.TaskContext 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)

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