Search in sources :

Example 51 with InvalidScriptException

use of org.ow2.proactive.scripting.InvalidScriptException in project scheduling by ow2-proactive.

the class ProbablisticSelectionManager method replaceBindings.

private SelectionScript replaceBindings(SelectionScript script, Map<String, Serializable> bindings) {
    String scriptContent = script.fetchScript();
    if (scriptContent != null && bindings != null) {
        for (Map.Entry<String, Serializable> entry : bindings.entrySet()) {
            String reservedKeyword = entry.getKey();
            Serializable binding = entry.getValue();
            if (binding instanceof Map) {
                scriptContent = replaceBindingKeysByTheirValue(scriptContent, (Map<String, Serializable>) binding);
            } else {
                if (binding != null) {
                    scriptContent = scriptContent.replace(reservedKeyword, binding.toString());
                }
            }
        }
    }
    try {
        if (scriptContent != null) {
            return new SelectionScript(scriptContent, script.getEngineName(), script.getParameters(), script.isDynamic());
        } else {
            return script;
        }
    } catch (InvalidScriptException e) {
        logger.warn("Error when replacing bindings of script (revert to use original script):" + System.lineSeparator() + script.toString(), e);
        return script;
    }
}
Also used : Serializable(java.io.Serializable) SelectionScript(org.ow2.proactive.scripting.SelectionScript) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Test (org.junit.Test)28 SimpleScript (org.ow2.proactive.scripting.SimpleScript)25 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)16 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)16 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)14 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)14 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)13 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)12 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)12 NodeInfo (org.ow2.proactive.scheduler.task.context.NodeInfo)12 FlowScript (org.ow2.proactive.scheduler.common.task.flow.FlowScript)11 Script (org.ow2.proactive.scripting.Script)11 TaskScript (org.ow2.proactive.scripting.TaskScript)11 HashMap (java.util.HashMap)7 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)6 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)6 Serializable (java.io.Serializable)5 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)5 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)5 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)5