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 05702b322d..e0e7f5e2dd 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 @@ -17,6 +17,7 @@ import io.cloudslang.lang.runtime.services.ScriptsService; import io.cloudslang.runtime.api.python.PythonEvaluationResult; import io.cloudslang.runtime.api.python.PythonRuntimeService; +import io.cloudslang.runtime.api.python.enums.PythonStrategy; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.python.core.Py; @@ -33,6 +34,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static io.cloudslang.runtime.api.python.enums.PythonStrategy.PYTHON_SERVER; +import static io.cloudslang.runtime.api.python.enums.PythonStrategy.getPythonStrategy; + /** * @author stoneo * @version $Id$ @@ -45,10 +49,8 @@ public class ScriptEvaluator extends ScriptProcessor { private static final String ACCESSED_RESOURCES_SET = "accessed_resources_set"; private static final String BACKWARD_COMPATIBLE_ACCESS_METHOD = "def accessed(key):" + LINE_SEPARATOR + " pass"; - private static final boolean EXTERNAL_PYTHON = !Boolean.valueOf( - System.getProperty("use.jython.expressions", "true")); - - + private static final PythonStrategy PYTHON_EVALUATOR = + getPythonStrategy(System.getProperty("python.expressionsEval"), PYTHON_SERVER); public static final int MAX_LENGTH = Integer.getInteger("input.error.max.length", 1000); @Resource(name = "externalPythonRuntimeService") @@ -63,10 +65,15 @@ public class ScriptEvaluator extends ScriptProcessor { public Value evalExpr(String expr, Map context, Set systemProperties, Set functionDependencies) { try { - if (EXTERNAL_PYTHON) { - return doEvaluateExpressionExternalPython(expr, context, systemProperties, functionDependencies); - } else { - return doEvaluateExpressionJython(expr, context, systemProperties, functionDependencies); + switch (PYTHON_EVALUATOR) { + //TODO add method for python server once the server is implemented; also copy for the default method + case PYTHON_SERVER: + case PYTHON: + return doEvaluateExpressionExternalPython(expr, context, systemProperties, functionDependencies); + case JYTHON: + return doEvaluateExpressionJython(expr, context, systemProperties, functionDependencies); + default: + return doEvaluateExpressionExternalPython(expr, context, systemProperties, functionDependencies); } } catch (Exception exception) { throw new RuntimeException("Error in evaluating expression: '" + @@ -120,11 +127,15 @@ private Value doEvaluateExpressionExternalPython(String expr, public Value testExpr(String expr, Map context, Set systemProperties, Set functionDependencies, long timeoutPeriod) { try { - if (EXTERNAL_PYTHON) { - return doTestExternalPython(expr, context, systemProperties, functionDependencies, timeoutPeriod); - - } else { - return doTestJython(expr, context, systemProperties, functionDependencies, timeoutPeriod); + switch (PYTHON_EVALUATOR) { + //TODO add method for python server once the server is implemented; also copy for the default method + case PYTHON_SERVER: + case PYTHON: + return doTestExternalPython(expr, context, systemProperties, functionDependencies, timeoutPeriod); + case JYTHON: + return doTestJython(expr, context, systemProperties, functionDependencies, timeoutPeriod); + default: + return doTestExternalPython(expr, context, systemProperties, functionDependencies, timeoutPeriod); } } catch (Exception exception) { throw new RuntimeException("Error in evaluating expression: '" + diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ArgumentsBindingTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ArgumentsBindingTest.java index ef79eb45d2..02f8349673 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ArgumentsBindingTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ArgumentsBindingTest.java @@ -88,7 +88,7 @@ public class ArgumentsBindingTest { PythonExecutionNotCachedEngine.class.getSimpleName()); assertNull("python.executor.engine was configured before this test!!!!!!!", provideralAlreadyConfigured); - System.setProperty("use.jython.expressions", "true"); + System.setProperty("python.expressionsEval", "jython"); } @SuppressWarnings("unchecked") diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/InputsBindingTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/InputsBindingTest.java index a8a5978ec8..d28862b851 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/InputsBindingTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/InputsBindingTest.java @@ -56,7 +56,7 @@ @ContextConfiguration(classes = InputsBindingTest.Config.class) public class InputsBindingTest { static { - System.setProperty("use.jython.expressions", "true"); + System.setProperty("python.expressionsEval", "jython"); } @Autowired diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/LoopsBindingTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/LoopsBindingTest.java index e4ded8607f..626c8a0a33 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/LoopsBindingTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/LoopsBindingTest.java @@ -48,7 +48,7 @@ @RunWith(MockitoJUnitRunner.class) public class LoopsBindingTest { static { - System.setProperty("use.jython.expressions", "true"); + System.setProperty("python.expressionsEval", "jython"); } @SuppressWarnings("unchecked") diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/OutputsBindingTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/OutputsBindingTest.java index f34d6ad787..fd272c1e0c 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/OutputsBindingTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/OutputsBindingTest.java @@ -58,7 +58,7 @@ @ContextConfiguration(classes = OutputsBindingTest.Config.class) public class OutputsBindingTest { static { - System.setProperty("use.jython.expressions", "true"); + System.setProperty("python.expressionsEval", "jython"); } private static final long DEFAULT_TIMEOUT = 10000; diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ParallelLoopBindingTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ParallelLoopBindingTest.java index cff7b8dec1..646f8629f2 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ParallelLoopBindingTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ParallelLoopBindingTest.java @@ -40,7 +40,7 @@ @RunWith(MockitoJUnitRunner.class) public class ParallelLoopBindingTest { static { - System.setProperty("use.jython.expressions", "true"); + System.setProperty("python.expressionsEval", "jython"); } @SuppressWarnings("unchecked") diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ResultBindingTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ResultBindingTest.java index e000fcb13a..c06e8fda8c 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ResultBindingTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/ResultBindingTest.java @@ -55,7 +55,7 @@ @ContextConfiguration(classes = ResultBindingTest.Config.class) public class ResultBindingTest { static { - System.setProperty("use.jython.expressions", "true"); + System.setProperty("python.expressionsEval", "jython"); } @SuppressWarnings("unchecked") diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluatorTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluatorTest.java index dc74a881ab..65889b923d 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluatorTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluatorTest.java @@ -66,7 +66,7 @@ @ContextConfiguration(classes = ScriptEvaluatorTest.Config.class) public class ScriptEvaluatorTest { static { - System.setProperty("use.jython.expressions", "true"); + System.setProperty("python.expressionsEval", "jython"); } private static String LINE_SEPARATOR = "\n"; diff --git a/cloudslang-tests/src/test/java/io/cloudslang/lang/systemtests/SystemsTestsParent.java b/cloudslang-tests/src/test/java/io/cloudslang/lang/systemtests/SystemsTestsParent.java index 29764f2a97..6f94141ee0 100644 --- a/cloudslang-tests/src/test/java/io/cloudslang/lang/systemtests/SystemsTestsParent.java +++ b/cloudslang-tests/src/test/java/io/cloudslang/lang/systemtests/SystemsTestsParent.java @@ -102,7 +102,7 @@ public abstract class SystemsTestsParent { assertNull("python.executor.engine was configured before this test!!!!!!!", provideralAlreadyConfigured); System.setProperty(CSLANG_RUNTIME_EVENTS_VERBOSITY.getValue(), EventVerbosityLevel.DEFAULT.getValue()); - System.setProperty("use.jython.expressions", "true"); + System.setProperty("python.expressionsEval", "jython"); } @Autowired