From f2990020451e01782bd45d1d74c48d328a2cb1f2 Mon Sep 17 00:00:00 2001 From: GIlca Date: Wed, 15 Feb 2023 14:55:17 +0200 Subject: [PATCH 1/2] Check if python executor is alive before attempting to run --- .../bindings/scripts/ScriptEvaluator.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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 929c77057..0d765723a 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 @@ -16,6 +16,7 @@ import io.cloudslang.lang.entities.bindings.values.ValueFactory; import io.cloudslang.lang.runtime.services.ScriptsService; import io.cloudslang.runtime.api.python.PythonEvaluationResult; +import io.cloudslang.runtime.api.python.PythonExecutorLifecycleManagerService; import io.cloudslang.runtime.api.python.PythonRuntimeService; import io.cloudslang.runtime.api.python.enums.PythonStrategy; import io.cloudslang.runtime.impl.python.external.ExternalPythonScriptException; @@ -70,6 +71,9 @@ public class ScriptEvaluator extends ScriptProcessor { @Autowired private ScriptsService scriptsService; + @Autowired + PythonExecutorLifecycleManagerService pythonExecutorLifecycleManagerService; + public Value evalExpr(String expr, Map context, Set systemProperties, Set functionDependencies) { try { @@ -148,13 +152,18 @@ private Value doEvaluateExpressionPythonExecutor(String expr, } PythonEvaluationResult result; - try { - result = pythonExecutorService.eval( - buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); - } catch (ExternalPythonScriptException exception) { - if (logger.isDebugEnabled()) { - logger.warn("Could not evaluate expressions on python executor, retrying with python"); + if (pythonExecutorLifecycleManagerService.isAlive()) { + try { + result = pythonExecutorService.eval( + buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); + } catch (ExternalPythonScriptException exception) { + if (logger.isDebugEnabled()) { + logger.warn("Could not evaluate expressions on python executor, retrying with python"); + } + result = pythonRuntimeService.eval( + buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); } + } else { result = pythonRuntimeService.eval( buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); } From 99d8a27691ec53c5be4dc3716856b5ed33c43abb Mon Sep 17 00:00:00 2001 From: GIlca Date: Wed, 15 Feb 2023 15:21:40 +0200 Subject: [PATCH 2/2] make field private --- .../lang/runtime/bindings/scripts/ScriptEvaluator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0d765723a..5f1e7e903 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 @@ -72,7 +72,7 @@ public class ScriptEvaluator extends ScriptProcessor { private ScriptsService scriptsService; @Autowired - PythonExecutorLifecycleManagerService pythonExecutorLifecycleManagerService; + private PythonExecutorLifecycleManagerService pythonExecutorLifecycleManagerService; public Value evalExpr(String expr, Map context, Set systemProperties, Set functionDependencies) {