Search in sources :

Example 66 with TaskContext

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

the class InProcessTaskExecutorTest method multiNodesURLsAreBounded.

@Test
public void multiNodesURLsAreBounded() 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("println nodesurl.size()", "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("1%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 67 with TaskContext

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

the class InProcessTaskExecutorTest method failingFlowScript.

@Test
public void failingFlowScript() throws Exception {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setControlFlowScript(FlowScript.createReplicateFlowScript(""));
    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("hello", 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 68 with TaskContext

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

the class TaskContextVariableExtractor method getScopeVariables.

/**
 * Return all variables in scope of a given taskContext.
 *
 * @param taskContext task context container.
 * @return Map containing all variables resolved.
 */
public Map<String, Serializable> getScopeVariables(TaskContext taskContext) {
    Map<String, Serializable> variables = new HashMap<>();
    Map<String, Serializable> inherited = new HashMap<>();
    Map<String, Serializable> dictionary = new HashMap<>();
    try {
        inherited.putAll(extractSystemVariables(taskContext, ""));
        inherited.putAll(extractJobVariables(taskContext));
        inherited.putAll(extractInheritedVariables(taskContext));
        for (TaskVariable taskVariable : taskContext.getInitializer().getTaskVariables().values()) {
            if (!taskVariable.isJobInherited()) {
                // add non inherited variables
                variables.put(taskVariable.getName(), taskVariable.getValue());
            } else if (!inherited.containsKey(taskVariable.getName())) {
                // but if the variable is inherited
                // replace by the inherited value if exists
                variables.put(taskVariable.getName(), taskVariable.getValue());
            }
        }
        dictionary = extractAllVariables(taskContext, null, "");
    } catch (IOException | ClassNotFoundException e) {
        logger.error(ERROR_READING_VARIABLES, e);
    }
    return VariableSubstitutor.resolveVariables(variables, dictionary);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) IOException(java.io.IOException)

Example 69 with TaskContext

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

the class ForkEnvironmentScriptExecutor method executeForkEnvironmentScript.

/**
 * Executes a fork environment script.
 *
 * @param context    The task context to execute the script in.
 * @param outputSink Standard output sink.
 * @param errorSink  Error output sink.
 * @return Returns a ScriptResult.
 * @throws Exception
 */
public ScriptResult executeForkEnvironmentScript(TaskContext context, PrintStream outputSink, PrintStream errorSink) throws Exception {
    VariablesMap variables = new VariablesMap();
    variables.setInheritedMap(taskContextVariableExtractor.getAllNonTaskVariables(context));
    variables.setScopeMap(taskContextVariableExtractor.getScopeVariables(context));
    Map<String, String> thirdPartyCredentials = forkedTaskVariablesManager.extractThirdPartyCredentials(context);
    ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
    Script<?> script = context.getInitializer().getForkEnvironment().getEnvScript();
    SchedulerNodeClient schedulerNodeClient = forkedTaskVariablesManager.createSchedulerNodeClient(context);
    RemoteSpace userSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(context, schedulerNodeClient, IDataSpaceClient.Dataspace.USER);
    RemoteSpace globalSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(context, schedulerNodeClient, IDataSpaceClient.Dataspace.GLOBAL);
    forkedTaskVariablesManager.addBindingsToScriptHandler(scriptHandler, context, variables, thirdPartyCredentials, schedulerNodeClient, userSpaceClient, globalSpaceClient, Collections.<String, String>emptyMap());
    forkedTaskVariablesManager.replaceScriptParameters(script, thirdPartyCredentials, variables, errorSink);
    ScriptResult scriptResult = scriptHandler.handle(script, outputSink, errorSink);
    if (scriptResult.errorOccured()) {
        throw new Exception("Failed to execute fork environment script", scriptResult.getException());
    }
    return scriptResult;
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) RemoteSpace(org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace) SchedulerNodeClient(org.ow2.proactive.scheduler.task.client.SchedulerNodeClient) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 70 with TaskContext

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

the class ForkedProcessBuilderCreator method createForkedProcessBuilder.

/**
 * Creates a process builder for a given task context.
 *
 * @param context           The task context to execute.
 * @param serializedContext The task context saved to disk.
 * @param outputSink        Standard output sink.
 * @param errorSink         Error sink.
 * @param workingDir        The working directory to execute the process in.
 * @return Returns a process builder, ready to execute.
 * @throws Exception
 */
public OSProcessBuilder createForkedProcessBuilder(TaskContext context, File serializedContext, PrintStream outputSink, PrintStream errorSink, File workingDir) throws Exception {
    String nativeScriptPath = context.getSchedulerHome();
    OSProcessBuilder processBuilder = getOsProcessBuilder(context, workingDir, nativeScriptPath);
    ScriptResult forkEnvironmentScriptResult = executeForkEnvironmentScriptAndExtractVariables(context, outputSink, errorSink, processBuilder);
    processBuilder.command().addAll(forkedJvmTaskExecutionCommandCreator.createForkedJvmTaskExecutionCommand(context, forkEnvironmentScriptResult, serializedContext.getAbsolutePath()));
    processBuilder = processBuilder.directory(workingDir);
    return processBuilder;
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) OSProcessBuilder(org.objectweb.proactive.extensions.processbuilder.OSProcessBuilder)

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