NIFI-4815 - Add EL support to ExecuteProcess

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

This closes #2432
This commit is contained in:
Pierre Villard 2018-01-25 16:29:10 +01:00 committed by Matthew Burgess
parent bc37015693
commit ff95be2a11
2 changed files with 10 additions and 5 deletions

View File

@ -85,7 +85,7 @@ public class ExecuteProcess extends AbstractProcessor {
.name("Command") .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.") .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) .required(true)
.expressionLanguageSupported(false) .expressionLanguageSupported(true)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build(); .build();
@ -100,7 +100,7 @@ public class ExecuteProcess extends AbstractProcessor {
public static final PropertyDescriptor WORKING_DIR = new PropertyDescriptor.Builder() public static final PropertyDescriptor WORKING_DIR = new PropertyDescriptor.Builder()
.name("Working Directory") .name("Working Directory")
.description("The directory to use as the current working directory when executing the command") .description("The directory to use as the current working directory when executing the command")
.expressionLanguageSupported(false) .expressionLanguageSupported(true)
.addValidator(StandardValidators.createDirectoryExistsValidator(false, true)) .addValidator(StandardValidators.createDirectoryExistsValidator(false, true))
.required(false) .required(false)
.build(); .build();
@ -213,7 +213,7 @@ public class ExecuteProcess extends AbstractProcessor {
final Long batchNanos = context.getProperty(BATCH_DURATION).asTimePeriod(TimeUnit.NANOSECONDS); 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() final String arguments = context.getProperty(COMMAND_ARGUMENTS).isSet()
? context.getProperty(COMMAND_ARGUMENTS).evaluateAttributeExpressions().getValue() ? context.getProperty(COMMAND_ARGUMENTS).evaluateAttributeExpressions().getValue()
: null; : null;
@ -311,7 +311,7 @@ public class ExecuteProcess extends AbstractProcessor {
final Boolean redirectErrorStream = context.getProperty(REDIRECT_ERROR_STREAM).asBoolean(); final Boolean redirectErrorStream = context.getProperty(REDIRECT_ERROR_STREAM).asBoolean();
final ProcessBuilder builder = new ProcessBuilder(commandStrings); 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) { if (workingDirName != null) {
builder.directory(new File(workingDirName)); builder.directory(new File(workingDirName));
} }

View File

@ -105,7 +105,8 @@ public class TestExecuteProcess {
@Test @Test
public void validateProcessInterruptOnStop() throws Exception { public void validateProcessInterruptOnStop() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(ExecuteProcess.class); 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.COMMAND_ARGUMENTS, "nifi.apache.org");
runner.setProperty(ExecuteProcess.BATCH_DURATION, "500 millis"); runner.setProperty(ExecuteProcess.BATCH_DURATION, "500 millis");
@ -127,6 +128,10 @@ public class TestExecuteProcess {
fail(); fail();
} }
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS);
if(!flowFiles.isEmpty()) {
assertTrue(flowFiles.get(0).getAttribute("command").equals("ping"));
}
} }
// @Test // @Test