org.apache.nifi.expression.ExpressionLanguageScope Java Examples

The following examples show how to use org.apache.nifi.expression.ExpressionLanguageScope. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdateAttribute.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    PropertyDescriptor.Builder propertyBuilder = new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .required(false)
            .addValidator(StandardValidators.ATTRIBUTE_KEY_PROPERTY_NAME_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .dynamic(true);

    if (stateful) {
        return propertyBuilder
                .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING, true))
                .build();
    } else {
        return propertyBuilder
                .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
                .build();
    }
}
 
Example #2
Source File: MockPropertyValue.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public PropertyValue evaluateAttributeExpressions(final FlowFile flowFile) throws ProcessException {
    /*
     * The reason for this null check is that somewhere in the test API, it automatically assumes that a null FlowFile
     * should be treated as though it were evaluated with the VARIABLE_REGISTRY scope instead of the flowfile scope. When NiFi
     * is running, it doesn't care when it's evaluating EL against a null flowfile. However, the testing framework currently
     * raises an error which makes it not mimick real world behavior.
     */
    if (flowFile == null && expressionLanguageScope == ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) {
        return evaluateAttributeExpressions(new HashMap<>());
    } else if (flowFile == null && expressionLanguageScope == ExpressionLanguageScope.VARIABLE_REGISTRY) {
        return evaluateAttributeExpressions(); //Added this to get around a similar edge case where the a null flowfile is passed
                                                //and the scope is to the registry
    }

    return evaluateAttributeExpressions(flowFile, null, null);
}
 
Example #3
Source File: TestExecuteStreamCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoggingToStdErrDynamicProperties() throws IOException {
    File exJar = new File("src/test/resources/ExecuteCommand/TestLogStdErr.jar");
    File dummy = new File("src/test/resources/ExecuteCommand/1mb.txt");
    String jarPath = exJar.getAbsolutePath();
    exJar.setExecutable(true);
    final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
    controller.setValidateExpressionUsage(false);
    controller.enqueue(dummy.toPath());
    controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java");
    controller.setProperty(ExecuteStreamCommand.ARGUMENTS_STRATEGY, ExecuteStreamCommand.DYNAMIC_PROPERTY_ARGUMENTS_STRATEGY.getValue());
    PropertyDescriptor dynamicProp1 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.1")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp1, "-jar");
    PropertyDescriptor dynamicProp2 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.2")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp2, jarPath);
    controller.run(1);
    controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1);
    controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1);
    List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
    MockFlowFile flowFile = flowFiles.get(0);
    assertEquals(0, flowFile.getSize());
    assertEquals("fffffffffffffffffffffffffffffff", flowFile.getAttribute("execution.error").substring(0, 31));
}
 
Example #4
Source File: TestExecuteStreamCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testIgnoredStdinPutToAttributeDynamicProperties() throws IOException {
    File exJar = new File("src/test/resources/ExecuteCommand/TestIngestAndUpdate.jar");
    File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt");
    String jarPath = exJar.getAbsolutePath();
    exJar.setExecutable(true);
    final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
    controller.enqueue(dummy.toPath());
    controller.setProperty(ExecuteStreamCommand.WORKING_DIR, "target");
    controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java");
    controller.setProperty(ExecuteStreamCommand.ARGUMENTS_STRATEGY, ExecuteStreamCommand.DYNAMIC_PROPERTY_ARGUMENTS_STRATEGY.getValue());
    PropertyDescriptor dynamicProp1 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.1")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp1, "-jar");
    PropertyDescriptor dynamicProp2 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.2")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp2, jarPath);
    controller.setProperty(ExecuteStreamCommand.IGNORE_STDIN, "true");
    controller.setProperty(ExecuteStreamCommand.PUT_OUTPUT_IN_ATTRIBUTE, "executeStreamCommand.output");
    controller.run(1);
    controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1);
    List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP);
    String result = flowFiles.get(0).getAttribute("executeStreamCommand.output");
    assertTrue("TestIngestAndUpdate.jar should not have received anything to modify",
        Pattern.compile("target:ModifiedResult\r?\n?").matcher(result).find());
}
 
Example #5
Source File: JndiJmsConnectionFactoryProperties.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static PropertyDescriptor getDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new Builder()
            .name(propertyDescriptorName)
            .displayName(propertyDescriptorName)
            .description("JNDI Initial Context Environment configuration for '" + propertyDescriptorName + "'")
            .required(false)
            .dynamic(true)
            .addValidator(Validator.VALID)
            .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
            .build();
}
 
Example #6
Source File: JMSConnectionFactoryProperties.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static PropertyDescriptor getDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Specifies the value for '" + propertyDescriptorName
                    + "' property to be set on the provided Connection Factory implementation.")
            .name(propertyDescriptorName)
            .required(false)
            .dynamic(true)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
            .build();
}
 
Example #7
Source File: UpdateAttributeCreateOwnProperty.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
        .name(propertyDescriptorName)
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .addValidator(Validator.VALID)
        .build();
}
 
Example #8
Source File: PutGCSObject.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .dynamic(true)
            .build();
}
 
Example #9
Source File: ConsumeKafka_1_0.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Specifies the value for '" + propertyDescriptorName + "' Kafka Configuration.")
            .name(propertyDescriptorName)
            .addValidator(new KafkaProcessorUtils.KafkaConfigValidator(ConsumerConfig.class))
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
            .build();
}
 
Example #10
Source File: CouchbaseClusterService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(
        String propertyDescriptorName) {
    if (propertyDescriptorName.startsWith(DYNAMIC_PROP_BUCKET_PASSWORD)) {
        return new PropertyDescriptor
                .Builder().name(propertyDescriptorName)
                .description("Bucket password.")
                .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
                .dynamic(true)
                .sensitive(true)
                .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
                .build();
    }
    return null;
}
 
Example #11
Source File: YandexTranslate.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .dynamic(true)
            .build();
}
 
Example #12
Source File: PublishKafkaRecord_1_0.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
        .description("Specifies the value for '" + propertyDescriptorName + "' Kafka Configuration.")
        .name(propertyDescriptorName)
        .addValidator(new KafkaProcessorUtils.KafkaConfigValidator(ProducerConfig.class))
        .dynamic(true)
        .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
        .build();
}
 
Example #13
Source File: AbstractJMSProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Additional configuration property for the Connection Factory")
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
            .dynamic(true)
            .build();
}
 
Example #14
Source File: TestExecuteStreamCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteJarPutToAttributeDynamicProperties() throws Exception {
    File exJar = new File("src/test/resources/ExecuteCommand/TestSuccess.jar");
    File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt");
    String jarPath = exJar.getAbsolutePath();
    exJar.setExecutable(true);
    final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
    controller.enqueue(dummy.toPath());
    controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java");
    controller.setProperty(ExecuteStreamCommand.ARGUMENTS_STRATEGY, ExecuteStreamCommand.DYNAMIC_PROPERTY_ARGUMENTS_STRATEGY.getValue());
    PropertyDescriptor dynamicProp1 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.1")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp1, "-jar");
    PropertyDescriptor dynamicProp2 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.2")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp2, jarPath);
    controller.setProperty(ExecuteStreamCommand.PUT_OUTPUT_IN_ATTRIBUTE, "executeStreamCommand.output");
    controller.run(1);
    controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1);
    controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 0);

    List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP);
    MockFlowFile outputFlowFile = flowFiles.get(0);
    String result = outputFlowFile.getAttribute("executeStreamCommand.output");
    outputFlowFile.assertContentEquals(dummy);
    assertTrue(Pattern.compile("Test was a success\r?\n").matcher(result).find());
    assertEquals("0", outputFlowFile.getAttribute("execution.status"));
    assertEquals("java", outputFlowFile.getAttribute("execution.command"));
    assertEquals("-jar", outputFlowFile.getAttribute("execution.command.args").substring(0, 4));
    String attribute = outputFlowFile.getAttribute("execution.command.args");
    String expected = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "ExecuteCommand" + File.separator + "TestSuccess.jar";
    assertEquals(expected, attribute.substring(attribute.length() - expected.length()));
}
 
Example #15
Source File: TestExecuteStreamCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testDynamicEnvironmentDynamicProperties() throws Exception {
    File exJar = new File("src/test/resources/ExecuteCommand/TestDynamicEnvironment.jar");
    File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt");
    String jarPath = exJar.getAbsolutePath();
    exJar.setExecutable(true);
    final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
    controller.setProperty("NIFI_TEST_1", "testvalue1");
    controller.setProperty("NIFI_TEST_2", "testvalue2");
    controller.enqueue(dummy.toPath());
    controller.setProperty(ExecuteStreamCommand.WORKING_DIR, "target");
    controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java");
    controller.setProperty(ExecuteStreamCommand.ARGUMENTS_STRATEGY, ExecuteStreamCommand.DYNAMIC_PROPERTY_ARGUMENTS_STRATEGY.getValue());
    PropertyDescriptor dynamicProp1 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.1")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp1, "-jar");
    PropertyDescriptor dynamicProp2 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.2")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp2, jarPath);
    controller.run(1);
    controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1);
    controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1);
    List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
    byte[] byteArray = flowFiles.get(0).toByteArray();
    String result = new String(byteArray);
    Set<String> dynamicEnvironmentVariables = new HashSet<>(Arrays.asList(result.split("\r?\n")));
    assertFalse("Should contain at least two environment variables starting with NIFI", dynamicEnvironmentVariables.size() < 2);
    assertTrue("NIFI_TEST_1 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_1=testvalue1"));
    assertTrue("NIFI_TEST_2 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_2=testvalue2"));
}
 
Example #16
Source File: TestExecuteStreamCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testIgnoredStdinDynamicProperties() throws IOException {
    File exJar = new File("src/test/resources/ExecuteCommand/TestIngestAndUpdate.jar");
    File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt");
    String jarPath = exJar.getAbsolutePath();
    exJar.setExecutable(true);
    final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
    controller.enqueue(dummy.toPath());
    controller.setProperty(ExecuteStreamCommand.WORKING_DIR, "target");
    controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java");
    controller.setProperty(ExecuteStreamCommand.ARGUMENTS_STRATEGY, ExecuteStreamCommand.DYNAMIC_PROPERTY_ARGUMENTS_STRATEGY.getValue());
    PropertyDescriptor dynamicProp1 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.1")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp1, "-jar");
    PropertyDescriptor dynamicProp2 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.2")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp2, jarPath);
    controller.setProperty(ExecuteStreamCommand.IGNORE_STDIN, "true");
    controller.run(1);
    controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1);
    controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1);
    List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
    byte[] byteArray = flowFiles.get(0).toByteArray();
    String result = new String(byteArray);
    assertTrue("TestIngestAndUpdate.jar should not have received anything to modify",
        Pattern.compile("target:ModifiedResult\r?\n$").matcher(result).find());
}
 
Example #17
Source File: AbstractPutHBase.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    if (propertyDescriptorName.startsWith("visibility.")) {
        String[] parts = propertyDescriptorName.split("\\.");
        String displayName;
        String description;

        if (parts.length == 2) {
            displayName = String.format("Column Family %s Default Visibility", parts[1]);
            description = String.format("Default visibility setting for %s", parts[1]);
        } else if (parts.length == 3) {
            displayName = String.format("Column Qualifier %s.%s Default Visibility", parts[1], parts[2]);
            description = String.format("Default visibility setting for %s.%s", parts[1], parts[2]);
        } else {
            return null;
        }

        return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .displayName(displayName)
            .description(description)
            .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .dynamic(true)
            .build();
    }

    return null;
}
 
Example #18
Source File: PutSNS.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .required(false)
            .dynamic(true)
            .build();
}
 
Example #19
Source File: TestExecuteStreamCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteIngestAndUpdateDynamicProperties() throws IOException {
    File exJar = new File("src/test/resources/ExecuteCommand/TestIngestAndUpdate.jar");
    File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt");
    File dummy10MBytes = new File("target/10MB.txt");
    try (FileOutputStream fos = new FileOutputStream(dummy10MBytes)) {
        byte[] bytes = Files.readAllBytes(dummy.toPath());
        assertEquals(1000, bytes.length);
        for (int i = 0; i < 10000; i++) {
            fos.write(bytes, 0, 1000);
        }
    }
    String jarPath = exJar.getAbsolutePath();
    exJar.setExecutable(true);
    final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
    controller.enqueue(dummy10MBytes.toPath());
    controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java");
    controller.setProperty(ExecuteStreamCommand.ARGUMENTS_STRATEGY, ExecuteStreamCommand.DYNAMIC_PROPERTY_ARGUMENTS_STRATEGY.getValue());
    PropertyDescriptor dynamicProp1 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.1")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp1, "-jar");
    PropertyDescriptor dynamicProp2 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.2")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp2, jarPath);
    controller.run(1);
    controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1);
    controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1);
    List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
    byte[] byteArray = flowFiles.get(0).toByteArray();
    String result = new String(byteArray);

    assertTrue(Pattern.compile("nifi-standard-processors:ModifiedResult\r?\n").matcher(result).find());
}
 
Example #20
Source File: TestExecuteStreamCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteJarWithBadPathDynamicProperties() throws Exception {
    File exJar = new File("src/test/resources/ExecuteCommand/noSuchFile.jar");
    File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt");
    String jarPath = exJar.getAbsolutePath();
    exJar.setExecutable(true);
    final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
    controller.enqueue(dummy.toPath());
    controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java");
    controller.setProperty(ExecuteStreamCommand.ARGUMENTS_STRATEGY, ExecuteStreamCommand.DYNAMIC_PROPERTY_ARGUMENTS_STRATEGY.getValue());
    PropertyDescriptor dynamicProp1 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.1")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp1, "-jar");
    PropertyDescriptor dynamicProp2 = new PropertyDescriptor.Builder()
        .dynamic(true)
        .name("command.argument.2")
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
    controller.setProperty(dynamicProp2, jarPath);
    controller.run(1);
    controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1);
    controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 0);
    controller.assertTransferCount(ExecuteStreamCommand.NONZERO_STATUS_RELATIONSHIP, 1);
    List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.NONZERO_STATUS_RELATIONSHIP);
    MockFlowFile flowFile = flowFiles.get(0);
    assertEquals(0, flowFile.getSize());
    assertEquals("Error: Unable to access jarfile", flowFile.getAttribute("execution.error").substring(0, 31));
    assertTrue(flowFile.isPenalized());
}
 
Example #21
Source File: UpdateAttributeWithEL.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
        .name(propertyDescriptorName)
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .addValidator(Validator.VALID)
        .build();
}
 
Example #22
Source File: ConsumeKafka_2_0.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Specifies the value for '" + propertyDescriptorName + "' Kafka Configuration.")
            .name(propertyDescriptorName)
            .addValidator(new KafkaProcessorUtils.KafkaConfigValidator(ConsumerConfig.class))
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
            .build();
}
 
Example #23
Source File: RouteOnAttribute.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .required(false)
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(ResultType.BOOLEAN, false))
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .build();
}
 
Example #24
Source File: ConsumeKafkaRecord_2_0.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new Builder()
            .description("Specifies the value for '" + propertyDescriptorName + "' Kafka Configuration.")
            .name(propertyDescriptorName)
            .addValidator(new KafkaProcessorUtils.KafkaConfigValidator(ConsumerConfig.class))
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
            .build();
}
 
Example #25
Source File: PutDatabaseRecord.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .required(false)
            .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING, true))
            .addValidator(StandardValidators.ATTRIBUTE_KEY_PROPERTY_NAME_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .dynamic(true)
            .build();
}
 
Example #26
Source File: EvaluateXPath.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .expressionLanguageSupported(ExpressionLanguageScope.NONE)
            .addValidator(new XPathValidator())
            .required(false)
            .dynamic(true)
            .build();
}
 
Example #27
Source File: RouteOnContent.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    if (propertyDescriptorName.equals(REL_NO_MATCH.getName())) {
        return null;
    }

    return new PropertyDescriptor.Builder()
            .required(false)
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.createRegexValidator(0, Integer.MAX_VALUE, true))
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .build();
}
 
Example #28
Source File: EvaluateXQuery.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .expressionLanguageSupported(ExpressionLanguageScope.NONE)
            .addValidator(new XQueryValidator())
            .required(false)
            .dynamic(true)
            .build();
}
 
Example #29
Source File: ExtractText.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .expressionLanguageSupported(ExpressionLanguageScope.NONE)
            .addValidator(StandardValidators.createRegexValidator(0, 40, true))
            .required(false)
            .dynamic(true)
            .build();
}
 
Example #30
Source File: PutCloudWatchMetric.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING, true))
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .dynamic(true)
            .build();
}