use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl 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());
}
use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl 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());
}
use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl in project scheduling by ow2-proactive.
the class TaskLauncherDataSpacesTest method input_file_using_variable_in_its_selector.
@Test
public void input_file_using_variable_in_its_selector() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("println new File('.').listFiles();", "groovy")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
initializer.setJobVariables(singletonMap("aVar", new JobVariable("aVar", "foo")));
initializer.setTaskInputFiles(singletonList(new InputSelector(new FileSelector("input_${aVar}_${aResultVar}.txt"), InputAccessMode.TransferFromInputSpace)));
File inputFile = new File(taskLauncherFactory.getDataSpaces().getInputURI(), "input_foo_bar.txt");
assertTrue(inputFile.createNewFile());
TaskResultImpl previousTaskResult = taskResult(Collections.<String, Serializable>singletonMap("aResultVar", "bar"));
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, taskLauncherFactory), executableContainer, previousTaskResult);
assertTaskResultOk(taskResult);
assertTrue(taskResult.getOutput().getAllLogs(false).contains("input_foo_bar.txt"));
}
use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl in project scheduling by ow2-proactive.
the class TaskLauncherDataSpacesTest method output_file_using_variable_in_its_selector.
@Test
public void output_file_using_variable_in_its_selector() throws Throwable {
ScriptExecutableContainer createAFileAndWriteVariable = new ScriptExecutableContainer(new TaskScript(new SimpleScript("new File('output_foo_bar.txt').text = 'hello'; variables.put('aVar', 'foo')", "groovy")));
TaskLauncherInitializer copyOutputFile = new TaskLauncherInitializer();
copyOutputFile.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
copyOutputFile.setTaskOutputFiles(singletonList(new OutputSelector(new FileSelector("output_${aVar}_${aResultVar}.txt"), OutputAccessMode.TransferToGlobalSpace)));
TaskResultImpl previousTaskResult = taskResult(Collections.<String, Serializable>singletonMap("aResultVar", "bar"));
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(copyOutputFile, taskLauncherFactory), createAFileAndWriteVariable, previousTaskResult);
assertTaskResultOk(taskResult);
assertTrue(new File(taskLauncherFactory.getDataSpaces().getGlobalURI(), "output_foo_bar.txt").exists());
}
use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl 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, null);
new TaskContextVariableExtractor().getAllVariables(taskContext);
}
Aggregations