diff --git a/legend-engine-config/legend-engine-server/src/main/java/org/finos/legend/engine/server/Server.java b/legend-engine-config/legend-engine-server/src/main/java/org/finos/legend/engine/server/Server.java index 3258a9883b1..ad248e0062b 100644 --- a/legend-engine-config/legend-engine-server/src/main/java/org/finos/legend/engine/server/Server.java +++ b/legend-engine-config/legend-engine-server/src/main/java/org/finos/legend/engine/server/Server.java @@ -45,17 +45,18 @@ import org.finos.legend.connection.AuthenticationMechanismConfiguration; import org.finos.legend.connection.ConnectionFactory; import org.finos.legend.connection.DatabaseType; -import org.finos.legend.connection.impl.DefaultStoreInstanceProvider; import org.finos.legend.connection.LegendEnvironment; import org.finos.legend.connection.RelationalDatabaseStoreSupport; import org.finos.legend.connection.StoreInstanceProvider; +import org.finos.legend.connection.impl.DefaultStoreInstanceProvider; import org.finos.legend.connection.impl.EncryptedPrivateKeyPairAuthenticationConfiguration; +import org.finos.legend.connection.impl.HACKY__SnowflakeConnectionAdapter; import org.finos.legend.connection.impl.KerberosCredentialExtractor; import org.finos.legend.connection.impl.KeyPairCredentialBuilder; import org.finos.legend.connection.impl.SnowflakeConnectionBuilder; +import org.finos.legend.connection.impl.StaticJDBCConnectionBuilder; import org.finos.legend.connection.impl.UserPasswordAuthenticationConfiguration; import org.finos.legend.connection.impl.UserPasswordCredentialBuilder; -import org.finos.legend.connection.impl.StaticJDBCConnectionBuilder; import org.finos.legend.connection.protocol.AuthenticationMechanismType; import org.finos.legend.engine.api.analytics.DataSpaceAnalytics; import org.finos.legend.engine.api.analytics.DiagramAnalytics; @@ -279,6 +280,9 @@ public void run(T serverConfiguration, Environment environment) relationalExecution.setFlowProviderConfiguration(new LegendDefaultDatabaseAuthenticationFlowProviderConfiguration()); } relationalExecution.setConnectionFactory(this.setupConnectionFactory(serverConfiguration.vaults)); + relationalExecution.setRelationalDatabaseConnectionAdapters(Lists.mutable.of( + new HACKY__SnowflakeConnectionAdapter.WithKeyPair() + )); relationalStoreExecutor = (RelationalStoreExecutor) Relational.build(serverConfiguration.relationalexecution); diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/HACKY__RelationalDatabaseConnectionAdapter.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/HACKY__RelationalDatabaseConnectionAdapter.java index 00d5d8d45c9..172bdd2a8d2 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/HACKY__RelationalDatabaseConnectionAdapter.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/HACKY__RelationalDatabaseConnectionAdapter.java @@ -16,6 +16,7 @@ import org.finos.legend.connection.protocol.AuthenticationConfiguration; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection; +import org.finos.legend.engine.shared.core.identity.Identity; /** * NOTE: this is hacky way of us to realize the relational database connection that we can support @@ -24,7 +25,7 @@ */ public interface HACKY__RelationalDatabaseConnectionAdapter { - ConnectionFactoryMaterial adapt(RelationalDatabaseConnection relationalDatabaseConnection, LegendEnvironment environment); + ConnectionFactoryMaterial adapt(RelationalDatabaseConnection relationalDatabaseConnection, Identity identity, LegendEnvironment environment); class ConnectionFactoryMaterial { diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-connection/src/main/java/org/finos/legend/connection/impl/HACKY__SnowflakeConnectionAdapter.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-connection/src/main/java/org/finos/legend/connection/impl/HACKY__SnowflakeConnectionAdapter.java index 1f9eb579cce..32c89b91622 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-connection/src/main/java/org/finos/legend/connection/impl/HACKY__SnowflakeConnectionAdapter.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-connection/src/main/java/org/finos/legend/connection/impl/HACKY__SnowflakeConnectionAdapter.java @@ -23,13 +23,14 @@ import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.SnowflakePublicAuthenticationStrategy; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.SnowflakeDatasourceSpecification; +import org.finos.legend.engine.shared.core.identity.Identity; public class HACKY__SnowflakeConnectionAdapter { public static class WithKeyPair implements HACKY__RelationalDatabaseConnectionAdapter { @Override - public ConnectionFactoryMaterial adapt(RelationalDatabaseConnection relationalDatabaseConnection, LegendEnvironment environment) + public ConnectionFactoryMaterial adapt(RelationalDatabaseConnection relationalDatabaseConnection, Identity identity, LegendEnvironment environment) { if ( DatabaseType.Snowflake.equals(relationalDatabaseConnection.databaseType) && diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/RelationalExecutor.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/RelationalExecutor.java index b3b3b51c387..f4573c59dfd 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/RelationalExecutor.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/RelationalExecutor.java @@ -107,7 +107,7 @@ public RelationalExecutor(TemporaryTestDbConfiguration temporarytestdb, Relation public RelationalExecutor(TemporaryTestDbConfiguration temporarytestdb, RelationalExecutionConfiguration relationalExecutionConfiguration, Optional flowProviderHolder) { this.flowProviderHolder = flowProviderHolder; - this.connectionManager = new ConnectionManagerSelector(temporarytestdb, relationalExecutionConfiguration.oauthProfiles, flowProviderHolder, relationalExecutionConfiguration.getConnectionFactory()); + this.connectionManager = new ConnectionManagerSelector(temporarytestdb, relationalExecutionConfiguration.oauthProfiles, flowProviderHolder, relationalExecutionConfiguration.getConnectionFactory(), relationalExecutionConfiguration.getRelationalDatabaseConnectionAdapters(), false); this.relationalExecutionConfiguration = relationalExecutionConfiguration; this.resultInterpreterExtensions = Iterate.addAllTo(ResultInterpreterExtensionLoader.extensions(), Lists.mutable.empty()).collect(ResultInterpreterExtension::additionalResultBuilder); } diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/config/RelationalExecutionConfiguration.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/config/RelationalExecutionConfiguration.java index b0a9e4ba139..b22846a8447 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/config/RelationalExecutionConfiguration.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/config/RelationalExecutionConfiguration.java @@ -18,6 +18,7 @@ import org.eclipse.collections.api.factory.Lists; import org.finos.legend.authentication.credentialprovider.CredentialProviderProvider; import org.finos.legend.connection.ConnectionFactory; +import org.finos.legend.connection.HACKY__RelationalDatabaseConnectionAdapter; import org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider; import org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProviderConfiguration; import org.finos.legend.engine.plan.execution.stores.StoreExecutorConfiguration; @@ -37,6 +38,7 @@ public class RelationalExecutionConfiguration implements StoreExecutorConfigurat @JsonProperty private RelationalGraphFetchExecutionConfig relationalGraphFetchExecutionConfig; private ConnectionFactory connectionFactory; + private List relationalDatabaseConnectionAdapters = Lists.mutable.empty(); @Override public StoreType getStoreType() @@ -78,6 +80,11 @@ public ConnectionFactory getConnectionFactory() return connectionFactory; } + public List getRelationalDatabaseConnectionAdapters() + { + return relationalDatabaseConnectionAdapters; + } + public void setCredentialProviderProvider(CredentialProviderProvider credentialProviderProvider) { this.credentialProviderProvider = credentialProviderProvider; @@ -98,6 +105,11 @@ public void setConnectionFactory(ConnectionFactory connectionFactory) this.connectionFactory = connectionFactory; } + public void setRelationalDatabaseConnectionAdapters(List adapters) + { + this.relationalDatabaseConnectionAdapters = adapters; + } + public static Builder newInstance() { return new Builder(); @@ -118,6 +130,7 @@ public static class Builder private CredentialProviderProvider credentialProviderProvider; private RelationalGraphFetchExecutionConfig relationalGraphFetchExecutionConfig; private ConnectionFactory connectionFactory; + private final List relationalDatabaseConnectionAdapters = Lists.mutable.empty(); public Builder withTempPath(String tempPath) { @@ -170,6 +183,12 @@ public Builder withConnectionFactory(ConnectionFactory connectionFactory) return this; } + public Builder withRelationalDatabaseConnectionAdapters(List adapters) + { + this.relationalDatabaseConnectionAdapters.addAll(adapters); + return this; + } + public RelationalExecutionConfiguration build() { RelationalExecutionConfiguration relationalExecutionConfiguration = new RelationalExecutionConfiguration(); @@ -181,6 +200,7 @@ public RelationalExecutionConfiguration build() relationalExecutionConfiguration.credentialProviderProvider = credentialProviderProvider; relationalExecutionConfiguration.relationalGraphFetchExecutionConfig = relationalGraphFetchExecutionConfig; relationalExecutionConfiguration.connectionFactory = connectionFactory; + relationalExecutionConfiguration.relationalDatabaseConnectionAdapters = relationalDatabaseConnectionAdapters; return relationalExecutionConfiguration; } } diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/connection/manager/ConnectionManagerSelector.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/connection/manager/ConnectionManagerSelector.java index ef315ff53aa..c8a4be55180 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/connection/manager/ConnectionManagerSelector.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-execution/legend-engine-xt-relationalStore-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/relational/connection/manager/ConnectionManagerSelector.java @@ -68,18 +68,7 @@ public ConnectionManagerSelector(TemporaryTestDbConfiguration temporaryTestDb, L this.connectionFactory = null; } - public ConnectionManagerSelector(TemporaryTestDbConfiguration temporaryTestDb, List oauthProfiles, Optional flowProviderHolder, ConnectionFactory connectionFactory) - { - MutableList extensions = Iterate.addAllTo(ServiceLoader.load(ConnectionManagerExtension.class), Lists.mutable.empty()); - this.connectionManagers = Lists.mutable.with( - new RelationalConnectionManager(temporaryTestDb.port, oauthProfiles, flowProviderHolder) - ).withAll(extensions.collect(e -> e.getExtensionManager(temporaryTestDb.port, oauthProfiles))); - this.flowProviderHolder = flowProviderHolder; - this.connectionFactory = connectionFactory; - this.relationalDatabaseConnectionAdapters.addAll(Lists.mutable.withAll(ServiceLoader.load(HACKY__RelationalDatabaseConnectionAdapter.class))); - } - - public ConnectionManagerSelector(TemporaryTestDbConfiguration temporaryTestDb, List oauthProfiles, Optional flowProviderHolder, ConnectionFactory connectionFactory, List relationalDatabaseConnectionAdapters) + public ConnectionManagerSelector(TemporaryTestDbConfiguration temporaryTestDb, List oauthProfiles, Optional flowProviderHolder, ConnectionFactory connectionFactory, List relationalDatabaseConnectionAdapters, boolean enableNewConnectionFrameworkByDefault) { MutableList extensions = Iterate.addAllTo(ServiceLoader.load(ConnectionManagerExtension.class), Lists.mutable.empty()); this.connectionManagers = Lists.mutable.with( @@ -89,7 +78,7 @@ public ConnectionManagerSelector(TemporaryTestDbConfiguration temporaryTestDb, L this.connectionFactory = connectionFactory; this.relationalDatabaseConnectionAdapters.addAll(relationalDatabaseConnectionAdapters); - this.enableNewConnectionFramework = true; + this.enableNewConnectionFramework = enableNewConnectionFrameworkByDefault; } public Optional getFlowProviderHolder() @@ -155,7 +144,7 @@ public Connection getDatabaseConnectionImpl(Identity identity, DatabaseConnectio HACKY__RelationalDatabaseConnectionAdapter.ConnectionFactoryMaterial connectionFactoryMaterial = null; for (HACKY__RelationalDatabaseConnectionAdapter adapter : this.relationalDatabaseConnectionAdapters) { - connectionFactoryMaterial = adapter.adapt(relationalDatabaseConnection, this.connectionFactory.getEnvironment()); + connectionFactoryMaterial = adapter.adapt(relationalDatabaseConnection, identity, this.connectionFactory.getEnvironment()); if (connectionFactoryMaterial != null) { break;