Search in sources :

Example 16 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult 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 17 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult 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 18 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult 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"));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) File(java.io.File) Test(org.junit.Test)

Example 19 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult 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());
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector) SimpleScript(org.ow2.proactive.scripting.SimpleScript) FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 20 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class TaskLauncherDataSpacesTest method input_file_using_job_id_in_its_selector.

@Test
public void input_file_using_job_id_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.setTaskInputFiles(singletonList(new InputSelector(new FileSelector("input_$PA_JOB_ID.txt"), InputAccessMode.TransferFromInputSpace)));
    File inputFile = new File(taskLauncherFactory.getDataSpaces().getInputURI(), "input_1000.txt");
    assertTrue(inputFile.createNewFile());
    TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, taskLauncherFactory), executableContainer);
    assertFalse(taskResult.hadException());
    assertTrue(taskResult.getOutput().getAllLogs(false).contains("input_1000.txt"));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector) File(java.io.File) Test(org.junit.Test)

Aggregations

TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)99 Test (org.junit.Test)54 JobId (org.ow2.proactive.scheduler.common.job.JobId)38 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)28 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)25 SimpleScript (org.ow2.proactive.scripting.SimpleScript)25 File (java.io.File)24 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)23 TaskScript (org.ow2.proactive.scripting.TaskScript)23 HashMap (java.util.HashMap)22 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)22 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)18 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)17 GET (javax.ws.rs.GET)16 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 GZIP (org.jboss.resteasy.annotations.GZIP)16 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)14 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)12 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)12