Search in sources :

Example 6 with TaskContext

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

the class InProcessTaskExecutorTest method variablesPropagation_fromParentTask.

@Test
public void variablesPropagation_fromParentTask() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
    Map<String, Serializable> variablesFromParent = new HashMap<>();
    variablesFromParent.put("var", "parent");
    variablesFromParent.put(SchedulerVars.PA_TASK_ID.toString(), "1234");
    TaskResult[] previousTasksResults = { new TaskResultImpl(null, null, null, null, null, SerializationUtil.serializeVariableMap(variablesFromParent), false) };
    new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('var'));print(variables.get('PA_TASK_ID'))", "groovy"))), initializer, previousTasksResults, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals("parent42", taskOutput.output());
}
Also used : Serializable(java.io.Serializable) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 7 with TaskContext

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

the class InProcessTaskExecutorTest method nodesFileIsCreated.

@Test
public void nodesFileIsCreated() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    ScriptExecutableContainer printNodesFileTask = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print new File(variables.get('PA_NODESFILE')).text", "groovy")));
    printNodesFileTask.setNodes(mockedNodeSet());
    TaskContext context = new TaskContext(printNodesFileTask, initializer, null, new NodeDataSpacesURIs(tmpFolder.newFolder().getAbsolutePath(), "", "", "", "", ""), "", "thisHost");
    TaskResultImpl taskResult = new InProcessTaskExecutor().execute(context, taskOutput.outputStream, taskOutput.error);
    assertTaskResultOk(taskResult);
    assertEquals(String.format("thisHost%ndummyhost%n"), taskOutput.output());
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) 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 8 with TaskContext

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

the class InProcessTaskExecutorTest method variablesPropagation.

@Test
public void variablesPropagation() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setPreScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'pre')", "groovy"));
    initializer.setPostScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'post')", "groovy"));
    initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
    initializer.setJobVariables(Collections.singletonMap("var", new JobVariable("var", "value")));
    TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'task')", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals("valuepretask", taskOutput.output());
    assertEquals("post", SerializationUtil.deserializeVariableMap(result.getPropagatedVariables()).get("var"));
}
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) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 9 with TaskContext

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

the class InProcessTaskExecutorTest method failingPrescript.

@Test
public void failingPrescript() throws Exception {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setPreScript(new SimpleScript("return 10/0", "groovy"));
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals("", taskOutput.output());
    assertNotEquals("", taskOutput.error());
    assertNotNull(result.getException());
}
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 10 with TaskContext

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

the class InProcessTaskExecutorTest method resultMetadata.

@Test
public void resultMetadata() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    Map<String, String> metadata = ImmutableMap.of("pre", "pre", "post", "post", "task", "task");
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setPreScript(new SimpleScript(SchedulerConstants.RESULT_METADATA_VARIABLE + ".put('pre','pre')", "groovy"));
    initializer.setPostScript(new SimpleScript(SchedulerConstants.RESULT_METADATA_VARIABLE + ".put('post','post')", "groovy"));
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(SchedulerConstants.RESULT_METADATA_VARIABLE + ".put('task','task')", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(metadata, result.getMetadata());
}
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)

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