NIFI-3222 - Allow ExecuteScript,InvokeScriptedProcessor and ScriptedReporting to use ExpressionLanguage to define the scripting engine modules path

Signed-off-by: Matt Burgess <mattyb149@apache.org>

This closes #1640
This commit is contained in:
Andre F de Miranda 2017-04-01 02:31:39 +11:00 committed by Matt Burgess
parent 6a64b3cd9c
commit 84f1fb3959
6 changed files with 9 additions and 6 deletions

View File

@ -444,7 +444,7 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor {
scriptingComponentHelper.setScriptEngineName(context.getProperty(scriptingComponentHelper.SCRIPT_ENGINE).getValue()); scriptingComponentHelper.setScriptEngineName(context.getProperty(scriptingComponentHelper.SCRIPT_ENGINE).getValue());
scriptingComponentHelper.setScriptPath(context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue()); scriptingComponentHelper.setScriptPath(context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue());
scriptingComponentHelper.setScriptBody(context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue()); scriptingComponentHelper.setScriptBody(context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue());
String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue(); String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).evaluateAttributeExpressions().getValue();
if (!StringUtils.isEmpty(modulePath)) { if (!StringUtils.isEmpty(modulePath)) {
scriptingComponentHelper.setModules(modulePath.split(",")); scriptingComponentHelper.setModules(modulePath.split(","));
} else { } else {

View File

@ -285,7 +285,7 @@ public class ScriptingComponentHelper {
scriptEngineName = context.getProperty(SCRIPT_ENGINE).getValue(); scriptEngineName = context.getProperty(SCRIPT_ENGINE).getValue();
scriptPath = context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue(); scriptPath = context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue();
scriptBody = context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue(); scriptBody = context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue();
String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue(); String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).evaluateAttributeExpressions().getValue();
if (!StringUtils.isEmpty(modulePath)) { if (!StringUtils.isEmpty(modulePath)) {
modules = modulePath.split(","); modules = modulePath.split(",");
} else { } else {

View File

@ -60,7 +60,7 @@ public class ScriptingComponentUtils {
.name("Module Directory") .name("Module Directory")
.description("Comma-separated list of paths to files and/or directories which contain modules required by the script.") .description("Comma-separated list of paths to files and/or directories which contain modules required by the script.")
.required(false) .required(false)
.expressionLanguageSupported(false) .expressionLanguageSupported(true)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build(); .build();
} }

View File

@ -122,7 +122,7 @@ public class ScriptedReportingTask extends AbstractReportingTask {
scriptingComponentHelper.setScriptEngineName(context.getProperty(scriptingComponentHelper.SCRIPT_ENGINE).getValue()); scriptingComponentHelper.setScriptEngineName(context.getProperty(scriptingComponentHelper.SCRIPT_ENGINE).getValue());
scriptingComponentHelper.setScriptPath(context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue()); scriptingComponentHelper.setScriptPath(context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue());
scriptingComponentHelper.setScriptBody(context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue()); scriptingComponentHelper.setScriptBody(context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue());
String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue(); String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).evaluateAttributeExpressions().getValue();
if (!StringUtils.isEmpty(modulePath)) { if (!StringUtils.isEmpty(modulePath)) {
scriptingComponentHelper.setModules(modulePath.split(",")); scriptingComponentHelper.setModules(modulePath.split(","));
} else { } else {

View File

@ -44,7 +44,8 @@ public class TestExecuteJavascript extends BaseScriptTest {
runner.setValidateExpressionUsage(false); runner.setValidateExpressionUsage(false);
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_onTrigger.js"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_onTrigger.js");
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/javascript"); // Use basic manipulation to validate that EL is working
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/${literal('JAVASCRIPT'):toLower()}");
runner.assertValid(); runner.assertValid();
runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8));

View File

@ -104,7 +104,8 @@ public class TestInvokeJython extends BaseScriptTest {
runner.setValidateExpressionUsage(false); runner.setValidateExpressionUsage(false);
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/jython/test_reader.py"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/jython/test_reader.py");
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/jython"); // Use EL to populate MODULES property
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/${literal('JYTHON'):toLower()}");
runner.assertValid(); runner.assertValid();
runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8));
@ -139,6 +140,7 @@ public class TestInvokeJython extends BaseScriptTest {
final TestRunner two = TestRunners.newTestRunner(new InvokeScriptedProcessor()); final TestRunner two = TestRunners.newTestRunner(new InvokeScriptedProcessor());
two.setValidateExpressionUsage(false); two.setValidateExpressionUsage(false);
two.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); two.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python");
two.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/jython"); two.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/jython");
two.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/jython/test_compress.py"); two.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/jython/test_compress.py");
two.setProperty("mode", "decompress"); two.setProperty("mode", "decompress");