This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a5a2da  NIFI-6954: Evaluate EL for DBCPConnectionPool properties
3a5a2da is described below

commit 3a5a2da73c2a74ad390487bd2d22dac1dd3954ac
Author: Matthew Burgess <[email protected]>
AuthorDate: Tue Dec 17 10:09:47 2019 -0500

    NIFI-6954: Evaluate EL for DBCPConnectionPool properties
    
    Signed-off-by: Pierre Villard <[email protected]>
    
    This closes #3940.
---
 .../org/apache/nifi/dbcp/DBCPConnectionPool.java   | 30 ++++++++++++----------
 .../java/org/apache/nifi/dbcp/DBCPServiceTest.java | 24 ++++++++++++-----
 2 files changed, 33 insertions(+), 21 deletions(-)

diff --git 
a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java
 
b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java
index 3508fee..cdc91ce 100644
--- 
a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java
+++ 
b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java
@@ -61,28 +61,28 @@ import java.util.concurrent.TimeUnit;
 public class DBCPConnectionPool extends AbstractControllerService implements 
DBCPService {
 
     /**
-     * Copied from {@link GenericObjectPoolConfig.DEFAULT_MIN_IDLE} in 
Commons-DBCP 2.5.0
+     * Copied from {@link GenericObjectPoolConfig.DEFAULT_MIN_IDLE} in 
Commons-DBCP 2.7.0
      */
     private static final String DEFAULT_MIN_IDLE = "0";
     /**
-     * Copied from {@link GenericObjectPoolConfig.DEFAULT_MAX_IDLE} in 
Commons-DBCP 2.5.0
+     * Copied from {@link GenericObjectPoolConfig.DEFAULT_MAX_IDLE} in 
Commons-DBCP 2.7.0
      */
     private static final String DEFAULT_MAX_IDLE = "8";
     /**
-     * Copied from private variable {@link 
BasicDataSource.maxConnLifetimeMillis} in Commons-DBCP 2.5.0
+     * Copied from private variable {@link 
BasicDataSource.maxConnLifetimeMillis} in Commons-DBCP 2.7.0
      */
     private static final String DEFAULT_MAX_CONN_LIFETIME = "-1";
     /**
-     * Copied from {@link 
GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS} in 
Commons-DBCP 2.5.0
+     * Copied from {@link 
GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS} in 
Commons-DBCP 2.7.0
      */
     private static final String DEFAULT_EVICTION_RUN_PERIOD = 
String.valueOf(-1L);
     /**
-     * Copied from {@link 
GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS} in Commons-DBCP 
2.5.0
+     * Copied from {@link 
GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS} in Commons-DBCP 
2.7.0
      * and converted from 1800000L to "1800000 millis" to "30 mins"
      */
     private static final String DEFAULT_MIN_EVICTABLE_IDLE_TIME = "30 mins";
     /**
-     * Copied from {@link 
GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS} in 
Commons-DBCP 2.5.0
+     * Copied from {@link 
GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS} in 
Commons-DBCP 2.7.0
      */
     private static final String DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME = 
String.valueOf(-1L);
 
@@ -140,6 +140,7 @@ public class DBCPConnectionPool extends 
AbstractControllerService implements DBC
         .defaultValue("500 millis")
         .required(true)
         .addValidator(DBCPValidator.CUSTOM_TIME_PERIOD_VALIDATOR)
+        .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
         .sensitive(false)
         .build();
 
@@ -150,6 +151,7 @@ public class DBCPConnectionPool extends 
AbstractControllerService implements DBC
         .defaultValue("8")
         .required(true)
         .addValidator(StandardValidators.INTEGER_VALIDATOR)
+        .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
         .sensitive(false)
         .build();
 
@@ -306,15 +308,15 @@ public class DBCPConnectionPool extends 
AbstractControllerService implements DBC
         final String drv = 
context.getProperty(DB_DRIVERNAME).evaluateAttributeExpressions().getValue();
         final String user = 
context.getProperty(DB_USER).evaluateAttributeExpressions().getValue();
         final String passw = 
context.getProperty(DB_PASSWORD).evaluateAttributeExpressions().getValue();
-        final Integer maxTotal = 
context.getProperty(MAX_TOTAL_CONNECTIONS).asInteger();
+        final Integer maxTotal = 
context.getProperty(MAX_TOTAL_CONNECTIONS).evaluateAttributeExpressions().asInteger();
         final String validationQuery = 
context.getProperty(VALIDATION_QUERY).evaluateAttributeExpressions().getValue();
-        final Long maxWaitMillis = 
extractMillisWithInfinite(context.getProperty(MAX_WAIT_TIME));
-        final Integer minIdle = context.getProperty(MIN_IDLE).asInteger();
-        final Integer maxIdle = context.getProperty(MAX_IDLE).asInteger();
-        final Long maxConnLifetimeMillis = 
extractMillisWithInfinite(context.getProperty(MAX_CONN_LIFETIME));
-        final Long timeBetweenEvictionRunsMillis = 
extractMillisWithInfinite(context.getProperty(EVICTION_RUN_PERIOD));
-        final Long minEvictableIdleTimeMillis = 
extractMillisWithInfinite(context.getProperty(MIN_EVICTABLE_IDLE_TIME));
-        final Long softMinEvictableIdleTimeMillis = 
extractMillisWithInfinite(context.getProperty(SOFT_MIN_EVICTABLE_IDLE_TIME));
+        final Long maxWaitMillis = 
extractMillisWithInfinite(context.getProperty(MAX_WAIT_TIME).evaluateAttributeExpressions());
+        final Integer minIdle = 
context.getProperty(MIN_IDLE).evaluateAttributeExpressions().asInteger();
+        final Integer maxIdle = 
context.getProperty(MAX_IDLE).evaluateAttributeExpressions().asInteger();
+        final Long maxConnLifetimeMillis = 
extractMillisWithInfinite(context.getProperty(MAX_CONN_LIFETIME).evaluateAttributeExpressions());
+        final Long timeBetweenEvictionRunsMillis = 
extractMillisWithInfinite(context.getProperty(EVICTION_RUN_PERIOD).evaluateAttributeExpressions());
+        final Long minEvictableIdleTimeMillis = 
extractMillisWithInfinite(context.getProperty(MIN_EVICTABLE_IDLE_TIME).evaluateAttributeExpressions());
+        final Long softMinEvictableIdleTimeMillis = 
extractMillisWithInfinite(context.getProperty(SOFT_MIN_EVICTABLE_IDLE_TIME).evaluateAttributeExpressions());
         final KerberosCredentialsService kerberosCredentialsService = 
context.getProperty(KERBEROS_CREDENTIALS_SERVICE).asControllerService(KerberosCredentialsService.class);
 
         if (kerberosCredentialsService != null) {
diff --git 
a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java
 
b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java
index 2714e2e..7522125 100644
--- 
a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java
+++ 
b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java
@@ -200,13 +200,23 @@ public class DBCPServiceTest {
         runner.setProperty(service, DBCPConnectionPool.DB_USER, "tester");
         runner.setProperty(service, DBCPConnectionPool.DB_PASSWORD, "testerp");
         runner.setProperty(service, DBCPConnectionPool.DB_DRIVERNAME, 
"org.apache.derby.jdbc.EmbeddedDriver");
-        runner.setProperty(service, DBCPConnectionPool.MAX_WAIT_TIME, "-1");
-        runner.setProperty(service, DBCPConnectionPool.MAX_IDLE, "4");
-        runner.setProperty(service, DBCPConnectionPool.MIN_IDLE, "1");
-        runner.setProperty(service, DBCPConnectionPool.MAX_CONN_LIFETIME, 
"1000 millis");
-        runner.setProperty(service, DBCPConnectionPool.EVICTION_RUN_PERIOD, 
"100 millis");
-        runner.setProperty(service, 
DBCPConnectionPool.MIN_EVICTABLE_IDLE_TIME, "100 millis");
-        runner.setProperty(service, 
DBCPConnectionPool.SOFT_MIN_EVICTABLE_IDLE_TIME, "100 millis");
+        runner.setProperty(service, DBCPConnectionPool.MAX_WAIT_TIME, 
"${max.wait.time}");
+        runner.setProperty(service, DBCPConnectionPool.MAX_TOTAL_CONNECTIONS, 
"${max.total.connections}");
+        runner.setProperty(service, DBCPConnectionPool.MAX_IDLE, 
"${max.idle}");
+        runner.setProperty(service, DBCPConnectionPool.MIN_IDLE, 
"${min.idle}");
+        runner.setProperty(service, DBCPConnectionPool.MAX_CONN_LIFETIME, 
"${max.conn.lifetime}");
+        runner.setProperty(service, DBCPConnectionPool.EVICTION_RUN_PERIOD, 
"${eviction.run.period}");
+        runner.setProperty(service, 
DBCPConnectionPool.MIN_EVICTABLE_IDLE_TIME, "${min.evictable.idle.time}");
+        runner.setProperty(service, 
DBCPConnectionPool.SOFT_MIN_EVICTABLE_IDLE_TIME, 
"${soft.min.evictable.idle.time}");
+
+        runner.setVariable("max.wait.time", "1 sec");
+        runner.setVariable("max.total.connections", "7");
+        runner.setVariable("max.idle", "4");
+        runner.setVariable("min.idle", "1");
+        runner.setVariable("max.conn.lifetime", "1000 millis");
+        runner.setVariable("eviction.run.period", "100 millis");
+        runner.setVariable("min.evictable.idle.time", "100 millis");
+        runner.setVariable("soft.min.evictable.idle.time", "100 millis");
 
         runner.enableControllerService(service);
 

Reply via email to