This is an automated email from the ASF dual-hosted git repository. exceptionfactory pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push: new 6358249 NIFI-9609 Added nifi-snowflake-bundle with SnowflakeComputingConnectionPool 6358249 is described below commit 635824904db67d9cebc2f3073c7aeb2ea59e2b9f Author: Tamas Palfy <tamas.bertalan.pa...@gmail.com> AuthorDate: Thu Jan 20 19:38:09 2022 +0100 NIFI-9609 Added nifi-snowflake-bundle with SnowflakeComputingConnectionPool - Updated DBCPConnectionPool for extension This closes #5692 Signed-off-by: David Handermann <exceptionfact...@apache.org> --- nifi-assembly/NOTICE | 5 + nifi-assembly/pom.xml | 14 ++ .../nifi-snowflake-services-nar/pom.xml | 42 +++++ .../src/main/resources/META-INF/LICENSE | 204 +++++++++++++++++++++ .../src/main/resources/META-INF/NOTICE | 31 ++++ .../nifi-snowflake-services/pom.xml | 68 +++++++ .../service/SnowflakeComputingConnectionPool.java | 128 +++++++++++++ .../org.apache.nifi.controller.ControllerService | 15 ++ .../service/SnowflakeConnectionPoolIT.java | 87 +++++++++ nifi-nar-bundles/nifi-snowflake-bundle/pom.xml | 29 +++ .../org/apache/nifi/dbcp/DBCPConnectionPool.java | 38 ++-- nifi-nar-bundles/pom.xml | 1 + 12 files changed, 645 insertions(+), 17 deletions(-) diff --git a/nifi-assembly/NOTICE b/nifi-assembly/NOTICE index e5cf091..1427875 100644 --- a/nifi-assembly/NOTICE +++ b/nifi-assembly/NOTICE @@ -680,6 +680,11 @@ The following binary components are provided under the Apache Software License v Apache CXF Copyright 2008-2017 The Apache Software Foundation + (ASLv2) snowflake-jdbc + The following NOTICE information applies: + snowflake-jdbc + Copyright (c) 2013-2018 Snowflake Computing, Inc. + (ASLv2) Apache Lucene The following NOTICE information applies: Apache Lucene diff --git a/nifi-assembly/pom.xml b/nifi-assembly/pom.xml index c03f020..2a60a44 100644 --- a/nifi-assembly/pom.xml +++ b/nifi-assembly/pom.xml @@ -1270,6 +1270,20 @@ language governing permissions and limitations under the License. --> </dependencies> </profile> <profile> + <id>include-snowflake</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-snowflake-services-nar</artifactId> + <version>1.16.0-SNAPSHOT</version> + <type>nar</type> + </dependency> + </dependencies> + </profile> + <profile> <id>avoid-archive-formats</id> <activation> <property> diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services-nar/pom.xml b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services-nar/pom.xml new file mode 100644 index 0000000..7b8c61c --- /dev/null +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services-nar/pom.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-snowflake-bundle</artifactId> + <version>1.16.0-SNAPSHOT</version> + </parent> + + <artifactId>nifi-snowflake-services-nar</artifactId> + <version>1.16.0-SNAPSHOT</version> + <packaging>nar</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-snowflake-services</artifactId> + <version>1.16.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-dbcp-service-nar</artifactId> + <version>1.16.0-SNAPSHOT</version> + <type>nar</type> + </dependency> + </dependencies> +</project> \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services-nar/src/main/resources/META-INF/LICENSE b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services-nar/src/main/resources/META-INF/LICENSE new file mode 100644 index 0000000..de4b130 --- /dev/null +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services-nar/src/main/resources/META-INF/LICENSE @@ -0,0 +1,204 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services-nar/src/main/resources/META-INF/NOTICE b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services-nar/src/main/resources/META-INF/NOTICE new file mode 100644 index 0000000..17172ba --- /dev/null +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services-nar/src/main/resources/META-INF/NOTICE @@ -0,0 +1,31 @@ +nifi-snowflake-services-nar +Copyright 2015-2020 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +****************** +Apache Software License v2 +****************** + +The following binary components are provided under the Apache Software License v2 + + (ASLv2) Apache Commons Lang + The following NOTICE information applies: + Apache Commons Lang + Copyright 2001-2021 The Apache Software Foundation + + (ASLv2) Apache Commons DBCP + The following NOTICE information applies: + Apache Commons DBCP + Copyright 2002-2019 The Apache Software Foundation + + (ASLv2) Apache Commons Pool + The following NOTICE information applies: + Apache Commons Pool + Copyright 2002-2019 The Apache Software Foundation + + (ASLv2) snowflake-jdbc + The following NOTICE information applies: + snowflake-jdbc + Copyright (c) 2013-2018 Snowflake Computing, Inc. diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/pom.xml b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/pom.xml new file mode 100644 index 0000000..094840a --- /dev/null +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/pom.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-snowflake-bundle</artifactId> + <version>1.16.0-SNAPSHOT</version> + </parent> + + <artifactId>nifi-snowflake-services</artifactId> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-dbcp-service-api</artifactId> + <version>1.16.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-dbcp-service</artifactId> + <version>1.16.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-kerberos-credentials-service-api</artifactId> + <version>1.16.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-kerberos-user-service-api</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>net.snowflake</groupId> + <artifactId>snowflake-jdbc</artifactId> + <version>3.13.14</version> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-mock</artifactId> + <version>1.16.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/src/main/java/org/apache/nifi/snowflake/service/SnowflakeComputingConnectionPool.java b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/src/main/java/org/apache/nifi/snowflake/service/SnowflakeComputingConnectionPool.java new file mode 100644 index 0000000..f4ea36a --- /dev/null +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/src/main/java/org/apache/nifi/snowflake/service/SnowflakeComputingConnectionPool.java @@ -0,0 +1,128 @@ +/* + * 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.snowflake.service; + +import net.snowflake.client.jdbc.SnowflakeDriver; +import org.apache.nifi.annotation.behavior.DynamicProperties; +import org.apache.nifi.annotation.behavior.DynamicProperty; +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.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.dbcp.DBCPConnectionPool; +import org.apache.nifi.expression.ExpressionLanguageScope; +import org.apache.nifi.processor.exception.ProcessException; + +import java.sql.Driver; +import java.sql.DriverManager; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * Implementation of Database Connection Pooling Service for Snowflake. + * Apache DBCP is used for connection pooling functionality. + */ +@Tags({"snowflake", "dbcp", "jdbc", "database", "connection", "pooling", "store"}) +@CapabilityDescription("Provides Snowflake Connection Pooling Service. Connections can be asked from pool and returned after usage.") +@DynamicProperties({ + @DynamicProperty(name = "JDBC property name", + value = "Snowflake JDBC property value", + expressionLanguageScope = ExpressionLanguageScope.VARIABLE_REGISTRY, + description = "Snowflake JDBC driver property name and value applied to JDBC connections."), + @DynamicProperty(name = "SENSITIVE.JDBC property name", + value = "Snowflake JDBC property value", + expressionLanguageScope = ExpressionLanguageScope.NONE, + description = "Snowflake JDBC driver property name prefixed with 'SENSITIVE.' handled as a sensitive property.") +}) +@RequiresInstanceClassLoading +public class SnowflakeComputingConnectionPool extends DBCPConnectionPool { + + public static final PropertyDescriptor SNOWFLAKE_URL = new PropertyDescriptor.Builder() + .fromPropertyDescriptor(DBCPConnectionPool.DATABASE_URL) + .displayName("Snowflake URL") + .description("Example connection string: jdbc:snowflake://[account].[region].snowflakecomputing.com/?[connection_params]" + + " The connection parameters can include db=DATABASE_NAME to avoid using qualified table names such as DATABASE_NAME.PUBLIC.TABLE_NAME") + .build(); + + public static final PropertyDescriptor SNOWFLAKE_USER = new PropertyDescriptor.Builder() + .fromPropertyDescriptor(DBCPConnectionPool.DB_USER) + .displayName("Snowflake User") + .description("The Snowflake user name") + .build(); + + public static final PropertyDescriptor SNOWFLAKE_PASSWORD = new PropertyDescriptor.Builder() + .fromPropertyDescriptor(DBCPConnectionPool.DB_PASSWORD) + .displayName("Snowflake Password") + .description("The password for the Snowflake user") + .build(); + + private static final List<PropertyDescriptor> properties; + + static { + final List<PropertyDescriptor> props = new ArrayList<>(); + props.add(SNOWFLAKE_URL); + props.add(SNOWFLAKE_USER); + props.add(SNOWFLAKE_PASSWORD); + props.add(VALIDATION_QUERY); + props.add(MAX_WAIT_TIME); + props.add(MAX_TOTAL_CONNECTIONS); + props.add(MIN_IDLE); + props.add(MAX_IDLE); + props.add(MAX_CONN_LIFETIME); + props.add(EVICTION_RUN_PERIOD); + props.add(MIN_EVICTABLE_IDLE_TIME); + props.add(SOFT_MIN_EVICTABLE_IDLE_TIME); + + properties = Collections.unmodifiableList(props); + } + + @Override + protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { + return properties; + } + + @Override + protected Collection<ValidationResult> customValidate(final ValidationContext context) { + return Collections.emptyList(); + } + + @Override + protected String getUrl(final ConfigurationContext context) { + String snowflakeUrl = context.getProperty(SNOWFLAKE_URL).evaluateAttributeExpressions().getValue(); + + if (!snowflakeUrl.startsWith("jdbc:snowflake")) { + snowflakeUrl = "jdbc:snowflake://" + snowflakeUrl; + } + + return snowflakeUrl; + } + + @Override + protected Driver getDriver(final String driverName, final String url) { + try { + Class.forName(SnowflakeDriver.class.getName()); + return DriverManager.getDriver(url); + } catch (Exception e) { + throw new ProcessException("Snowflake driver unavailable or incompatible connection URL", e); + } + } +} diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/src/main/resources/META-INF/services/org.apache.nifi.controller.ControllerService b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/src/main/resources/META-INF/services/org.apache.nifi.controller.ControllerService new file mode 100644 index 0000000..0e0a16b --- /dev/null +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/src/main/resources/META-INF/services/org.apache.nifi.controller.ControllerService @@ -0,0 +1,15 @@ +# 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. +org.apache.nifi.snowflake.service.SnowflakeComputingConnectionPool diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/src/test/java/org/apache/nifi/snowflake/service/SnowflakeConnectionPoolIT.java b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/src/test/java/org/apache/nifi/snowflake/service/SnowflakeConnectionPoolIT.java new file mode 100644 index 0000000..7a2dd8c --- /dev/null +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/src/test/java/org/apache/nifi/snowflake/service/SnowflakeConnectionPoolIT.java @@ -0,0 +1,87 @@ +/* + * 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.snowflake.service; + +import org.apache.nifi.processor.AbstractSessionFactoryProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSessionFactory; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; + +/** + * Set the following constants:<p> + * SNOWFLAKE_URL<p> + * SNOWFLAKE_USER<p> + * SNOWFLAKE_PASSWORD<p> + * TABLE_NAME<p> + */ +public class SnowflakeConnectionPoolIT { + public static final String SNOWFLAKE_URL = "account.snowflakecomputing.com"; + public static final String SNOWFLAKE_USER = "???"; + public static final String SNOWFLAKE_PASSWORD = "???"; + public static final String TABLE_NAME = "test_db.public.test_table"; + + private static final String SERVICE_ID = SnowflakeComputingConnectionPool.class.getName(); + + private TestRunner runner; + + private SnowflakeComputingConnectionPool service; + + @BeforeEach + void setUp() throws Exception { + service = new SnowflakeComputingConnectionPool(); + runner = TestRunners.newTestRunner(new AbstractSessionFactoryProcessor() { + @Override + public void onTrigger(ProcessContext context, ProcessSessionFactory sessionFactory) throws ProcessException { + } + }); + runner.addControllerService(SERVICE_ID, service); + + runner.setProperty(service, SnowflakeComputingConnectionPool.SNOWFLAKE_URL, SNOWFLAKE_URL); + runner.setProperty(service, SnowflakeComputingConnectionPool.SNOWFLAKE_USER, SNOWFLAKE_USER); + runner.setProperty(service, SnowflakeComputingConnectionPool.SNOWFLAKE_PASSWORD, SNOWFLAKE_PASSWORD); + runner.setProperty(service, "loginTimeout", "5"); + } + + @Test + void testReadSnowflakeTable() throws Exception { + runner.assertValid(service); + runner.enableControllerService(service); + runner.assertValid(service); + + try ( + final Connection connection = service.getConnection(); + final Statement st = connection.createStatement() + ) { + ResultSet resultSet = st.executeQuery("select * from " + TABLE_NAME); + + int nrOfRows = 0; + while (resultSet.next()) { + nrOfRows++; + } + + System.out.println("Read " + nrOfRows + " records from " + TABLE_NAME); + } + } +} diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/pom.xml b/nifi-nar-bundles/nifi-snowflake-bundle/pom.xml new file mode 100644 index 0000000..8366717 --- /dev/null +++ b/nifi-nar-bundles/nifi-snowflake-bundle/pom.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- 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. --> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-nar-bundles</artifactId> + <version>1.16.0-SNAPSHOT</version> + </parent> + + <artifactId>nifi-snowflake-bundle</artifactId> + <version>1.16.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <modules> + <module>nifi-snowflake-services</module> + <module>nifi-snowflake-services-nar</module> + </modules> +</project> 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 48141a8..cbb3162 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 @@ -81,28 +81,28 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC protected static final String SENSITIVE_PROPERTY_PREFIX = "SENSITIVE."; /** - * Copied from {@link GenericObjectPoolConfig.DEFAULT_MIN_IDLE} in Commons-DBCP 2.7.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.7.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.7.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.7.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.7.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.7.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); @@ -180,7 +180,7 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC .name("Validation-query") .displayName("Validation query") .description("Validation query used to validate connections before returning them. " - + "When connection is invalid, it get's dropped and new valid connection will be returned. " + + "When connection is invalid, it gets dropped and new valid connection will be returned. " + "Note!! Using validation might have some performance penalty.") .required(false) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) @@ -190,8 +190,8 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC public static final PropertyDescriptor MIN_IDLE = new PropertyDescriptor.Builder() .displayName("Minimum Idle Connections") .name("dbcp-min-idle-conns") - .description("The minimum number of connections that can remain idle in the pool, without extra ones being " + - "created, or zero to create none.") + .description("The minimum number of connections that can remain idle in the pool without extra ones being " + + "created. Set to or zero to allow no idle connections.") .defaultValue(DEFAULT_MIN_IDLE) .required(false) .addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR) @@ -201,8 +201,8 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC public static final PropertyDescriptor MAX_IDLE = new PropertyDescriptor.Builder() .displayName("Max Idle Connections") .name("dbcp-max-idle-conns") - .description("The maximum number of connections that can remain idle in the pool, without extra ones being " + - "released, or negative for no limit.") + .description("The maximum number of connections that can remain idle in the pool without extra ones being " + + "released. Set to any negative value to allow unlimited idle connections.") .defaultValue(DEFAULT_MAX_IDLE) .required(false) .addValidator(StandardValidators.INTEGER_VALIDATOR) @@ -319,8 +319,8 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC properties = Collections.unmodifiableList(props); } - private volatile BasicDataSource dataSource; - private volatile KerberosUser kerberosUser; + protected volatile BasicDataSource dataSource; + protected volatile KerberosUser kerberosUser; @Override protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { @@ -414,11 +414,11 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC */ @OnEnabled public void onConfigured(final ConfigurationContext context) throws InitializationException { + final String dburl = getUrl(context); final String driverName = 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 String dburl = context.getProperty(DATABASE_URL).evaluateAttributeExpressions().getValue(); 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).evaluateAttributeExpressions()); @@ -486,7 +486,11 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC }); } - private Driver getDriver(final String driverName, final String url) { + protected String getUrl(ConfigurationContext context) { + return context.getProperty(DATABASE_URL).evaluateAttributeExpressions().getValue(); + } + + protected Driver getDriver(final String driverName, final String url) { final Class<?> clazz; try { @@ -511,7 +515,7 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC } } - private Long extractMillisWithInfinite(PropertyValue prop) { + protected Long extractMillisWithInfinite(PropertyValue prop) { return "-1".equals(prop.getValue()) ? -1 : prop.asTimePeriod(TimeUnit.MILLISECONDS); } @@ -571,7 +575,7 @@ public class DBCPConnectionPool extends AbstractControllerService implements DBC @Override public String toString() { - return "DBCPConnectionPool[id=" + getIdentifier() + "]"; + return this.getClass().getSimpleName() + "[id=" + getIdentifier() + "]"; } BasicDataSource getDataSource() { diff --git a/nifi-nar-bundles/pom.xml b/nifi-nar-bundles/pom.xml index 415cd15..79acbfe 100755 --- a/nifi-nar-bundles/pom.xml +++ b/nifi-nar-bundles/pom.xml @@ -110,6 +110,7 @@ <module>nifi-hashicorp-vault-bundle</module> <module>nifi-stateless-processor-bundle</module> <module>nifi-geohash-bundle</module> + <module>nifi-snowflake-bundle</module> </modules> <build>