Repository: nifi Updated Branches: refs/heads/master 23cbc3b34 -> 4d0667380
NIFI-3404: Improved UX of LookupAttributes. - Added dependency notice. - Added EL evaluation at SimpleKeyValueLookupService. - Updated documentation. - Updated CommonsConfigurationLookupService to throw LookupFailureException if it fails to get configuration so that error messages can be displayed at each processor bulletin. - Added calling getConfiguration at OnEnabled of CommonsConfigurationLookupService, so that the service will stay in Enabling state if there is any issue. Signed-off-by: Joey Frazee <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/4d066738 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/4d066738 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/4d066738 Branch: refs/heads/master Commit: 4d0667380a62510e9a10896be41ce1b2c5538db9 Parents: 46e2420 Author: Koji Kawamura <[email protected]> Authored: Thu May 25 13:22:54 2017 +0900 Committer: Joey Frazee <[email protected]> Committed: Thu May 25 10:05:32 2017 -0500 ---------------------------------------------------------------------- .../processors/standard/LookupAttribute.java | 6 ++-- .../src/main/resources/META-INF/NOTICE | 37 ++++++++++++++++++++ .../nifi/lookup/SimpleCsvFileLookupService.java | 2 +- .../lookup/SimpleKeyValueLookupService.java | 2 +- .../nifi/lookup/XMLFileLookupService.java | 5 ++- .../CommonsConfigurationLookupService.java | 16 ++++++--- .../lookup/TestPropertiesFileLookupService.java | 2 +- .../nifi/lookup/TestXMLFileLookupService.java | 2 +- 8 files changed, 61 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/4d066738/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/LookupAttribute.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/LookupAttribute.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/LookupAttribute.java index 1e0a674..64a83e9 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/LookupAttribute.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/LookupAttribute.java @@ -228,13 +228,15 @@ public class LookupAttribute extends AbstractProcessor { logger.debug("No such value for key: {}", new Object[]{lookupKey}); } } + + flowFile = session.putAllAttributes(flowFile, attributes); + session.transfer(flowFile, matched ? REL_MATCHED : REL_UNMATCHED); + } catch (final LookupFailureException e) { logger.error(e.getMessage(), e); session.transfer(flowFile, REL_FAILURE); } - flowFile = session.putAllAttributes(flowFile, attributes); - session.transfer(flowFile, matched ? REL_MATCHED : REL_UNMATCHED); } private boolean putAttribute(final String attributeName, final Optional<String> attributeValue, final Map<String, String> attributes, final boolean includeEmptyValues, final ComponentLog logger) { http://git-wip-us.apache.org/repos/asf/nifi/blob/4d066738/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services-nar/src/main/resources/META-INF/NOTICE ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services-nar/src/main/resources/META-INF/NOTICE b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services-nar/src/main/resources/META-INF/NOTICE index 5fd0f66..58b2dc8 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services-nar/src/main/resources/META-INF/NOTICE +++ b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services-nar/src/main/resources/META-INF/NOTICE @@ -80,11 +80,48 @@ The following binary components are provided under the Apache Software License v Apache Commons Net Copyright 2001-2016 The Apache Software Foundation + (ASLv2) Apache Commons Collections + The following NOTICE information applies: + Apache Commons Collections + Copyright 2001-2016 The Apache Software Foundation + + (ASLv2) Apache Commons IO + The following NOTICE information applies: + Apache Commons IO + Copyright 2002-2016 The Apache Software Foundation + (ASLv2) GeoIP2 Java API The following NOTICE information applies: GeoIP2 Java API This software is Copyright (c) 2013 by MaxMind, Inc. +ââ(ASLv2) Google HTTP Client Library for Java +ââââThe following NOTICE information applies: +ââââââCopyright 2011 Google Inc. + + (ASLv2) Jackson JSON processor + The following NOTICE information applies: + # Jackson JSON processor + + Jackson is a high-performance, Free/Open Source JSON processing library. + It was originally written by Tatu Saloranta ([email protected]), and has + been in development since 2007. + It is currently developed by a community of developers, as well as supported + commercially by FasterXML.com. + + ## Licensing + + Jackson core and extension components may licensed under different licenses. + To find the details that apply to this artifact see the accompanying LICENSE file. + For more information, including possible other licensing options, contact + FasterXML.com (http://fasterxml.com). + + ## Credits + + A list of contributors may be found from CREDITS file, which is included + in some artifacts (usually source distributions); but is always available + from the source code management (SCM) system project uses. + ************************ Creative Commons Attribution-ShareAlike 3.0 ************************ http://git-wip-us.apache.org/repos/asf/nifi/blob/4d066738/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleCsvFileLookupService.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleCsvFileLookupService.java b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleCsvFileLookupService.java index d5aa164..ae304a9 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleCsvFileLookupService.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleCsvFileLookupService.java @@ -52,7 +52,7 @@ import org.apache.nifi.util.file.monitor.LastModifiedMonitor; import org.apache.nifi.util.file.monitor.SynchronousFileWatcher; @Tags({"lookup", "cache", "enrich", "join", "csv", "reloadable", "key", "value"}) -@CapabilityDescription("A reloadable properties file-based lookup service") +@CapabilityDescription("A reloadable CSV file-based lookup service") public class SimpleCsvFileLookupService extends AbstractControllerService implements StringLookupService { private static final String KEY = "key"; http://git-wip-us.apache.org/repos/asf/nifi/blob/4d066738/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleKeyValueLookupService.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleKeyValueLookupService.java b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleKeyValueLookupService.java index 7176260..445d83c 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleKeyValueLookupService.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/SimpleKeyValueLookupService.java @@ -54,7 +54,7 @@ public class SimpleKeyValueLookupService extends AbstractControllerService imple @OnEnabled public void cacheConfiguredValues(final ConfigurationContext context) { lookupValues = context.getProperties().entrySet().stream() - .collect(Collectors.toMap(entry -> entry.getKey().getName(), entry -> context.getProperty(entry.getKey()).getValue())); + .collect(Collectors.toMap(entry -> entry.getKey().getName(), entry -> context.getProperty(entry.getKey()).evaluateAttributeExpressions().getValue())); } @Override http://git-wip-us.apache.org/repos/asf/nifi/blob/4d066738/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/XMLFileLookupService.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/XMLFileLookupService.java b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/XMLFileLookupService.java index e522e31..b8bcd85 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/XMLFileLookupService.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/XMLFileLookupService.java @@ -23,7 +23,10 @@ import org.apache.nifi.annotation.documentation.Tags; import org.apache.nifi.lookup.configuration2.CommonsConfigurationLookupService; @Tags({"lookup", "cache", "enrich", "join", "xml", "reloadable", "key", "value"}) -@CapabilityDescription("A reloadable properties file-based lookup service") +@CapabilityDescription("A reloadable XML file-based lookup service." + + " This service uses Apache Commons Configuration." + + " Example XML configuration file and how to access specific configuration can be found at" + + " http://commons.apache.org/proper/commons-configuration/userguide/howto_hierarchical.html") public class XMLFileLookupService extends CommonsConfigurationLookupService<XMLConfiguration> { } http://git-wip-us.apache.org/repos/asf/nifi/blob/4d066738/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/configuration2/CommonsConfigurationLookupService.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/configuration2/CommonsConfigurationLookupService.java b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/configuration2/CommonsConfigurationLookupService.java index a8be80f..ef1a73f 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/configuration2/CommonsConfigurationLookupService.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/configuration2/CommonsConfigurationLookupService.java @@ -42,6 +42,7 @@ import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.controller.AbstractControllerService; import org.apache.nifi.controller.ControllerServiceInitializationContext; import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.lookup.LookupFailureException; import org.apache.nifi.lookup.StringLookupService; import org.apache.nifi.processor.util.StandardValidators; import org.apache.nifi.reporting.InitializationException; @@ -73,14 +74,13 @@ public abstract class CommonsConfigurationLookupService<T extends FileBasedConfi private volatile ReloadingFileBasedConfigurationBuilder<T> builder; - private Configuration getConfiguration() { + private Configuration getConfiguration() throws LookupFailureException { try { if (builder != null) { return builder.getConfiguration(); } } catch (final ConfigurationException e) { - // TODO: Need to fail starting the service if this happens - getLogger().error(e.getMessage(), e); + throw new LookupFailureException("Failed to get configuration due to " + e.getMessage(), e); } return null; } @@ -111,10 +111,18 @@ public abstract class CommonsConfigurationLookupService<T extends FileBasedConfi } } }); + + try { + // Try getting configuration to see if there is any issue, for example wrong file format. + // Then throw InitializationException to keep this service in 'Enabling' state. + builder.getConfiguration(); + } catch (ConfigurationException e) { + throw new InitializationException(e); + } } @Override - public Optional<String> lookup(final Map<String, String> coordinates) { + public Optional<String> lookup(final Map<String, String> coordinates) throws LookupFailureException { if (coordinates == null) { return Optional.empty(); } http://git-wip-us.apache.org/repos/asf/nifi/blob/4d066738/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestPropertiesFileLookupService.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestPropertiesFileLookupService.java b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestPropertiesFileLookupService.java index 7cfd1dd..3301302 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestPropertiesFileLookupService.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestPropertiesFileLookupService.java @@ -34,7 +34,7 @@ public class TestPropertiesFileLookupService { final static Optional<String> EMPTY_STRING = Optional.empty(); @Test - public void testPropertiesFileLookupService() throws InitializationException { + public void testPropertiesFileLookupService() throws InitializationException, LookupFailureException { final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class); final PropertiesFileLookupService service = new PropertiesFileLookupService(); http://git-wip-us.apache.org/repos/asf/nifi/blob/4d066738/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestXMLFileLookupService.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestXMLFileLookupService.java b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestXMLFileLookupService.java index 6063858..34c7b87 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestXMLFileLookupService.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestXMLFileLookupService.java @@ -34,7 +34,7 @@ public class TestXMLFileLookupService { final static Optional<String> EMPTY_STRING = Optional.empty(); @Test - public void testXMLFileLookupService() throws InitializationException { + public void testXMLFileLookupService() throws InitializationException, LookupFailureException { final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class); final XMLFileLookupService service = new XMLFileLookupService();
