Skip to content

Commit

Permalink
Merge pull request #1387 from CloudSlang/wrapper_prop
Browse files Browse the repository at this point in the history
Wrapper prop
  • Loading branch information
QueueUpX authored Dec 6, 2022
2 parents 47adf62 + 5bf49a8 commit e291075
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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$
Expand All @@ -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")
Expand All @@ -63,10 +65,15 @@ public class ScriptEvaluator extends ScriptProcessor {
public Value evalExpr(String expr, Map<String, Value> context, Set<SystemProperty> systemProperties,
Set<ScriptFunction> 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: '" +
Expand Down Expand Up @@ -120,11 +127,15 @@ private Value doEvaluateExpressionExternalPython(String expr,
public Value testExpr(String expr, Map<String, Value> context, Set<SystemProperty> systemProperties,
Set<ScriptFunction> 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: '" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
@RunWith(MockitoJUnitRunner.class)
public class LoopsBindingTest {
static {
System.setProperty("use.jython.expressions", "true");
System.setProperty("python.expressionsEval", "jython");
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@RunWith(MockitoJUnitRunner.class)
public class ParallelLoopBindingTest {
static {
System.setProperty("use.jython.expressions", "true");
System.setProperty("python.expressionsEval", "jython");
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e291075

Please sign in to comment.