Skip to content

Commit

Permalink
Merge branches 'build_enhancement' and 'master' of github.com:CloudSl…
Browse files Browse the repository at this point in the history
…ang/cloud-slang into build_enhancement

Signed-off-by: Levente Bonczidai <levente.bonczidai@hpe.com>

# Conflicts:
#	pom.xml
  • Loading branch information
Levente Bonczidai committed Jan 11, 2018
1 parent af61102 commit 524fcd7
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
import io.cloudslang.lang.entities.bindings.values.ValueFactory;
import io.cloudslang.runtime.api.python.PythonEvaluationResult;
import io.cloudslang.runtime.api.python.PythonRuntimeService;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.python.core.Py;
import org.python.core.PyObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
* @author stoneo
* @version $Id$
Expand All @@ -48,6 +49,8 @@ public class ScriptEvaluator extends ScriptProcessor {
"def check_empty(value_to_check, default_value=None):" + LINE_SEPARATOR +
" return default_value if value_to_check is None else value_to_check";

public static final int MAX_LENGTH = Integer.getInteger("input.error.max.length", 1000);

@Autowired
private PythonRuntimeService pythonRuntimeService;

Expand All @@ -69,11 +72,15 @@ public Value evalExpr(String expr, Map<String, Value> context, Set<SystemPropert
getSensitive(result.getResultContext(), systemPropertiesDefined));
} catch (Exception exception) {
throw new RuntimeException("Error in running script expression: '" +
expr + "',\n\tException is: " +
getTruncatedExpression(expr) + "',\n\tException is: " +
handleExceptionSpecialCases(exception.getMessage()), exception);
}
}

private String getTruncatedExpression(String expr) {
return expr.length() > MAX_LENGTH ? expr.substring(0, MAX_LENGTH) + "..." : expr;
}

private String buildAddFunctionsScript(Set<ScriptFunction> functionDependencies) {
String functions = "";
for (ScriptFunction function : functionDependencies) {
Expand Down

0 comments on commit 524fcd7

Please sign in to comment.