From ff95be2a118ec5bde1ad88ae2ad8557cd93323a4 Mon Sep 17 00:00:00 2001 From: Pierre Villard Date: Thu, 25 Jan 2018 16:29:10 +0100 Subject: [PATCH] NIFI-4815 - Add EL support to ExecuteProcess Signed-off-by: Matthew Burgess This closes #2432 --- .../apache/nifi/processors/standard/ExecuteProcess.java | 8 ++++---- .../nifi/processors/standard/TestExecuteProcess.java | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java index a7c41fed75..c1ab946e8b 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java @@ -85,7 +85,7 @@ public class ExecuteProcess extends AbstractProcessor { .name("Command") .description("Specifies the command to be executed; if just the name of an executable is provided, it must be in the user's environment PATH.") .required(true) - .expressionLanguageSupported(false) + .expressionLanguageSupported(true) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .build(); @@ -100,7 +100,7 @@ public class ExecuteProcess extends AbstractProcessor { public static final PropertyDescriptor WORKING_DIR = new PropertyDescriptor.Builder() .name("Working Directory") .description("The directory to use as the current working directory when executing the command") - .expressionLanguageSupported(false) + .expressionLanguageSupported(true) .addValidator(StandardValidators.createDirectoryExistsValidator(false, true)) .required(false) .build(); @@ -213,7 +213,7 @@ public class ExecuteProcess extends AbstractProcessor { final Long batchNanos = context.getProperty(BATCH_DURATION).asTimePeriod(TimeUnit.NANOSECONDS); - final String command = context.getProperty(COMMAND).getValue(); + final String command = context.getProperty(COMMAND).evaluateAttributeExpressions().getValue(); final String arguments = context.getProperty(COMMAND_ARGUMENTS).isSet() ? context.getProperty(COMMAND_ARGUMENTS).evaluateAttributeExpressions().getValue() : null; @@ -311,7 +311,7 @@ public class ExecuteProcess extends AbstractProcessor { final Boolean redirectErrorStream = context.getProperty(REDIRECT_ERROR_STREAM).asBoolean(); final ProcessBuilder builder = new ProcessBuilder(commandStrings); - final String workingDirName = context.getProperty(WORKING_DIR).getValue(); + final String workingDirName = context.getProperty(WORKING_DIR).evaluateAttributeExpressions().getValue(); if (workingDirName != null) { builder.directory(new File(workingDirName)); } diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java index 0d2ed48b15..a5a08f0898 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java @@ -105,7 +105,8 @@ public class TestExecuteProcess { @Test public void validateProcessInterruptOnStop() throws Exception { final TestRunner runner = TestRunners.newTestRunner(ExecuteProcess.class); - runner.setProperty(ExecuteProcess.COMMAND, "ping"); + runner.setVariable("command", "ping"); + runner.setProperty(ExecuteProcess.COMMAND, "${command}"); runner.setProperty(ExecuteProcess.COMMAND_ARGUMENTS, "nifi.apache.org"); runner.setProperty(ExecuteProcess.BATCH_DURATION, "500 millis"); @@ -127,6 +128,10 @@ public class TestExecuteProcess { fail(); } + final List flowFiles = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS); + if(!flowFiles.isEmpty()) { + assertTrue(flowFiles.get(0).getAttribute("command").equals("ping")); + } } // @Test