This is an automated email from the ASF dual-hosted git repository. exceptionfactory pushed a commit to branch support/nifi-1.x in repository https://gitbox.apache.org/repos/asf/nifi.git
commit a71e1c1c165ac5fc4cbdd38fcbbf52cfdc7a8730 Author: Peter Turcsanyi <[email protected]> AuthorDate: Thu Jun 15 23:12:02 2023 +0200 NIFI-11699 Fixed dynamic properties in SnowflakeComputingConnectionPool Also fixed driver class name handling (caused IT test failure). Other test fixes to make IT tests work. This closes #7387 Signed-off-by: David Handermann <[email protected]> (cherry picked from commit b36570f2cd2992450d6d36a934cda0d206ca7fc1) --- .../processors/snowflake/SnowflakeConfigAware.java | 1 - .../nifi/processors/snowflake/SnowflakePipeIT.java | 4 ++-- .../nifi-snowflake-services/pom.xml | 9 ++++++++ .../service/SnowflakeComputingConnectionPool.java | 27 +++++++++++++++------- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-processors/src/test/java/org/apache/nifi/processors/snowflake/SnowflakeConfigAware.java b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-processors/src/test/java/org/apache/nifi/processors/snowflake/SnowflakeConfigAware.java index ff7c03a684..2e892835dd 100644 --- a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-processors/src/test/java/org/apache/nifi/processors/snowflake/SnowflakeConfigAware.java +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-processors/src/test/java/org/apache/nifi/processors/snowflake/SnowflakeConfigAware.java @@ -31,7 +31,6 @@ import org.apache.nifi.util.TestRunner; public interface SnowflakeConfigAware { Path filePath = Paths.get("???"); - String stagedFilePath = "???"; String organizationName = "???"; String accountName = "???"; diff --git a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-processors/src/test/java/org/apache/nifi/processors/snowflake/SnowflakePipeIT.java b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-processors/src/test/java/org/apache/nifi/processors/snowflake/SnowflakePipeIT.java index d895e73f72..225e46fa3f 100644 --- a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-processors/src/test/java/org/apache/nifi/processors/snowflake/SnowflakePipeIT.java +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-processors/src/test/java/org/apache/nifi/processors/snowflake/SnowflakePipeIT.java @@ -85,7 +85,7 @@ class SnowflakePipeIT implements SnowflakeConfigAware { false); } - final Map<String, String> attributes = Collections.singletonMap(SnowflakeAttributes.ATTRIBUTE_STAGED_FILE_PATH, uuid + "/" + stagedFilePath); + final Map<String, String> attributes = Collections.singletonMap(SnowflakeAttributes.ATTRIBUTE_STAGED_FILE_PATH, uuid + "/" + fileName); runner.enqueue("", attributes); runner.run(); @@ -114,7 +114,7 @@ class SnowflakePipeIT implements SnowflakeConfigAware { false); } - final String stagedFilePathAttribute = uuid + "/" + stagedFilePath; + final String stagedFilePathAttribute = uuid + "/" + fileName; final StagedFileWrapper stagedFile = new StagedFileWrapper(stagedFilePathAttribute); ingestManagerProviderService.getIngestManager().ingestFile(stagedFile, null); 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 index 06bdf595b1..f3a4d2f129 100644 --- a/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/pom.xml +++ b/nifi-nar-bundles/nifi-snowflake-bundle/nifi-snowflake-services/pom.xml @@ -81,5 +81,14 @@ <version>1.23.0-SNAPSHOT</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-kerberos-user-service-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + </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 index 492d14340f..139e7fb13d 100644 --- 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 @@ -21,6 +21,7 @@ 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.behavior.SupportsSensitiveDynamicProperties; import org.apache.nifi.annotation.documentation.CapabilityDescription; import org.apache.nifi.annotation.documentation.Tags; import org.apache.nifi.components.PropertyDescriptor; @@ -30,6 +31,7 @@ import org.apache.nifi.controller.ConfigurationContext; import org.apache.nifi.dbcp.AbstractDBCPConnectionPool; import org.apache.nifi.dbcp.utils.DBCPProperties; import org.apache.nifi.dbcp.utils.DataSourceConfiguration; +import org.apache.nifi.expression.AttributeExpression; import org.apache.nifi.expression.ExpressionLanguageScope; import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.processor.util.StandardValidators; @@ -49,7 +51,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import static org.apache.nifi.dbcp.utils.DBCPProperties.DB_DRIVERNAME; import static org.apache.nifi.dbcp.utils.DBCPProperties.DB_PASSWORD; import static org.apache.nifi.dbcp.utils.DBCPProperties.DB_USER; import static org.apache.nifi.dbcp.utils.DBCPProperties.EVICTION_RUN_PERIOD; @@ -69,15 +70,12 @@ import static org.apache.nifi.dbcp.utils.DBCPProperties.extractMillisWithInfinit */ @Tags({"snowflake", "dbcp", "jdbc", "database", "connection", "pooling", "store"}) @CapabilityDescription("Provides Snowflake Connection Pooling Service. Connections can be asked from pool and returned after usage.") +@SupportsSensitiveDynamicProperties @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.") + description = "Snowflake JDBC driver property name and value applied to JDBC connections.") }) @RequiresInstanceClassLoading public class SnowflakeComputingConnectionPool extends AbstractDBCPConnectionPool implements SnowflakeConnectionProviderService { @@ -180,6 +178,19 @@ public class SnowflakeComputingConnectionPool extends AbstractDBCPConnectionPool return PROPERTIES; } + @Override + protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) { + final PropertyDescriptor.Builder builder = new PropertyDescriptor.Builder() + .name(propertyDescriptorName) + .required(false) + .dynamic(true) + .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY) + .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING, true)) + .addValidator(StandardValidators.ATTRIBUTE_KEY_PROPERTY_NAME_VALIDATOR); + + return builder.build(); + } + @Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { return Collections.emptyList(); @@ -188,7 +199,7 @@ public class SnowflakeComputingConnectionPool extends AbstractDBCPConnectionPool @Override protected DataSourceConfiguration getDataSourceConfiguration(final ConfigurationContext context) { final String url = getUrl(context); - final String driverName = context.getProperty(DB_DRIVERNAME).evaluateAttributeExpressions().getValue(); + final String driverName = SnowflakeDriver.class.getName(); final String user = context.getProperty(DB_USER).evaluateAttributeExpressions().getValue(); final String password = context.getProperty(DB_PASSWORD).evaluateAttributeExpressions().getValue(); final Integer maxTotal = context.getProperty(MAX_TOTAL_CONNECTIONS).evaluateAttributeExpressions().asInteger(); @@ -225,7 +236,7 @@ public class SnowflakeComputingConnectionPool extends AbstractDBCPConnectionPool @Override protected Driver getDriver(final String driverName, final String url) { try { - Class.forName(SnowflakeDriver.class.getName()); + Class.forName(driverName); return DriverManager.getDriver(url); } catch (Exception e) { throw new ProcessException("Snowflake driver unavailable or incompatible connection URL", e);
