NIFI-677, DBCPService should allow user to specify Connection URL should fix also NIFI-676 and NIFI-678
Signed-off-by: Toivo Adams <toivo.ad...@gmail.com> Signed-off-by: Mark Payne <marka...@hotmail.com> Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/ae9b40ec Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/ae9b40ec Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/ae9b40ec Branch: refs/heads/develop Commit: ae9b40ec6f71f69b7866d309464476686d3eebfa Parents: a3b8e44 Author: Toivo Adams <toivo.ad...@gmail.com> Authored: Thu Jun 11 18:27:23 2015 +0300 Committer: Mark Payne <marka...@hotmail.com> Committed: Wed Jun 17 12:37:26 2015 -0400 ---------------------------------------------------------------------- .../apache/nifi/dbcp/DBCPConnectionPool.java | 51 ++++-------------- .../nifi/dbcp/DatabaseSystemDescriptor.java | 1 + .../org/apache/nifi/dbcp/DatabaseSystems.java | 1 + .../org/apache/nifi/dbcp/DBCPServiceTest.java | 54 +++++--------------- 4 files changed, 25 insertions(+), 82 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ae9b40ec/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java b/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java index ef42be3..9ea93bb 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java +++ b/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java @@ -49,35 +49,19 @@ import org.apache.nifi.reporting.InitializationException; @CapabilityDescription("Provides Database Connection Pooling Service. Connections can be asked from pool and returned after usage.") public class DBCPConnectionPool extends AbstractControllerService implements DBCPService { - public static final DatabaseSystemDescriptor DEFAULT_DATABASE_SYSTEM = DatabaseSystems.getDescriptor("JavaDB"); - - public static final PropertyDescriptor DATABASE_SYSTEM = new PropertyDescriptor.Builder() - .name("Database Type") - .description("Database management system") - .allowableValues(DatabaseSystems.knownDatabaseSystems) - .defaultValue(DEFAULT_DATABASE_SYSTEM.getValue()) - .required(true) - .build(); - - public static final PropertyDescriptor DB_HOST = new PropertyDescriptor.Builder() - .name("Database Host") - .description("Database Host") + public static final PropertyDescriptor DATABASE_URL = new PropertyDescriptor.Builder() + .name("Database connection URL") + .description("A database connection URL used to connect to a database. May contain database system name, host, port, database name and some parameters." + + " The exact syntax of a database connection URL is specified by your DBMS.") .defaultValue(null) - .required(true) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .build(); - - public static final PropertyDescriptor DB_PORT = new PropertyDescriptor.Builder() - .name("Database Port") - .description("Database server port") .required(true) - .addValidator(StandardValidators.PORT_VALIDATOR) .build(); public static final PropertyDescriptor DB_DRIVERNAME = new PropertyDescriptor.Builder() .name("Database Driver Class Name") .description("Database driver class name") - .defaultValue(DEFAULT_DATABASE_SYSTEM.driverClassName) + .defaultValue(null) .required(true) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .build(); @@ -90,14 +74,6 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC .addValidator(StandardValidators.URL_VALIDATOR) .build(); - public static final PropertyDescriptor DB_NAME = new PropertyDescriptor.Builder() - .name("Database Name") - .description("Database name") - .defaultValue(null) - .required(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .build(); - public static final PropertyDescriptor DB_USER = new PropertyDescriptor.Builder() .name("Database User") .description("Database user name") @@ -110,9 +86,9 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC .name("Password") .description("The password for the database user") .defaultValue(null) - .required(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .required(false) .sensitive(true) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .build(); public static final PropertyDescriptor MAX_WAIT_TIME = new PropertyDescriptor.Builder() @@ -139,12 +115,9 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC static { List<PropertyDescriptor> props = new ArrayList<>(); - props.add(DATABASE_SYSTEM); - props.add(DB_HOST); - props.add(DB_PORT); + props.add(DATABASE_URL); props.add(DB_DRIVERNAME); props.add(DB_DRIVER_JAR_URL); - props.add(DB_NAME); props.add(DB_USER); props.add(DB_PASSWORD); props.add(MAX_WAIT_TIME); @@ -167,12 +140,8 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC */ @OnEnabled public void onConfigured(final ConfigurationContext context) throws InitializationException { - DatabaseSystemDescriptor dbsystem = DatabaseSystems.getDescriptor( context.getProperty(DATABASE_SYSTEM).getValue() ); - - String host = context.getProperty(DB_HOST).getValue(); - Integer port = context.getProperty(DB_PORT).asInteger(); + String drv = context.getProperty(DB_DRIVERNAME).getValue(); - String dbname = context.getProperty(DB_NAME).getValue(); String user = context.getProperty(DB_USER).getValue(); String passw = context.getProperty(DB_PASSWORD).getValue(); Long maxWaitMillis = context.getProperty(MAX_WAIT_TIME).asTimePeriod(TimeUnit.MILLISECONDS); @@ -185,7 +154,7 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC String urlString = context.getProperty(DB_DRIVER_JAR_URL).getValue(); dataSource.setDriverClassLoader( getDriverClassLoader(urlString, drv) ); - String dburl = dbsystem.buildUrl(host, port, dbname); + String dburl = context.getProperty(DATABASE_URL).getValue(); dataSource.setMaxWait(maxWaitMillis); dataSource.setMaxActive(maxTotal); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ae9b40ec/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystemDescriptor.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystemDescriptor.java b/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystemDescriptor.java index fd45421..00e30ca 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystemDescriptor.java +++ b/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystemDescriptor.java @@ -24,6 +24,7 @@ import org.apache.nifi.components.AllowableValue; * An immutable object for holding information about a database system. * */ +@Deprecated public class DatabaseSystemDescriptor extends AllowableValue { public final String driverClassName; http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ae9b40ec/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystems.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystems.java b/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystems.java index 2d21cd7..943f6d2 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystems.java +++ b/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DatabaseSystems.java @@ -16,6 +16,7 @@ */ package org.apache.nifi.dbcp; +@Deprecated public class DatabaseSystems { /** http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ae9b40ec/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java b/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java index 541df8f..fe23b31 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java +++ b/nifi/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java @@ -16,7 +16,6 @@ */ package org.apache.nifi.dbcp; -import static org.apache.nifi.dbcp.DatabaseSystems.getDescriptor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -53,21 +52,6 @@ public class DBCPServiceTest { System.setProperty("derby.stream.error.file", "target/derby.log"); } - - /** - * Unknown database system. - * - */ - @Test - public void testUnknownDatabaseSystem() throws InitializationException { - final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class); - final DBCPConnectionPool service = new DBCPConnectionPool(); - final Map<String, String> properties = new HashMap<String, String>(); - properties.put(DBCPConnectionPool.DATABASE_SYSTEM.getName(), "garbage"); - runner.addControllerService("test-bad2", service, properties); - runner.assertNotValid(service); - } - /** * Missing property values. */ @@ -95,15 +79,11 @@ public class DBCPServiceTest { File dbLocation = new File(DB_LOCATION); dbLocation.delete(); - // Should setProperty call also generate DBCPConnectionPool.onPropertyModified() method call? - // It does not currently. - - // Some properties already should have JavaDB/Derby default values, let's set only missing values. - runner.setProperty(service, DBCPConnectionPool.DB_HOST, "NA"); // Embedded Derby don't use host - runner.setProperty(service, DBCPConnectionPool.DB_PORT, "1"); // Embedded Derby don't use port, but must have value anyway - runner.setProperty(service, DBCPConnectionPool.DB_NAME, DB_LOCATION); + // set embedded Derby database connection url + runner.setProperty(service, DBCPConnectionPool.DATABASE_URL, "jdbc:derby:" + DB_LOCATION + ";create=true"); 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.enableControllerService(service); @@ -134,18 +114,11 @@ public class DBCPServiceTest { final DBCPConnectionPool service = new DBCPConnectionPool(); runner.addControllerService("test-external-jar", service); - DatabaseSystemDescriptor mariaDb = getDescriptor("MariaDB"); - assertNotNull(mariaDb); + // set MariaDB database connection url + runner.setProperty(service, DBCPConnectionPool.DATABASE_URL, "jdbc:mariadb://localhost:3306/" + "testdb"); + runner.setProperty(service, DBCPConnectionPool.DB_DRIVERNAME, "org.mariadb.jdbc.Driver"); + runner.setProperty(service, DBCPConnectionPool.DB_DRIVER_JAR_URL, "file:///var/tmp/mariadb-java-client-1.1.7.jar"); - // Set MariaDB properties values. - runner.setProperty(service, DBCPConnectionPool.DATABASE_SYSTEM, mariaDb.getValue()); - runner.setProperty(service, DBCPConnectionPool.DB_PORT, mariaDb.defaultPort.toString()); - runner.setProperty(service, DBCPConnectionPool.DB_DRIVERNAME, mariaDb.driverClassName); - runner.setProperty(service, DBCPConnectionPool.DB_DRIVER_JAR_URL, "file:///var/tmp/mariadb-java-client-1.1.7.jar"); - - - runner.setProperty(service, DBCPConnectionPool.DB_HOST, "localhost"); // localhost - runner.setProperty(service, DBCPConnectionPool.DB_NAME, "testdb"); runner.setProperty(service, DBCPConnectionPool.DB_USER, "tester"); runner.setProperty(service, DBCPConnectionPool.DB_PASSWORD, "testerp"); @@ -181,11 +154,10 @@ public class DBCPServiceTest { File dbLocation = new File(DB_LOCATION); dbLocation.delete(); - runner.setProperty(service, DBCPConnectionPool.DB_HOST, "NA"); // Embedded Derby don't use host - runner.setProperty(service, DBCPConnectionPool.DB_PORT, "1"); // Embedded Derby don't use port, but must have value anyway - runner.setProperty(service, DBCPConnectionPool.DB_NAME, DB_LOCATION); + // set embedded Derby database connection url + runner.setProperty(service, DBCPConnectionPool.DATABASE_URL, "jdbc:derby:" + DB_LOCATION + ";create=true"); 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.enableControllerService(service); @@ -216,11 +188,11 @@ public class DBCPServiceTest { File dbLocation = new File(DB_LOCATION); dbLocation.delete(); - runner.setProperty(service, DBCPConnectionPool.DB_HOST, "NA"); // Embedded Derby don't use host - runner.setProperty(service, DBCPConnectionPool.DB_PORT, "1"); // Embedded Derby don't use port, but must have value anyway - runner.setProperty(service, DBCPConnectionPool.DB_NAME, DB_LOCATION); + // set embedded Derby database connection url + runner.setProperty(service, DBCPConnectionPool.DATABASE_URL, "jdbc:derby:" + DB_LOCATION + ";create=true"); 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.enableControllerService(service);