Search in sources :

Example 31 with VariablesMap

use of org.ow2.proactive.scheduler.task.utils.VariablesMap 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 32 with VariablesMap

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

the class RMProxyActiveObject method cleanCallBack.

/**
 * Called when a script has returned (call is made as an active object call)
 * <p>
 * Check the nodes to release and release the one that have to (clean script has returned)
 * Take care when renaming this method, method name is linked to
 * {@link #handleCleaningScript(NodeSet, Script, VariablesMap, Map, TaskId, Credentials)}
 */
@ImmediateService
public synchronized void cleanCallBack(Future<ScriptResult<?>> future, NodeSet nodes) {
    String nodeUrl = nodes.get(0).getNodeInformation().getURL();
    ScriptResult<?> sResult = null;
    TaskId taskId = nodesTaskId.get(nodes);
    try {
        sResult = future.get();
    } catch (Exception e) {
        logger.error("Exception occurred while executing cleaning script on node " + nodeUrl + ":", e);
    }
    printCleaningScriptInformations(nodes, sResult, taskId);
    releaseNodes(nodes);
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) LoginException(javax.security.auth.login.LoginException) ImmediateService(org.objectweb.proactive.annotation.ImmediateService)

Aggregations

VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)22 Test (org.junit.Test)20 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)17 HashMap (java.util.HashMap)13 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)10 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)9 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)9 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)8 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)8 Serializable (java.io.Serializable)7 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)4 SchedulerNodeClient (org.ow2.proactive.scheduler.task.client.SchedulerNodeClient)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)3 RemoteSpace (org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace)3 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 LoginException (javax.security.auth.login.LoginException)2