Search in sources :

Example 46 with TaskResultImpl

use of org.ow2.proactive.scheduler.task.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());
}
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 47 with TaskResultImpl

use of org.ow2.proactive.scheduler.task.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);
}
Also used : 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 48 with TaskResultImpl

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

the class InProcessTaskExecutor method execute.

/**
 * Executes a task inside a task context.
 *
 * @param taskContext Task context to execute.
 * @param output      Standard output sink.
 * @param error       Error sink.
 * @return Returns the task result.
 */
@Override
public TaskResultImpl execute(TaskContext taskContext, PrintStream output, PrintStream error) {
    ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
    String nodesFile = null;
    SchedulerNodeClient schedulerNodeClient = null;
    RemoteSpace userSpaceClient = null;
    RemoteSpace globalSpaceClient = null;
    try {
        nodesFile = writeNodesFile(taskContext);
        VariablesMap variables = new VariablesMap();
        variables.setInheritedMap(taskContextVariableExtractor.getAllNonTaskVariablesInjectNodesFile(taskContext, nodesFile));
        variables.setScopeMap(taskContextVariableExtractor.getScopeVariables(taskContext));
        Map<String, String> resultMetadata = new HashMap<>();
        Map<String, String> thirdPartyCredentials = forkedTaskVariablesManager.extractThirdPartyCredentials(taskContext);
        schedulerNodeClient = forkedTaskVariablesManager.createSchedulerNodeClient(taskContext);
        userSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.USER);
        globalSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.GLOBAL);
        forkedTaskVariablesManager.addBindingsToScriptHandler(scriptHandler, taskContext, variables, thirdPartyCredentials, schedulerNodeClient, userSpaceClient, globalSpaceClient, resultMetadata);
        Stopwatch stopwatch = Stopwatch.createUnstarted();
        TaskResultImpl taskResult;
        try {
            stopwatch.start();
            Serializable result = execute(taskContext, output, error, scriptHandler, thirdPartyCredentials, variables);
            stopwatch.stop();
            taskResult = new TaskResultImpl(taskContext.getTaskId(), result, null, stopwatch.elapsed(TimeUnit.MILLISECONDS));
        } catch (Throwable e) {
            stopwatch.stop();
            e.printStackTrace(error);
            taskResult = new TaskResultImpl(taskContext.getTaskId(), e, null, stopwatch.elapsed(TimeUnit.MILLISECONDS));
        }
        executeFlowScript(taskContext.getControlFlowScript(), scriptHandler, output, error, taskResult);
        taskResult.setPropagatedVariables(SerializationUtil.serializeVariableMap(variables.getPropagatedVariables()));
        taskResult.setMetadata(resultMetadata);
        return taskResult;
    } catch (Throwable e) {
        e.printStackTrace(error);
        return new TaskResultImpl(taskContext.getTaskId(), e);
    } finally {
        if (nodesFile != null && !nodesFile.isEmpty()) {
            FileUtils.deleteQuietly(new File(nodesFile));
        }
    }
}
Also used : RemoteSpace(org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace) Serializable(java.io.Serializable) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) SchedulerNodeClient(org.ow2.proactive.scheduler.task.client.SchedulerNodeClient) HashMap(java.util.HashMap) Stopwatch(com.google.common.base.Stopwatch) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) File(java.io.File) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 49 with TaskResultImpl

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

the class ForkedTaskExecutorRunAsMeTest method runAsMe_PasswordMethod.

@Test
public void runAsMe_PasswordMethod() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    Decrypter decrypter = createCredentials(USERNAME, PASSWORD);
    ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
    ScriptExecutableContainer container = new ScriptExecutableContainer(new TaskScript(new SimpleScript("whoami", "native")));
    container.setRunAsUser(true);
    TaskContext taskContext = new TaskContext(container, initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", "", decrypter);
    TaskResultImpl result = taskExecutor.execute(taskContext, taskOutput.outputStream, taskOutput.error);
    assertTaskResultOk(result);
    assertEquals("admin\n", taskOutput.output());
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TestTaskOutput(org.ow2.proactive.scheduler.task.TestTaskOutput) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 50 with TaskResultImpl

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

the class ForkedTaskExecutorTest method nonDaemonThreadsForkedJVMExit.

/**
 * This test ensures that the forked JVM exited properly when non-daemon threads are created inside the task
 *
 * @throws Exception
 */
@Test(timeout = 30000)
public void nonDaemonThreadsForkedJVMExit() throws Exception {
    String taskScript = CharStreams.toString(new InputStreamReader(getClass().getResourceAsStream("/task-nondaemon-thread.groovy"), Charsets.UTF_8));
    TestTaskOutput taskOutput = new TestTaskOutput();
    File workingDir = tmpFolder.newFolder();
    ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(workingDir);
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
    TaskResultImpl result = taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(taskScript, "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    Assert.assertFalse(result.hadException());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InputStreamReader(java.io.InputStreamReader) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TestTaskOutput(org.ow2.proactive.scheduler.task.TestTaskOutput) File(java.io.File) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Aggregations

TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)73 Test (org.junit.Test)70 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)32 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)30 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)26 SimpleScript (org.ow2.proactive.scripting.SimpleScript)26 TaskScript (org.ow2.proactive.scripting.TaskScript)26 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)25 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)25 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)22 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)21 JobId (org.ow2.proactive.scheduler.common.job.JobId)16 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)16 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)15 HashMap (java.util.HashMap)13 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)13 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)12 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)11 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)10