mirror of https://github.com/apache/nifi.git
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 <jfrazee@apache.org>
This commit is contained in:
parent
46e2420d74
commit
4d0667380a
|
@ -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) {
|
||||
|
|
|
@ -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 (tatu.saloranta@iki.fi), 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
|
||||
************************
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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> {
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue