Search in sources :

Example 56 with TaskScript

use of org.ow2.proactive.scripting.TaskScript 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 57 with TaskScript

use of org.ow2.proactive.scripting.TaskScript 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 58 with TaskScript

use of org.ow2.proactive.scripting.TaskScript 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 59 with TaskScript

use of org.ow2.proactive.scripting.TaskScript 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 60 with TaskScript

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

the class ForkedProcessBuilderCreatorTest method createTaskContext.

private TaskContext createTaskContext() throws InvalidScriptException, NodeException {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariableAndForkEnvironment();
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
    return taskContext;
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer)

Aggregations

TaskScript (org.ow2.proactive.scripting.TaskScript)78 SimpleScript (org.ow2.proactive.scripting.SimpleScript)76 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)64 Test (org.junit.Test)59 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)31 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)31 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)19 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)19 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)12 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)11 Serializable (java.io.Serializable)10 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)10 File (java.io.File)9 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)9 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)8 HashMap (java.util.HashMap)6 Semaphore (java.util.concurrent.Semaphore)5