Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapper prop #1387

Merged
merged 5 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<!--Project dependencies-->
<spring.version>5.3.23</spring.version>
<hamcrest.version>1.3</hamcrest.version>
<score.version>0.3.282</score.version>
<score.version>0.3.283</score.version>
<h2.version>2.1.210</h2.version>
<!--Project properties-->
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down