mattyb149 commented on code in PR #6756:
URL: https://github.com/apache/nifi/pull/6756#discussion_r1043793836


##########
nifi-nar-bundles/nifi-dbcp-services-bundle/nifi-postgres-dbcp-service/src/main/java/org/apache/nifi/service/PostgreSQLConnectionPool.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.service;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.behavior.RequiresInstanceClassLoading;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.dbcp.AbstractDBCPConnectionPool;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.nifi.service.JdbcUrlFormat.FULL_URL;
+import static org.apache.nifi.service.JdbcUrlFormat.PARAMETERS;
+import static org.apache.nifi.service.JdbcUrlFormat.POSTGRESQL_BASIC_URI;
+
+/**
+ * Implementation of Database Connection Pooling Service for PostgreSQL with 
built-in JDBC driver.
+ * Apache DBCP is used for connection pooling functionality.
+ */
+@Tags({"postgres", "postgresql", "dbcp", "jdbc", "database", "connection", 
"pooling", "store"})
+@CapabilityDescription("Provides PostgreSQL Connection Pooling Service with 
built-in JDBC driver." +
+        " Connections can be requested from the pool and returned once they 
have been used.")
+@RequiresInstanceClassLoading
+public class PostgreSQLConnectionPool extends AbstractDBCPConnectionPool {
+
+    public static final PropertyDescriptor CONNECTION_URL_FORMAT = new 
PropertyDescriptor.Builder()
+            .name("connection-url-format")
+            .displayName("Connection URL Format")
+            .description("The format of the connection URL.")
+            .allowableValues(JdbcUrlFormat.class)
+            .required(true)
+            .defaultValue(FULL_URL.getValue())
+            .build();
+
+    public static final PropertyDescriptor POSTGRES_DATABASE_URL = new 
PropertyDescriptor.Builder()
+            .fromPropertyDescriptor(DATABASE_URL)
+            .dependsOn(CONNECTION_URL_FORMAT, FULL_URL)
+            .build();
+
+    public static final PropertyDescriptor DATABASE_NAME = new 
PropertyDescriptor.Builder()

Review Comment:
   Is this specifically requested as a feature, to be able to just populate 
parts of what will become the JDBC URL? If so I presume it has something to do 
with parameters and such? If not I wonder if we're ok with just the URL 
property like in DBCPConnectionPool



##########
nifi-nar-bundles/nifi-dbcp-services-bundle/nifi-postgres-dbcp-service/src/main/java/org/apache/nifi/service/PostgreSQLConnectionPool.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.service;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.behavior.RequiresInstanceClassLoading;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.dbcp.AbstractDBCPConnectionPool;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.nifi.service.JdbcUrlFormat.FULL_URL;
+import static org.apache.nifi.service.JdbcUrlFormat.PARAMETERS;
+import static org.apache.nifi.service.JdbcUrlFormat.POSTGRESQL_BASIC_URI;
+
+/**
+ * Implementation of Database Connection Pooling Service for PostgreSQL with 
built-in JDBC driver.
+ * Apache DBCP is used for connection pooling functionality.
+ */
+@Tags({"postgres", "postgresql", "dbcp", "jdbc", "database", "connection", 
"pooling", "store"})
+@CapabilityDescription("Provides PostgreSQL Connection Pooling Service with 
built-in JDBC driver." +

Review Comment:
   It looks like inheriting from `AbstractDBCPConnectionPool` adds support for 
JDBC/driver properties via dynamic properties. If so, the same annotation from 
DBCPConnectionPool should be added here for documentation purposes:
   
   ```
   @DynamicProperties({
           @DynamicProperty(name = "JDBC property name",
                   value = "JDBC property value",
                   expressionLanguageScope = 
ExpressionLanguageScope.VARIABLE_REGISTRY,
                   description = "JDBC driver property name and value applied 
to JDBC connections."),
           @DynamicProperty(name = "SENSITIVE.JDBC property name",
                   value = "JDBC property value",
                   expressionLanguageScope = ExpressionLanguageScope.NONE,
                   description = "JDBC driver property name prefixed with 
'SENSITIVE.' handled as a sensitive property.")
   })
   ```



##########
nifi-nar-bundles/nifi-dbcp-services-bundle/nifi-postgres-dbcp-service/pom.xml:
##########
@@ -0,0 +1,64 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <!-- 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. -->
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.nifi</groupId>
+        <artifactId>nifi-dbcp-services-bundle</artifactId>
+        <version>1.20.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>nifi-postgres-dbcp-service</artifactId>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-api</artifactId>
+            <version>1.20.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-dbcp-service-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-dbcp-base</artifactId>
+            <version>1.20.0-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.nifi</groupId>
+                    <artifactId>nifi-utils</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.postgresql</groupId>
+            <artifactId>postgresql</artifactId>
+            <version>42.5.1</version>

Review Comment:
   I presume that if the user needs a different driver, they would just use 
DBCPConnectionPool? I'm just concerned about the maintenance aspect of this 
Controller Service in the case of driver upgrades that break backwards 
compatibility. If this processor stops working for a customer after upgrade 
because we are now using a driver version that's "too new", they have to 
replace this with DBCPConnection Pool. I wonder if we should offer a Driver 
Location Override property or something just in case?



##########
nifi-nar-bundles/nifi-dbcp-services-bundle/nifi-postgres-dbcp-service/src/main/java/org/apache/nifi/service/PostgreSQLConnectionPool.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.service;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.behavior.RequiresInstanceClassLoading;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.dbcp.AbstractDBCPConnectionPool;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.nifi.service.JdbcUrlFormat.FULL_URL;
+import static org.apache.nifi.service.JdbcUrlFormat.PARAMETERS;
+import static org.apache.nifi.service.JdbcUrlFormat.POSTGRESQL_BASIC_URI;
+
+/**
+ * Implementation of Database Connection Pooling Service for PostgreSQL with 
built-in JDBC driver.
+ * Apache DBCP is used for connection pooling functionality.
+ */
+@Tags({"postgres", "postgresql", "dbcp", "jdbc", "database", "connection", 
"pooling", "store"})
+@CapabilityDescription("Provides PostgreSQL Connection Pooling Service with 
built-in JDBC driver." +
+        " Connections can be requested from the pool and returned once they 
have been used.")
+@RequiresInstanceClassLoading
+public class PostgreSQLConnectionPool extends AbstractDBCPConnectionPool {
+
+    public static final PropertyDescriptor CONNECTION_URL_FORMAT = new 
PropertyDescriptor.Builder()
+            .name("connection-url-format")
+            .displayName("Connection URL Format")
+            .description("The format of the connection URL.")
+            .allowableValues(JdbcUrlFormat.class)
+            .required(true)
+            .defaultValue(FULL_URL.getValue())
+            .build();
+
+    public static final PropertyDescriptor POSTGRES_DATABASE_URL = new 
PropertyDescriptor.Builder()
+            .fromPropertyDescriptor(DATABASE_URL)
+            .dependsOn(CONNECTION_URL_FORMAT, FULL_URL)
+            .build();
+
+    public static final PropertyDescriptor DATABASE_NAME = new 
PropertyDescriptor.Builder()
+            .name("database-name")
+            .displayName("Database Name")
+            .description("The name of the database to connect.")
+            .required(false)
+            .dependsOn(CONNECTION_URL_FORMAT, PARAMETERS)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+            .build();
+
+    public static final PropertyDescriptor DATABASE_HOSTNAME = new 
PropertyDescriptor.Builder()
+            .name("database-hostname")
+            .displayName("Database Hostname")
+            .description("The hostname of the database to connect.")
+            .required(false)
+            .dependsOn(CONNECTION_URL_FORMAT, PARAMETERS)
+            
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+            .build();
+
+    public static final PropertyDescriptor DATABASE_PORT = new 
PropertyDescriptor.Builder()
+            .name("database-port")
+            .displayName("Database Port")
+            .description("The port of the database to connect.")
+            .required(false)
+            .dependsOn(CONNECTION_URL_FORMAT, PARAMETERS)
+            
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+            .build();
+
+    private static final List<PropertyDescriptor> PROPERTIES = 
Collections.unmodifiableList(Arrays.asList(
+            CONNECTION_URL_FORMAT,
+            POSTGRES_DATABASE_URL,
+            DATABASE_NAME,
+            DATABASE_HOSTNAME,
+            DATABASE_PORT,
+            DB_USER,
+            DB_PASSWORD,
+            KERBEROS_USER_SERVICE,
+            MAX_WAIT_TIME,
+            MAX_TOTAL_CONNECTIONS,
+            VALIDATION_QUERY,
+            MIN_IDLE,
+            MAX_IDLE,
+            MAX_CONN_LIFETIME,
+            EVICTION_RUN_PERIOD,
+            MIN_EVICTABLE_IDLE_TIME,
+            SOFT_MIN_EVICTABLE_IDLE_TIME
+    ));
+
+    @Override
+    protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return PROPERTIES;
+    }
+
+    @Override
+    protected Driver getDriver(final String driverName, final String url) {
+        try {
+            return DriverManager.getDriver(url);
+        } catch (Exception e) {
+            throw new ProcessException("PostgreSQL driver unavailable or 
incompatible connection URL", e);

Review Comment:
   This should only ever happen if they entered an URL in invalid format 
(certainly not by entering parameters as we construct the URL for the user), 
recommend adding a unit test for this.



##########
nifi-nar-bundles/nifi-dbcp-services-bundle/nifi-postgres-dbcp-service/src/main/java/org/apache/nifi/service/PostgreSQLConnectionPool.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.service;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.behavior.RequiresInstanceClassLoading;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.dbcp.AbstractDBCPConnectionPool;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.nifi.service.JdbcUrlFormat.FULL_URL;
+import static org.apache.nifi.service.JdbcUrlFormat.PARAMETERS;
+import static org.apache.nifi.service.JdbcUrlFormat.POSTGRESQL_BASIC_URI;
+
+/**
+ * Implementation of Database Connection Pooling Service for PostgreSQL with 
built-in JDBC driver.
+ * Apache DBCP is used for connection pooling functionality.
+ */
+@Tags({"postgres", "postgresql", "dbcp", "jdbc", "database", "connection", 
"pooling", "store"})
+@CapabilityDescription("Provides PostgreSQL Connection Pooling Service with 
built-in JDBC driver." +
+        " Connections can be requested from the pool and returned once they 
have been used.")
+@RequiresInstanceClassLoading
+public class PostgreSQLConnectionPool extends AbstractDBCPConnectionPool {
+
+    public static final PropertyDescriptor CONNECTION_URL_FORMAT = new 
PropertyDescriptor.Builder()
+            .name("connection-url-format")
+            .displayName("Connection URL Format")
+            .description("The format of the connection URL.")

Review Comment:
   Recommend adding a trivial example here, such as 
`jdbc:postgresql://localhost:5432` or something 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to