diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java index cedf108700..c68e374f6c 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java @@ -18,8 +18,11 @@ import io.cloudslang.runtime.api.python.PythonEvaluationResult; import io.cloudslang.runtime.api.python.PythonRuntimeService; import io.cloudslang.runtime.api.python.enums.PythonStrategy; +import io.cloudslang.runtime.impl.python.external.ExternalPythonScriptException; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.python.core.Py; import org.python.core.PyObject; import org.springframework.beans.factory.annotation.Autowired; @@ -44,6 +47,8 @@ */ @Component public class ScriptEvaluator extends ScriptProcessor { + + private static final Logger logger = LogManager.getLogger(ScriptEvaluator.class); private static String LINE_SEPARATOR = "\n"; private static final String SYSTEM_PROPERTIES_MAP = "sys_prop"; private static final String ACCESSED_RESOURCES_SET = "accessed_resources_set"; @@ -128,9 +133,9 @@ private Value doEvaluateExpressionExternalPython(String expr, } private Value doEvaluateExpressionPythonExecutor(String expr, - Map context, - Set systemProperties, - Set functionDependencies) { + Map context, + Set systemProperties, + Set functionDependencies) { Map pythonContext = createExternalPythonContext(context); boolean systemPropertiesDefined = false; if (functionDependencies.contains(ScriptFunction.GET_SYSTEM_PROPERTY) || @@ -142,8 +147,15 @@ private Value doEvaluateExpressionPythonExecutor(String expr, (Serializable) prepareSystemPropertiesForExternalPython(systemProperties)); } - PythonEvaluationResult result = pythonExecutorService.eval( - buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); + PythonEvaluationResult result; + try { + result = pythonExecutorService.eval( + buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); + } catch (ExternalPythonScriptException exception) { + logger.error("Could not evaluate expressions on python executor, retrying with python"); + result = pythonRuntimeService.eval( + buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); + } //noinspection unchecked Set accessedResources = (Set) result.getResultContext().get(ACCESSED_RESOURCES_SET);