[
https://issues.apache.org/jira/browse/NIFI-3404?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16019259#comment-16019259
]
ASF GitHub Bot commented on NIFI-3404:
--------------------------------------
Github user ijokarumawak commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1830#discussion_r117685550
--- Diff:
nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/DatabaseLookupService.java
---
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.lookup;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import javax.sql.DataSource;
+
+import org.apache.commons.configuration2.Configuration;
+import org.apache.commons.configuration2.DatabaseConfiguration;
+import org.apache.commons.configuration2.ex.ConfigurationException;
+import org.apache.commons.configuration2.builder.BasicConfigurationBuilder;
+import org.apache.commons.configuration2.builder.fluent.Parameters;
+import
org.apache.commons.configuration2.builder.fluent.DatabaseBuilderParameters;
+import org.apache.commons.lang3.StringUtils;
+
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+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.dbcp.DBCPService;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.reporting.InitializationException;
+
+@Tags({"lookup", "cache", "enrich", "join", "jdbc", "database", "key",
"value"})
+@CapabilityDescription("A reloadable properties file-based lookup service")
+public class DatabaseLookupService extends AbstractControllerService
implements StringLookupService {
+
+ static final PropertyDescriptor CONNECTION_POOL = new
PropertyDescriptor.Builder()
+ .name("connection-pool")
+ .displayName("Connection Pool")
+ .description("Specifices the JDBC connection pool used to connect
to the database.")
+ .identifiesControllerService(DBCPService.class)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor LOOKUP_TABLE_NAME = new
PropertyDescriptor.Builder()
+ .name("lookup-table-name")
+ .displayName("Lookup Table Name")
+ .description("Lookup table name.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(true)
+ .build();
+
+ static final PropertyDescriptor LOOKUP_KEY_COLUMN =
+ new PropertyDescriptor.Builder()
+ .name("lookup-key-column")
+ .displayName("Lookup Key Column")
+ .description("Lookup key column.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(true)
+ .build();
+
+ static final PropertyDescriptor LOOKUP_VALUE_COLUMN =
+ new PropertyDescriptor.Builder()
+ .name("lookup-value-column")
+ .displayName("Lookup Value Column")
+ .description("Lookup value column.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(true)
+ .build();
+
+ static final PropertyDescriptor LOOKUP_NAME_COLUMN =
+ new PropertyDescriptor.Builder()
+ .name("lookup-name-column")
+ .displayName("Lookup Name Column")
+ .description("Lookup name column.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(true)
+ .build();
+
+ static final PropertyDescriptor LOOKUP_NAME =
+ new PropertyDescriptor.Builder()
+ .name("lookup-name")
+ .displayName("Lookup Name")
+ .description("Lookup name.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(true)
+ .build();
+
+ private List<PropertyDescriptor> properties;
+
+ private volatile BasicConfigurationBuilder<DatabaseConfiguration>
builder;
+
+ private Configuration getConfiguration() {
+ try {
+ if (builder != null) {
+ return builder.getConfiguration();
+ }
+ } catch (final ConfigurationException e) {
+ getLogger().error(e.getMessage(), e);
+ }
+ return null;
+ }
+
+ @Override
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return properties;
+ }
+
+ @Override
+ protected void init(final ControllerServiceInitializationContext
context) throws InitializationException {
+ super.init(context);
+ final List<PropertyDescriptor> properties = new
ArrayList<>(super.getSupportedPropertyDescriptors());
+ properties.add(CONNECTION_POOL);
+ properties.add(LOOKUP_TABLE_NAME);
+ properties.add(LOOKUP_KEY_COLUMN);
+ properties.add(LOOKUP_VALUE_COLUMN);
+ properties.add(LOOKUP_NAME_COLUMN);
+ properties.add(LOOKUP_NAME);
+ this.properties = Collections.unmodifiableList(properties);
+ }
+
+ @OnEnabled
+ public void onEnabled(final ConfigurationContext context) throws
InitializationException {
+ final DBCPService databaseService =
context.getProperty(CONNECTION_POOL).asControllerService(DBCPService.class);
+ final DataSource dataSource = databaseService.getDataSource();
--- End diff --
As discussed at #1450, I think we'd better to avoid exposing DataSource
from DBCPService. Wrapping Connection to be a DataSource can be done here
without requiring DBCPService change. Thought?
> Add lookup processor for enrichments/joins to reference data
> ------------------------------------------------------------
>
> Key: NIFI-3404
> URL: https://issues.apache.org/jira/browse/NIFI-3404
> Project: Apache NiFi
> Issue Type: Improvement
> Reporter: Joey Frazee
> Assignee: Joey Frazee
>
> NiFi doesn't currently have an easy, concise way of doing enrichment, joining
> against reference data sets or performing attribute lookups against external
> data sources.
> Since enrichments and joins are basic streaming use cases, and since
> attributes and EL are often used to parameterize processor properties, there
> is a need for an easy way to do enrichments, joins and lookups without having
> to write code or create a lengthy data flow.
> There's been some discussion of this on the mailing list [1] and I've started
> work on a LookupAttribute [2] processor that delegates the work to controller
> services.
> 1.
> https://lists.apache.org/thread.html/74321ff0e9e0b7339e43ad53b36119315dc5094991605edfb12b34d0@%3Cdev.nifi.apache.org%3E
> 2. https://github.com/jfrazee/nifi-lookup-service
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)