diff --git a/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/AbstractConnectionFactoryTest.java b/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/AbstractConnectionFactoryTest.java index 47ebcbf93f8..27b8e42a8c6 100644 --- a/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/AbstractConnectionFactoryTest.java +++ b/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/AbstractConnectionFactoryTest.java @@ -22,11 +22,11 @@ import org.finos.legend.connection.Connection; import org.finos.legend.connection.ConnectionFactory; import org.finos.legend.connection.DatabaseSupport; +import org.finos.legend.connection.DatabaseType; import org.finos.legend.connection.IdentityFactory; import org.finos.legend.connection.IdentitySpecification; import org.finos.legend.connection.LegendEnvironment; import org.finos.legend.connection.impl.CoreAuthenticationMechanismType; -import org.finos.legend.connection.impl.InstrumentedConnectionProvider; import org.finos.legend.connection.impl.KerberosCredentialExtractor; import org.finos.legend.connection.impl.KeyPairCredentialBuilder; import org.finos.legend.connection.impl.RelationalDatabaseType; @@ -34,6 +34,7 @@ import org.finos.legend.connection.impl.StaticJDBCConnectionBuilder; import org.finos.legend.connection.impl.UserPasswordCredentialBuilder; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.AuthenticationConfiguration; +import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.ConnectionSpecification; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.EncryptedPrivateKeyPairAuthenticationConfiguration; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.UserPasswordAuthenticationConfiguration; import org.finos.legend.engine.shared.core.identity.Identity; @@ -43,11 +44,8 @@ public abstract class AbstractConnectionFactoryTest { - protected static final String TEST_CONNECTION_IDENTIFIER = "test::connection"; - protected LegendEnvironment environment; protected IdentityFactory identityFactory; - protected InstrumentedConnectionProvider connectionProvider; protected ConnectionFactory connectionFactory; @BeforeEach @@ -95,10 +93,8 @@ public void initialize() .environment(this.environment) .build(); - this.connectionProvider = new InstrumentedConnectionProvider(); this.connectionFactory = ConnectionFactory.builder() .environment(this.environment) - .connectionProvider(this.connectionProvider) .credentialBuilders( new KerberosCredentialExtractor(), new UserPasswordCredentialBuilder(), @@ -126,10 +122,12 @@ public CredentialVault getCredentialVault() return null; } - public abstract Connection getConnection(AuthenticationConfiguration authenticationConfiguration); - public abstract Identity getIdentity(); + public abstract DatabaseType getDatabaseType(); + + public abstract ConnectionSpecification getConnectionSpecification(); + public abstract AuthenticationConfiguration getAuthenticationConfiguration(); public abstract void runTestWithConnection(T connection) throws Exception; @@ -138,10 +136,18 @@ public CredentialVault getCredentialVault() public void runTest() throws Exception { Identity identity = this.getIdentity(); + DatabaseType databaseType = this.getDatabaseType(); + ConnectionSpecification connectionSpecification = this.getConnectionSpecification(); AuthenticationConfiguration authenticationConfiguration = this.getAuthenticationConfiguration(); - this.connectionProvider.injectConnection(this.getConnection(authenticationConfiguration)); - Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, TEST_CONNECTION_IDENTIFIER); + Connection databaseConnection = Connection.builder() + .databaseSupport(this.environment.getDatabaseSupport(databaseType)) + .identifier("test::connection") + .connectionSpecification(connectionSpecification) + .authenticationConfiguration(authenticationConfiguration) + .build(); + + Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, databaseConnection); T connection = this.connectionFactory.getConnection(identity, authenticator); this.runTestWithConnection(connection); diff --git a/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestJDBCConnectionManager.java b/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestJDBCConnectionManager.java index 89f933edefa..dc08b4dc741 100644 --- a/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestJDBCConnectionManager.java +++ b/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestJDBCConnectionManager.java @@ -23,11 +23,10 @@ import org.finos.legend.connection.DatabaseSupport; import org.finos.legend.connection.IdentityFactory; import org.finos.legend.connection.IdentitySpecification; -import org.finos.legend.connection.JDBCConnectionBuilder; import org.finos.legend.connection.LegendEnvironment; import org.finos.legend.connection.PostgresTestContainerWrapper; import org.finos.legend.connection.impl.CoreAuthenticationMechanismType; -import org.finos.legend.connection.impl.InstrumentedConnectionProvider; +import org.finos.legend.connection.impl.JDBCConnectionBuilder; import org.finos.legend.connection.impl.JDBCConnectionManager; import org.finos.legend.connection.impl.RelationalDatabaseType; import org.finos.legend.connection.impl.StaticJDBCConnectionBuilder; @@ -49,11 +48,9 @@ public class TestJDBCConnectionManager { PostgresTestContainerWrapper postgresContainer; - private static final String TEST_CONNECTION_IDENTIFIER = "test::connection"; private LegendEnvironment environment; private IdentityFactory identityFactory; - private InstrumentedConnectionProvider connectionProvider; private ConnectionFactory connectionFactory; private Connection connection; @@ -84,7 +81,6 @@ public void setup() this.identityFactory = IdentityFactory.builder() .environment(this.environment) .build(); - this.connectionProvider = new InstrumentedConnectionProvider(); ConnectionSpecification connectionSpecification = new StaticJDBCConnectionSpecification( this.postgresContainer.getHost(), this.postgresContainer.getPort(), @@ -92,7 +88,7 @@ public void setup() ); this.connection = Connection.builder() .databaseSupport(this.environment.getDatabaseSupport(RelationalDatabaseType.POSTGRES)) - .identifier(TEST_CONNECTION_IDENTIFIER) + .identifier("test::connection") .connectionSpecification(connectionSpecification) .authenticationConfiguration(new UserPasswordAuthenticationConfiguration( postgresContainer.getUser(), @@ -121,7 +117,6 @@ public void testBasicConnectionPooling() throws Exception ); this.connectionFactory = ConnectionFactory.builder() .environment(this.environment) - .connectionProvider(this.connectionProvider) .credentialBuilders( new UserPasswordCredentialBuilder() ) @@ -129,7 +124,6 @@ public void testBasicConnectionPooling() throws Exception customizedJDBCConnectionBuilder ) .build(); - this.connectionProvider.injectConnection(this.connection); Identity identity = identityFactory.createIdentity( IdentitySpecification.builder() .name("test-user") @@ -138,7 +132,7 @@ public void testBasicConnectionPooling() throws Exception ConnectionSpecification connectionSpecification = this.connection.getConnectionSpecification(); AuthenticationConfiguration authenticationConfiguration = this.connection.getAuthenticationConfiguration(); - Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, TEST_CONNECTION_IDENTIFIER); + Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, this.connection); JDBCConnectionManager connectionManager = JDBCConnectionManager.getInstance(); Assertions.assertEquals(0, connectionManager.getPoolSize()); @@ -187,7 +181,6 @@ public void testConnectionPoolingForDifferentIdentities() throws Exception { this.connectionFactory = ConnectionFactory.builder() .environment(this.environment) - .connectionProvider(this.connectionProvider) .credentialBuilders( new UserPasswordCredentialBuilder() ) @@ -195,7 +188,6 @@ public void testConnectionPoolingForDifferentIdentities() throws Exception new StaticJDBCConnectionBuilder.WithPlaintextUsernamePassword() ) .build(); - this.connectionProvider.injectConnection(this.connection); Identity identity1 = identityFactory.createIdentity( IdentitySpecification.builder() .name("testUser1") @@ -213,7 +205,7 @@ public void testConnectionPoolingForDifferentIdentities() throws Exception Assertions.assertEquals(0, connectionManager.getPoolSize()); // 1. Get a new connection for identity1, which should initialize a pool - this.connectionFactory.getConnection(identity1, this.connectionFactory.getAuthenticator(identity1, TEST_CONNECTION_IDENTIFIER)); + this.connectionFactory.getConnection(identity1, this.connectionFactory.getAuthenticator(identity1, this.connection)); String poolName1 = JDBCConnectionManager.getPoolName(identity1, connectionSpecification, authenticationConfiguration); JDBCConnectionManager.ConnectionPool connectionPool1 = connectionManager.getPool(poolName1); @@ -224,7 +216,7 @@ public void testConnectionPoolingForDifferentIdentities() throws Exception Assertions.assertEquals(0, connectionPool1.getIdleConnections()); // 2. Get a new connection for identity2, which should initialize another pool - this.connectionFactory.getConnection(identity2, this.connectionFactory.getAuthenticator(identity2, TEST_CONNECTION_IDENTIFIER)); + this.connectionFactory.getConnection(identity2, this.connectionFactory.getAuthenticator(identity2, this.connection)); String poolName2 = JDBCConnectionManager.getPoolName(identity2, connectionSpecification, authenticationConfiguration); JDBCConnectionManager.ConnectionPool connectionPool2 = connectionManager.getPool(poolName2); diff --git a/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestPostgresConnection.java b/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestPostgresConnection.java index b2a7c610592..6c9addedd6b 100644 --- a/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestPostgresConnection.java +++ b/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestPostgresConnection.java @@ -16,16 +16,14 @@ import org.finos.legend.authentication.vault.CredentialVault; import org.finos.legend.authentication.vault.impl.PropertiesFileCredentialVault; -import org.finos.legend.connection.AuthenticationMechanism; -import org.finos.legend.connection.impl.CoreAuthenticationMechanismType; +import org.finos.legend.connection.DatabaseType; import org.finos.legend.connection.PostgresTestContainerWrapper; -import org.finos.legend.connection.Connection; import org.finos.legend.connection.impl.RelationalDatabaseType; import org.finos.legend.engine.protocol.pure.v1.model.connection.StaticJDBCConnectionSpecification; +import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.authentication.vault.PropertiesFileSecret; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.AuthenticationConfiguration; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.ConnectionSpecification; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.UserPasswordAuthenticationConfiguration; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.authentication.vault.PropertiesFileSecret; import org.finos.legend.engine.shared.core.identity.Identity; import java.sql.Statement; @@ -71,29 +69,25 @@ public CredentialVault getCredentialVault() } @Override - public Connection getConnection(AuthenticationConfiguration authenticationConfiguration) + public Identity getIdentity() { - ConnectionSpecification connectionSpecification = new StaticJDBCConnectionSpecification( - this.postgresContainer.getHost(), - this.postgresContainer.getPort(), - this.postgresContainer.getDatabaseName() - ); - return Connection.builder() - .databaseSupport(this.environment.getDatabaseSupport(RelationalDatabaseType.POSTGRES)) - .identifier(TEST_CONNECTION_IDENTIFIER) - .authenticationMechanisms( - AuthenticationMechanism.builder() - .type(CoreAuthenticationMechanismType.USER_PASSWORD).build() - ) - .connectionSpecification(connectionSpecification) - .authenticationConfiguration(authenticationConfiguration) - .build(); + return getAnonymousIdentity(this.identityFactory); } @Override - public Identity getIdentity() + public DatabaseType getDatabaseType() { - return getAnonymousIdentity(this.identityFactory); + return RelationalDatabaseType.POSTGRES; + } + + @Override + public ConnectionSpecification getConnectionSpecification() + { + return new StaticJDBCConnectionSpecification( + this.postgresContainer.getHost(), + this.postgresContainer.getPort(), + this.postgresContainer.getDatabaseName() + ); } @Override diff --git a/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestSnowflakeConnection.java b/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestSnowflakeConnection.java index 6983b7b1b3a..1cd48d31390 100644 --- a/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestSnowflakeConnection.java +++ b/legend-engine-config/legend-engine-connection-integration-tests/src/test/java/org/finos/legend/engine/connection/test/TestSnowflakeConnection.java @@ -16,14 +16,13 @@ import org.finos.legend.authentication.vault.CredentialVault; import org.finos.legend.authentication.vault.impl.PropertiesFileCredentialVault; -import org.finos.legend.connection.AuthenticationMechanism; -import org.finos.legend.connection.Connection; -import org.finos.legend.connection.impl.CoreAuthenticationMechanismType; +import org.finos.legend.connection.DatabaseType; import org.finos.legend.connection.impl.RelationalDatabaseType; import org.finos.legend.engine.protocol.pure.v1.connection.SnowflakeConnectionSpecification; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.authentication.vault.EnvironmentCredentialVaultSecret; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.authentication.vault.PropertiesFileSecret; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.AuthenticationConfiguration; +import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.ConnectionSpecification; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.EncryptedPrivateKeyPairAuthenticationConfiguration; import org.finos.legend.engine.shared.core.identity.Identity; @@ -71,7 +70,19 @@ public CredentialVault getCredentialVault() } @Override - public Connection getConnection(AuthenticationConfiguration authenticationConfiguration) + public Identity getIdentity() + { + return getAnonymousIdentity(this.identityFactory); + } + + @Override + public DatabaseType getDatabaseType() + { + return RelationalDatabaseType.SNOWFLAKE; + } + + @Override + public ConnectionSpecification getConnectionSpecification() { SnowflakeConnectionSpecification connectionSpecification = new SnowflakeConnectionSpecification(); connectionSpecification.databaseName = "SUMMIT_DEV"; @@ -80,23 +91,7 @@ public Connection getConnection(AuthenticationConfiguration authenticationConfig connectionSpecification.region = "us-east-2"; connectionSpecification.cloudType = "aws"; connectionSpecification.role = "SUMMIT_DEV"; - return Connection.builder() - .databaseSupport(this.environment.getDatabaseSupport(RelationalDatabaseType.SNOWFLAKE)) - .identifier(TEST_CONNECTION_IDENTIFIER) - .authenticationMechanisms( - AuthenticationMechanism.builder() - .type(CoreAuthenticationMechanismType.KEY_PAIR) - .build() - ) - .connectionSpecification(connectionSpecification) - .authenticationConfiguration(authenticationConfiguration) - .build(); - } - - @Override - public Identity getIdentity() - { - return getAnonymousIdentity(this.identityFactory); + return connectionSpecification; } @Override 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 e979bf5dcdb..035ec9fd3e1 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,11 +45,9 @@ import org.finos.legend.authentication.vault.impl.SystemPropertiesCredentialVault; import org.finos.legend.connection.AuthenticationMechanism; import org.finos.legend.connection.ConnectionFactory; -import org.finos.legend.connection.ConnectionProvider; import org.finos.legend.connection.DatabaseSupport; import org.finos.legend.connection.LegendEnvironment; import org.finos.legend.connection.impl.CoreAuthenticationMechanismType; -import org.finos.legend.connection.impl.DefaultConnectionProvider; import org.finos.legend.connection.impl.HACKY__SnowflakeConnectionAdapter; import org.finos.legend.connection.impl.KerberosCredentialExtractor; import org.finos.legend.connection.impl.KeyPairCredentialBuilder; @@ -473,10 +471,8 @@ private ConnectionFactory setupConnectionFactory(List vaultC .build() ).build(); - ConnectionProvider connectionProvider = DefaultConnectionProvider.builder().build(); return ConnectionFactory.builder() .environment(environment) - .connectionProvider(connectionProvider) .credentialBuilders( new KerberosCredentialExtractor(), new UserPasswordCredentialBuilder(), diff --git a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/Connection.java b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/Connection.java index 3af71daec3f..a352b763636 100644 --- a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/Connection.java +++ b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/Connection.java @@ -252,7 +252,8 @@ public Builder fromProtocol(org.finos.legend.engine.protocol.pure.v1.packageable .build()) : Lists.mutable.empty() ) - .connectionSpecification(protocol.connectionSpecification); + .connectionSpecification(protocol.connectionSpecification) + .authenticationConfiguration(protocol.authenticationConfiguration); } diff --git a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionExtension.java b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionExtension.java index 62c8b0e1447..58fb2362ee1 100644 --- a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionExtension.java +++ b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionExtension.java @@ -14,11 +14,18 @@ package org.finos.legend.connection; +import java.util.Collections; import java.util.List; public interface ConnectionExtension { - List getExtraDatabaseTypes(); + default List getExtraDatabaseTypes() + { + return Collections.emptyList(); + } - List getExtraAuthenticationMechanismTypes(); + default List getExtraAuthenticationMechanismTypes() + { + return Collections.emptyList(); + } } diff --git a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionFactory.java b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionFactory.java index 346b89dd132..aedb2732661 100644 --- a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionFactory.java +++ b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionFactory.java @@ -36,14 +36,12 @@ public class ConnectionFactory { private final LegendEnvironment environment; - private final ConnectionProvider connectionProvider; private final Map credentialBuildersIndex = new LinkedHashMap<>(); private final Map connectionBuildersIndex = new LinkedHashMap<>(); - private ConnectionFactory(LegendEnvironment environment, ConnectionProvider connectionProvider, List credentialBuilders, List connectionBuilders) + private ConnectionFactory(LegendEnvironment environment, List credentialBuilders, List connectionBuilders) { this.environment = Objects.requireNonNull(environment, "environment is missing"); - this.connectionProvider = Objects.requireNonNull(connectionProvider, "connection provider is missing"); for (ConnectionBuilder builder : connectionBuilders) { this.connectionBuildersIndex.put(new ConnectionBuilder.Key(builder.getConnectionSpecificationType(), builder.getCredentialType()), builder); @@ -59,11 +57,6 @@ public LegendEnvironment getEnvironment() return environment; } - public Authenticator getAuthenticator(Identity identity, String connectionIdentifier, AuthenticationConfiguration authenticationConfiguration) - { - return this.getAuthenticator(identity, this.connectionProvider.lookup(connectionIdentifier), authenticationConfiguration); - } - public Authenticator getAuthenticator(Identity identity, Connection connection, AuthenticationConfiguration authenticationConfiguration) { AuthenticationMechanismType authenticationMechanismType = Objects.requireNonNull(connection.getAuthenticationMechanism(authenticationConfiguration.getClass()), String.format("Connection '%s' is not compatible with authentication configuration type '%s'. Supported configuration type(s):\n%s", @@ -88,11 +81,6 @@ private Authenticator getAuthenticator(Identity identity, Connection connection, return new Authenticator(connection, authenticationMechanismType, authenticationConfiguration, result.sourceCredentialType, result.targetCredentialType, result.flow, connectionBuildersIndex.get(new ConnectionBuilder.Key(connection.getConnectionSpecification().getClass(), result.targetCredentialType)), this.environment); } - public Authenticator getAuthenticator(Identity identity, String connectionIdentifier) - { - return this.getAuthenticator(identity, this.connectionProvider.lookup(connectionIdentifier)); - } - public Authenticator getAuthenticator(Identity identity, Connection connection) { Authenticator authenticator = null; @@ -351,21 +339,11 @@ public T getConnection(Identity identity, Connection connection, Authenticat return this.getConnection(identity, this.getAuthenticator(identity, connection, authenticationConfiguration)); } - public T getConnection(Identity identity, String connectionIdentifier, AuthenticationConfiguration authenticationConfiguration) throws Exception - { - return this.getConnection(identity, this.getAuthenticator(identity, connectionIdentifier, authenticationConfiguration)); - } - public T getConnection(Identity identity, Connection connection) throws Exception { return this.getConnection(identity, this.getAuthenticator(identity, connection)); } - public T getConnection(Identity identity, String connectionIdentifier) throws Exception - { - return this.getConnection(identity, this.getAuthenticator(identity, connectionIdentifier)); - } - public T getConnection(Identity identity, Authenticator authenticator) throws Exception { ConnectionBuilder flow = (ConnectionBuilder) authenticator.getConnectionBuilder(); @@ -380,7 +358,6 @@ public static Builder builder() public static class Builder { private LegendEnvironment environment; - private ConnectionProvider connectionProvider; private final List credentialBuilders = Lists.mutable.empty(); private final List connectionBuilders = Lists.mutable.empty(); @@ -394,12 +371,6 @@ public Builder environment(LegendEnvironment environment) return this; } - public Builder connectionProvider(ConnectionProvider connectionProvider) - { - this.connectionProvider = connectionProvider; - return this; - } - public Builder credentialBuilders(List credentialBuilders) { this.credentialBuilders.addAll(credentialBuilders); @@ -449,7 +420,6 @@ public ConnectionFactory build() return new ConnectionFactory( this.environment, - this.connectionProvider, this.credentialBuilders, this.connectionBuilders ); diff --git a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/impl/DefaultConnectionProvider.java b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/impl/DefaultConnectionProvider.java deleted file mode 100644 index 8e3adcef3c7..00000000000 --- a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/impl/DefaultConnectionProvider.java +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2023 Goldman Sachs -// -// 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. - -package org.finos.legend.connection.impl; - -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; -import org.eclipse.collections.api.map.ImmutableMap; -import org.finos.legend.connection.Connection; -import org.finos.legend.connection.ConnectionProvider; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -public class DefaultConnectionProvider implements ConnectionProvider -{ - private final ImmutableMap connectionsIndex; - - private DefaultConnectionProvider(Map connectionsIndex) - { - - this.connectionsIndex = Maps.immutable.withAll(connectionsIndex); - } - - @Override - public Connection lookup(String identifier) - { - return Objects.requireNonNull(this.connectionsIndex.get(identifier), String.format("Can't find connection with identifier '%s'", identifier)); - } - - @Override - public List getAll() - { - return Lists.mutable.withAll(connectionsIndex.valuesView()); - } - - public static Builder builder() - { - return new Builder(); - } - - public static class Builder - { - private final Map connectionsIndex = new HashMap<>(); - - private Builder() - { - } - - public Builder connections(List connections) - { - connections.forEach(this::registerConnection); - return this; - } - - public Builder connections(Connection... connections) - { - Lists.mutable.with(connections).forEach(this::registerConnection); - return this; - } - - public Builder connection(Connection connection) - { - this.registerConnection(connection); - return this; - } - - private void registerConnection(Connection connection) - { - if (this.connectionsIndex.containsKey(connection.getIdentifier())) - { - throw new RuntimeException(String.format("Found multiple connections with identifier '%s'", connection.getIdentifier())); - } - this.connectionsIndex.put(connection.getIdentifier(), connection); - } - - public DefaultConnectionProvider build() - { - return new DefaultConnectionProvider(this.connectionsIndex); - } - } -} diff --git a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/impl/InstrumentedConnectionProvider.java b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/impl/InstrumentedConnectionProvider.java deleted file mode 100644 index 07b845d3ab8..00000000000 --- a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/impl/InstrumentedConnectionProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2023 Goldman Sachs -// -// 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. - -package org.finos.legend.connection.impl; - -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; -import org.finos.legend.connection.Connection; -import org.finos.legend.connection.ConnectionProvider; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * This is the instrumented version of {@link ConnectionProvider} which is used for testing. - */ -public class InstrumentedConnectionProvider implements ConnectionProvider -{ - private final Map connectionsIndex = Maps.mutable.empty(); - - public void injectConnection(Connection connection) - { - if (this.connectionsIndex.containsKey(connection.getIdentifier())) - { - throw new RuntimeException(String.format("Found multiple connections with identifier '%s'", connection.getIdentifier())); - } - this.connectionsIndex.put(connection.getIdentifier(), connection); - } - - @Override - public Connection lookup(String identifier) - { - return Objects.requireNonNull(this.connectionsIndex.get(identifier), String.format("Can't find connection with identifier '%s'", identifier)); - } - - @Override - public List getAll() - { - return Lists.mutable.withAll(connectionsIndex.values()); - } -} diff --git a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/test/java/org/finos/legend/connection/ConnectionFactoryTest.java b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/test/java/org/finos/legend/connection/ConnectionFactoryTest.java index 98bb76fd3e3..7c935f6cdc5 100644 --- a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/test/java/org/finos/legend/connection/ConnectionFactoryTest.java +++ b/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/test/java/org/finos/legend/connection/ConnectionFactoryTest.java @@ -15,7 +15,6 @@ package org.finos.legend.connection; import org.eclipse.collections.api.factory.Lists; -import org.finos.legend.connection.impl.InstrumentedConnectionProvider; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.AuthenticationConfiguration; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.ConnectionSpecification; import org.finos.legend.engine.shared.core.identity.Credential; @@ -32,44 +31,35 @@ public class ConnectionFactoryTest public void testGetConnection_WithFailures() throws Exception { TestEnv env = TestEnv.create( - Lists.mutable.with( - new CredentialBuilder_Any_to_A__withX() - ), - Lists.mutable.with( - new ConnectionBuilder_A() - ), - Lists.mutable.with( - AuthenticationMechanism.builder() - .type(TestAuthenticationMechanismType.X) - .authenticationConfigurationTypes(AuthenticationConfiguration_X.class) - .build(), - AuthenticationMechanism.builder() - .type(TestAuthenticationMechanismType.Y) - .authenticationConfigurationTypes(AuthenticationConfiguration_Y.class) - .build() - ) + Lists.mutable.with( + new CredentialBuilder_Any_to_A__withX() + ), + Lists.mutable.with( + new ConnectionBuilder_A() + ), + Lists.mutable.with( + AuthenticationMechanism.builder() + .type(TestAuthenticationMechanismType.X) + .authenticationConfigurationTypes(AuthenticationConfiguration_X.class) + .build(), + AuthenticationMechanism.builder() + .type(TestAuthenticationMechanismType.Y) + .authenticationConfigurationTypes(AuthenticationConfiguration_Y.class) + .build() ) - .newStore("test::connectionX", new AuthenticationConfiguration_X()) - .newStore("test::connectionY", new AuthenticationConfiguration_Y()); + ); Identity identity = new Identity("test"); // success - env.connectionFactory.getConnection(identity, env.connectionFactory.getAuthenticator(identity, "test::connectionX")); + env.connectionFactory.getConnection(identity, env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X()))); Exception exception; - // error: store not found - exception = Assertions.assertThrows(RuntimeException.class, () -> - { - env.connectionFactory.getConnection(identity, env.connectionFactory.getAuthenticator(identity, "unknown")); - }); - Assertions.assertEquals("Can't find connection with identifier 'unknown'", exception.getMessage()); - // error: unsupported authentication configuration exception = Assertions.assertThrows(RuntimeException.class, () -> { - env.connectionFactory.getConnection(identity, env.connectionFactory.getAuthenticator(identity, "test::connectionX", new AuthenticationConfiguration_Z())); + env.connectionFactory.getConnection(identity, env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X()), new AuthenticationConfiguration_Z())); }); Assertions.assertEquals("Connection 'test::connectionX' is not compatible with authentication configuration type 'AuthenticationConfiguration_Z'. Supported configuration type(s):\n" + "- AuthenticationConfiguration_X\n" + @@ -78,7 +68,7 @@ public void testGetConnection_WithFailures() throws Exception // error: unresolvable authentication flow exception = Assertions.assertThrows(RuntimeException.class, () -> { - env.connectionFactory.getConnection(identity, env.connectionFactory.getAuthenticator(identity, "test::connectionX", new AuthenticationConfiguration_Y())); + env.connectionFactory.getConnection(identity, env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X()), new AuthenticationConfiguration_Y())); }); Assertions.assertEquals("No authentication flow for connection 'test::connectionX' can be resolved for the specified identity (authentication configuration: AuthenticationConfiguration_Y, connection specification: TestConnectionSpecification)", exception.getMessage()); } @@ -108,10 +98,10 @@ public void testGetConnection_WithSimpleFlow() throws Exception .authenticationConfigurationTypes(AuthenticationConfiguration_Y.class) .build() ) - ).newStore("test::connectionX", new AuthenticationConfiguration_X()); + ); Identity identity = new Identity("test"); - Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, "test::connectionX"); + Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X())); assertAuthenticator(identity, env.connectionFactory, authenticator, Credential.class, Lists.mutable.with( "Credential->Credential_A [AuthenticationConfiguration_X]" ), ConnectionBuilder_A.class); @@ -124,26 +114,25 @@ public void testGetConnection_WithSimpleFlow() throws Exception public void testGetConnection_WithSpecificBuilderOrder() throws Exception { TestEnv env = TestEnv.create( - Lists.mutable.with( - // if Any -> B credential builder is specified first, it will take precedence over Any -> A - new CredentialBuilder_Any_to_B__withX(), - new CredentialBuilder_Any_to_A__withX() - ), - Lists.mutable.with( - new ConnectionBuilder_A(), - new ConnectionBuilder_B() - ), - Lists.mutable.with( - AuthenticationMechanism.builder() - .type(TestAuthenticationMechanismType.X) - .authenticationConfigurationTypes(AuthenticationConfiguration_X.class) - .build() - ) + Lists.mutable.with( + // if Any -> B credential builder is specified first, it will take precedence over Any -> A + new CredentialBuilder_Any_to_B__withX(), + new CredentialBuilder_Any_to_A__withX() + ), + Lists.mutable.with( + new ConnectionBuilder_A(), + new ConnectionBuilder_B() + ), + Lists.mutable.with( + AuthenticationMechanism.builder() + .type(TestAuthenticationMechanismType.X) + .authenticationConfigurationTypes(AuthenticationConfiguration_X.class) + .build() ) - .newStore("test::connectionX", new AuthenticationConfiguration_X()); + ); Identity identity = new Identity("test"); - Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, "test::connectionX"); + Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X())); assertAuthenticator(identity, env.connectionFactory, authenticator, Credential.class, Lists.mutable.with( "Credential->Credential_B [AuthenticationConfiguration_X]" ), ConnectionBuilder_B.class); @@ -170,10 +159,10 @@ public void testGetConnection_WithChainFlow() throws Exception .authenticationConfigurationTypes(AuthenticationConfiguration_X.class) .build() ) - ).newStore("test::connectionX", new AuthenticationConfiguration_X()); + ); Identity identity = new Identity("test"); - Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, "test::connectionX"); + Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X())); assertAuthenticator(identity, env.connectionFactory, authenticator, Credential.class, Lists.mutable.with( "Credential->Credential_A [AuthenticationConfiguration_X]", "Credential_A->Credential_B [AuthenticationConfiguration_X]", @@ -202,10 +191,10 @@ public void testGetConnection_WithShortestFlowResolved() throws Exception .authenticationConfigurationTypes(AuthenticationConfiguration_X.class) .build() ) - ).newStore("test::connectionX", new AuthenticationConfiguration_X()); + ); Identity identity = new Identity("test", new Credential_B()); - Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, "test::connectionX"); + Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X())); assertAuthenticator(identity, env.connectionFactory, authenticator, Credential_B.class, Lists.mutable.with( "Credential_B->Credential_C [AuthenticationConfiguration_X]" ), ConnectionBuilder_C.class); @@ -239,12 +228,12 @@ public void testGetConnection_WithCustomAuthConfigProvided() throws Exception .authenticationConfigurationTypes(AuthenticationConfiguration_Z.class) .build() ) - ).newStore("test::connectionX", new AuthenticationConfiguration_X()); + ); Identity identity = new Identity("test", new Credential_A()); // success - Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, "test::connectionX", new AuthenticationConfiguration_Y()); + Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X()), new AuthenticationConfiguration_Y()); assertAuthenticator(identity, env.connectionFactory, authenticator, Credential_A.class, Lists.mutable.with( "Credential_A->Credential_B [AuthenticationConfiguration_Y]" ), ConnectionBuilder_B.class); @@ -252,7 +241,7 @@ public void testGetConnection_WithCustomAuthConfigProvided() throws Exception // error: unresolvable authentication flow Exception exception = Assertions.assertThrows(RuntimeException.class, () -> { - env.connectionFactory.getAuthenticator(new Identity("test"), "test::connectionX"); + env.connectionFactory.getAuthenticator(new Identity("test"), env.newStore("test::connectionX", new AuthenticationConfiguration_X())); }); Assertions.assertEquals("No authentication flow for connection 'test::connectionX' can be resolved for the specified identity. Try specifying another authentication configuration. Supported configuration type(s):\n" + "- AuthenticationConfiguration_X (X)\n" + @@ -279,10 +268,10 @@ public void testGetConnection_WithCredentialExtractor() throws Exception .authenticationConfigurationTypes(AuthenticationConfiguration_X.class) .build() ) - ).newStore("test::connectionX", new AuthenticationConfiguration_X()); + ); Identity identity = new Identity("test", new Credential_A()); - Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, "test::connectionX"); + Authenticator authenticator = env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X())); assertAuthenticator(identity, env.connectionFactory, authenticator, Credential_A.class, Lists.mutable.with( "Credential_A->Credential_A [AuthenticationConfiguration_X]" ), ConnectionBuilder_A.class); @@ -301,9 +290,9 @@ public void testGetConnection_WithCredentialExtractor() throws Exception .authenticationConfigurationTypes(AuthenticationConfiguration_X.class) .build() ) - ).newStore("test::connectionX", new AuthenticationConfiguration_X()); + ); - authenticator = env2.connectionFactory.getAuthenticator(identity, "test::connectionX"); + authenticator = env2.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X())); assertAuthenticator(identity, env2.connectionFactory, authenticator, Credential_A.class, Lists.mutable.with( "Credential_A->Credential_A [AuthenticationConfiguration_X]" ), ConnectionBuilder_A.class); @@ -329,12 +318,12 @@ public void testGetConnection_WithoutCredentialExtractor() throws Exception .authenticationConfigurationTypes(AuthenticationConfiguration_X.class) .build() ) - ).newStore("test::connectionX", new AuthenticationConfiguration_X()); + ); Identity identity = new Identity("test", new Credential_A()); Exception exception = Assertions.assertThrows(RuntimeException.class, () -> { - env.connectionFactory.getConnection(identity, env.connectionFactory.getAuthenticator(identity, "test::connectionX")); + env.connectionFactory.getConnection(identity, env.connectionFactory.getAuthenticator(identity, env.newStore("test::connectionX", new AuthenticationConfiguration_X()))); }); Assertions.assertEquals("No authentication flow for connection 'test::connectionX' can be resolved for the specified identity. Try specifying another authentication configuration. Supported configuration type(s):\n" + "- AuthenticationConfiguration_X (X)", exception.getMessage()); @@ -351,7 +340,6 @@ private void assertAuthenticator(Identity identity, ConnectionFactory connection private static class TestEnv { final LegendEnvironment environment; - final InstrumentedConnectionProvider connectionProvider; final ConnectionFactory connectionFactory; private TestEnv(List credentialBuilders, List connectionBuilders, List authenticationMechanisms) @@ -362,29 +350,26 @@ private TestEnv(List credentialBuilders, List authenticationMechanisms) + Connection newStore(String identifier, AuthenticationConfiguration authenticationConfiguration, List authenticationMechanisms) { DatabaseSupport databaseSupport = this.environment.getDatabaseSupport(TestDatabaseType.TEST); - this.connectionProvider.injectConnection(Connection.builder() + return Connection.builder() .databaseSupport(databaseSupport) .identifier(identifier) .authenticationMechanisms(authenticationMechanisms) .connectionSpecification(new TestConnectionSpecification()) .authenticationConfiguration(authenticationConfiguration) - .build()); - return this; + .build(); } - TestEnv newStore(String identifier, AuthenticationConfiguration authenticationConfiguration) + Connection newStore(String identifier, AuthenticationConfiguration authenticationConfiguration) { return newStore(identifier, authenticationConfiguration, Lists.mutable.empty()); } diff --git a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/BaseDataPushServer.java b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/BaseDataPushServer.java index 76480f7d42c..1129ce8f1bf 100644 --- a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/BaseDataPushServer.java +++ b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/BaseDataPushServer.java @@ -16,29 +16,37 @@ import io.dropwizard.setup.Environment; import org.finos.legend.connection.ConnectionFactory; -import org.finos.legend.connection.ConnectionProvider; import org.finos.legend.connection.IdentityFactory; import org.finos.legend.connection.LegendEnvironment; import org.finos.legend.engine.datapush.DataPusherProvider; import org.finos.legend.engine.datapush.server.configuration.DataPushServerConfiguration; import org.finos.legend.engine.datapush.server.resources.DataPushResource; +import org.finos.legend.engine.protocol.pure.v1.PureProtocolObjectMapperFactory; import org.finos.legend.engine.server.support.server.BaseServer; +import org.finos.legend.engine.shared.core.ObjectMapperFactory; public abstract class BaseDataPushServer extends BaseServer { protected LegendEnvironment environment; protected IdentityFactory identityFactory; - protected ConnectionProvider connectionProvider; protected ConnectionFactory connectionFactory; protected DataPusherProvider dataPushProvider; + @Override + public void initialize(io.dropwizard.setup.Bootstrap bootstrap) + { + super.initialize(bootstrap); + + PureProtocolObjectMapperFactory.withPureProtocolExtensions(bootstrap.getObjectMapper()); + ObjectMapperFactory.withStandardConfigurations(bootstrap.getObjectMapper()); + } + @Override public void run(DataPushServerConfiguration configuration, Environment environment) { this.environment = this.buildLegendEnvironment(configuration); this.identityFactory = this.buildIdentityFactory(configuration, this.environment); - this.connectionProvider = this.buildConnectionBuilder(configuration, this.environment); - this.connectionFactory = this.buildConnectionFactory(configuration, this.connectionProvider, this.environment); + this.connectionFactory = this.buildConnectionFactory(configuration, this.environment); this.dataPushProvider = this.buildDataPushProvider(); super.run(configuration, environment); } @@ -46,7 +54,7 @@ public void run(DataPushServerConfiguration configuration, Environment environme @Override protected void configureServerCore(DataPushServerConfiguration configuration, Environment environment) { - environment.jersey().register(new DataPushResource(configuration.getMetadataServerConfiguration(), this.environment, this.identityFactory, this.connectionProvider, this.connectionFactory, this.dataPushProvider)); + environment.jersey().register(new DataPushResource(configuration.getMetadataServerConfiguration(), this.environment, this.identityFactory, this.connectionFactory, this.dataPushProvider)); } @Override @@ -59,9 +67,7 @@ protected void configureServerExtension(DataPushServerConfiguration configuratio public abstract IdentityFactory buildIdentityFactory(DataPushServerConfiguration configuration, LegendEnvironment environment); - public abstract ConnectionProvider buildConnectionBuilder(DataPushServerConfiguration configuration, LegendEnvironment environment); - - public abstract ConnectionFactory buildConnectionFactory(DataPushServerConfiguration configuration, ConnectionProvider connectionProvider, LegendEnvironment environment); + public abstract ConnectionFactory buildConnectionFactory(DataPushServerConfiguration configuration, LegendEnvironment environment); public abstract DataPusherProvider buildDataPushProvider(); } diff --git a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/DataPushServer.java b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/DataPushServer.java index b03088b06e3..c9e566ca3d2 100644 --- a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/DataPushServer.java +++ b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/DataPushServer.java @@ -20,13 +20,11 @@ import org.finos.legend.connection.AuthenticationMechanism; import org.finos.legend.connection.Connection; import org.finos.legend.connection.ConnectionFactory; -import org.finos.legend.connection.ConnectionProvider; import org.finos.legend.connection.DatabaseSupport; import org.finos.legend.connection.DatabaseType; import org.finos.legend.connection.IdentityFactory; import org.finos.legend.connection.LegendEnvironment; import org.finos.legend.connection.impl.CoreAuthenticationMechanismType; -import org.finos.legend.connection.impl.InstrumentedConnectionProvider; import org.finos.legend.connection.impl.KerberosCredentialExtractor; import org.finos.legend.connection.impl.KeyPairCredentialBuilder; import org.finos.legend.connection.impl.RelationalDatabaseType; @@ -37,8 +35,6 @@ import org.finos.legend.engine.datapush.DataPusherProvider; import org.finos.legend.engine.datapush.impl.SnowflakeWithS3StageDataPusher; import org.finos.legend.engine.datapush.server.configuration.DataPushServerConfiguration; -import org.finos.legend.engine.protocol.pure.v1.connection.SnowflakeConnectionSpecification; -import org.finos.legend.engine.protocol.pure.v1.model.connection.StaticJDBCConnectionSpecification; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.EncryptedPrivateKeyPairAuthenticationConfiguration; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.UserPasswordAuthenticationConfiguration; import org.finos.legend.engine.server.support.server.config.BaseServerConfiguration; @@ -106,63 +102,10 @@ public IdentityFactory buildIdentityFactory(DataPushServerConfiguration configur } @Override - public ConnectionProvider buildConnectionBuilder(DataPushServerConfiguration configuration, LegendEnvironment environment) - { - InstrumentedConnectionProvider connectionProvider = new InstrumentedConnectionProvider(); - - connectionProvider.injectConnection(Connection.builder() - .databaseSupport(this.environment.getDatabaseSupport(RelationalDatabaseType.POSTGRES)) - .identifier("test-postgres") - .connectionSpecification(new StaticJDBCConnectionSpecification( - "localhost", - 5432, - "legend" - )) - .build()); - - SnowflakeConnectionSpecification summitSnowflake = new SnowflakeConnectionSpecification(); - summitSnowflake.databaseName = "SUMMIT_DEV"; - summitSnowflake.accountName = "ki79827"; - summitSnowflake.warehouseName = "SUMMIT_DEV"; - summitSnowflake.region = "us-east-2"; - summitSnowflake.cloudType = "aws"; - summitSnowflake.role = "SUMMIT_DEV"; - connectionProvider.injectConnection(Connection.builder() - .databaseSupport(this.environment.getDatabaseSupport(RelationalDatabaseType.SNOWFLAKE)) - .identifier("test-snowflake") - .connectionSpecification(summitSnowflake) - .build() - ); - - SnowflakeConnectionSpecification finosSnowflake = new SnowflakeConnectionSpecification(); - finosSnowflake.databaseName = "DPSH_DB1"; - finosSnowflake.accountName = "ki79827"; - finosSnowflake.warehouseName = "PUSH_WH1"; - finosSnowflake.region = "us-east-2"; - finosSnowflake.cloudType = "aws"; - finosSnowflake.role = "PUSH_ROLE1"; - connectionProvider.injectConnection(Connection.builder() - .databaseSupport(this.environment.getDatabaseSupport(RelationalDatabaseType.SNOWFLAKE)) - .identifier("finosSF") - .connectionSpecification(finosSnowflake) - .build() - ); - - System.setProperty("passwordRef", "xxxxx"); // NOTE: secret - to be removed when committed - System.setProperty("sfsummit_snowflakePkRef", "xxxxx"); // NOTE: secret - to be removed when committed - System.setProperty("sfsummit_snowflakePkPassphraseRef", "xxxxx"); // NOTE: secret - to be removed when committed - System.setProperty("finos_snowflakePkRef", "xxxxx"); // NOTE: secret - to be removed when committed - System.setProperty("finos_snowflakePkPassphraseRef", "xxxxx"); // NOTE: secret - to be removed when committed - - return connectionProvider; - } - - @Override - public ConnectionFactory buildConnectionFactory(DataPushServerConfiguration configuration, ConnectionProvider connectionProvider, LegendEnvironment environment) + public ConnectionFactory buildConnectionFactory(DataPushServerConfiguration configuration, LegendEnvironment environment) { return ConnectionFactory.builder() .environment(this.environment) - .connectionProvider(this.connectionProvider) .credentialBuilders( new KerberosCredentialExtractor(), new UserPasswordCredentialBuilder(), diff --git a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/resources/DataPushResource.java b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/resources/DataPushResource.java index f1a152880dc..6bffdce91bd 100644 --- a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/resources/DataPushResource.java +++ b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/main/java/org/finos/legend/engine/datapush/server/resources/DataPushResource.java @@ -18,7 +18,6 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.connection.Connection; import org.finos.legend.connection.ConnectionFactory; -import org.finos.legend.connection.ConnectionProvider; import org.finos.legend.connection.IdentityFactory; import org.finos.legend.connection.IdentitySpecification; import org.finos.legend.connection.LegendEnvironment; @@ -64,15 +63,13 @@ public class DataPushResource extends BaseResource private final ConnectionModelLoader connectionModelLoader; private final LegendEnvironment environment; private final IdentityFactory identityFactory; - private final ConnectionProvider connectionProvider; private final ConnectionFactory connectionFactory; private final DataPusherProvider dataPusherProvider; - public DataPushResource(MetaDataServerConfiguration metadataserver, LegendEnvironment environment, IdentityFactory identityFactory, ConnectionProvider connectionProvider, ConnectionFactory connectionFactory, DataPusherProvider dataPusherProvider) + public DataPushResource(MetaDataServerConfiguration metadataserver, LegendEnvironment environment, IdentityFactory identityFactory, ConnectionFactory connectionFactory, DataPusherProvider dataPusherProvider) { this.environment = environment; this.identityFactory = identityFactory; - this.connectionProvider = connectionProvider; this.connectionFactory = connectionFactory; this.dataPusherProvider = dataPusherProvider; this.connectionModelLoader = new ConnectionModelLoader(metadataserver); @@ -81,7 +78,7 @@ public DataPushResource(MetaDataServerConfiguration metadataserver, LegendEnviro @Path("/push/{groupId}/{artifactId}/{versionId}/{connectionPath}") @POST @Consumes({ - // TODO: content type will drive how we interpret the data, right nowe + // TODO: content type will drive how we interpret the data, right now // we only support CSV MediaType.TEXT_PLAIN, MediaType.TEXT_XML, @@ -115,6 +112,7 @@ public Response pushData( } catch (Exception exception) { + LOGGER.error("Can't push data:\n", exception); return handleException(profiles, exception); } } @@ -122,7 +120,7 @@ public Response pushData( @Path("/pushDev/{projectId}/{workspaceId}/{connectionPath}") @POST @Consumes({ - // TODO: content type will drive how we interpret the data, right nowe + // TODO: content type will drive how we interpret the data, right now // we only support CSV MediaType.TEXT_PLAIN, MediaType.TEXT_XML, @@ -156,6 +154,7 @@ public Response pushData_Dev( } catch (Exception exception) { + LOGGER.error("Can't push data:\n", exception); return handleException(profiles, exception); } } @@ -180,4 +179,42 @@ private void pushCSVData(Identity identity, org.finos.legend.engine.protocol.pur throw new RuntimeException(e); } } + + // ------------------------ DEBUG ----------------------- + // TO BE REMOVED when we stabilize the API and models + + @Path("/pushDev/debug") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response TEMPORARY__pushData_Debug( + DebugInput input, + @Context HttpServletRequest request, + @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager profileManager + ) + { + List profiles = ProfileManagerHelper.extractProfiles(profileManager); + Identity identity = this.identityFactory.createIdentity( + IdentitySpecification.builder().profiles(profiles).build() + ); + CSVData csvData = new CSVData(); + csvData.value = input.data; + + try + { + this.pushCSVData(identity, input.connection, csvData); + return Response.noContent().build(); + } + catch (Exception exception) + { + LOGGER.error("Can't push data:\n", exception); + return handleException(profiles, exception); + } + } + + public static class DebugInput + { + public org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.Connection connection; + public String data; + } } diff --git a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/test/java/org/finos/legend/engine/datapush/server/test/DataPushServerForTest.java b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/test/java/org/finos/legend/engine/datapush/server/test/DataPushServerForTest.java index 2d55429407c..70ab113b50c 100644 --- a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/test/java/org/finos/legend/engine/datapush/server/test/DataPushServerForTest.java +++ b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/test/java/org/finos/legend/engine/datapush/server/test/DataPushServerForTest.java @@ -18,11 +18,9 @@ import org.finos.legend.authentication.vault.impl.SystemPropertiesCredentialVault; import org.finos.legend.connection.AuthenticationMechanism; import org.finos.legend.connection.ConnectionFactory; -import org.finos.legend.connection.ConnectionProvider; import org.finos.legend.connection.DatabaseSupport; import org.finos.legend.connection.LegendEnvironment; import org.finos.legend.connection.impl.CoreAuthenticationMechanismType; -import org.finos.legend.connection.impl.InstrumentedConnectionProvider; import org.finos.legend.connection.impl.KerberosCredentialExtractor; import org.finos.legend.connection.impl.RelationalDatabaseType; import org.finos.legend.connection.impl.StaticJDBCConnectionBuilder; @@ -65,17 +63,10 @@ public LegendEnvironment buildLegendEnvironment(DataPushServerConfiguration conf } @Override - public ConnectionProvider buildConnectionBuilder(DataPushServerConfiguration configuration, LegendEnvironment environment) - { - return new InstrumentedConnectionProvider(); - } - - @Override - public ConnectionFactory buildConnectionFactory(DataPushServerConfiguration configuration, ConnectionProvider connectionProvider, LegendEnvironment environment) + public ConnectionFactory buildConnectionFactory(DataPushServerConfiguration configuration, LegendEnvironment environment) { return ConnectionFactory.builder() .environment(this.environment) - .connectionProvider(this.connectionProvider) .credentialBuilders( new KerberosCredentialExtractor(), new UserPasswordCredentialBuilder() @@ -90,9 +81,4 @@ public LegendEnvironment getEnvironment() { return environment; } - - public InstrumentedConnectionProvider getConnectionProvider() - { - return (InstrumentedConnectionProvider) connectionProvider; - } } \ No newline at end of file diff --git a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/test/java/org/finos/legend/engine/datapush/server/test/TestDataPushServer.java b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/test/java/org/finos/legend/engine/datapush/server/test/TestDataPushServer.java index 4fd440e2409..19a78f80f8f 100644 --- a/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/test/java/org/finos/legend/engine/datapush/server/test/TestDataPushServer.java +++ b/legend-engine-xts-data-push/legend-engine-xt-data-push-server/src/test/java/org/finos/legend/engine/datapush/server/test/TestDataPushServer.java @@ -14,13 +14,7 @@ package org.finos.legend.engine.datapush.server.test; -import org.finos.legend.connection.AuthenticationMechanism; -import org.finos.legend.connection.Connection; import org.finos.legend.connection.PostgresTestContainerWrapper; -import org.finos.legend.connection.impl.CoreAuthenticationMechanismType; -import org.finos.legend.connection.impl.RelationalDatabaseType; -import org.finos.legend.engine.protocol.pure.v1.model.connection.StaticJDBCConnectionSpecification; -import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.ConnectionSpecification; import org.junit.After; import org.junit.Assume; import org.junit.Before; @@ -63,25 +57,6 @@ public void setUp() { Assume.assumeTrue("Can't start PostgreSQLContainer", false); } - - System.setProperty("passwordRef", this.postgresContainer.getPassword()); - - DataPushServerForTest application = this.getApplicationInstance(); - ConnectionSpecification connectionSpecification = new StaticJDBCConnectionSpecification( - this.postgresContainer.getHost(), - this.postgresContainer.getPort(), - this.postgresContainer.getDatabaseName() - ); - application.getConnectionProvider().injectConnection(Connection.builder() - .databaseSupport(application.getEnvironment().getDatabaseSupport(RelationalDatabaseType.POSTGRES)) - .identifier("test::connection") - .authenticationMechanisms( - AuthenticationMechanism.builder() - .type(CoreAuthenticationMechanismType.USER_PASSWORD).build() - ) - .connectionSpecification(connectionSpecification) - .build() - ); } @After diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/JDBCConnectionBuilder.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/JDBCConnectionBuilder.java similarity index 95% rename from legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/JDBCConnectionBuilder.java rename to legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/JDBCConnectionBuilder.java index 495bfde98e9..d380bb07a9c 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/JDBCConnectionBuilder.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/JDBCConnectionBuilder.java @@ -12,8 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.finos.legend.connection; +package org.finos.legend.connection.impl; +import org.finos.legend.connection.ConnectionBuilder; import org.finos.legend.connection.impl.JDBCConnectionManager; import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.ConnectionSpecification; import org.finos.legend.engine.shared.core.identity.Credential; diff --git a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionProvider.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/RelationalConnectionExtension.java similarity index 56% rename from legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionProvider.java rename to legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/RelationalConnectionExtension.java index 5708467b009..138e56e5506 100644 --- a/legend-engine-xts-connection/legend-engine-xt-connection-factory/src/main/java/org/finos/legend/connection/ConnectionProvider.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/RelationalConnectionExtension.java @@ -12,13 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.finos.legend.connection; +package org.finos.legend.connection.impl; + +import org.eclipse.collections.api.factory.Lists; +import org.finos.legend.connection.AuthenticationMechanismType; +import org.finos.legend.connection.ConnectionExtension; +import org.finos.legend.connection.DatabaseType; import java.util.List; -public interface ConnectionProvider +public class RelationalConnectionExtension implements ConnectionExtension { - Connection lookup(String identifier); - - List getAll(); + @Override + public List getExtraDatabaseTypes() + { + return Lists.mutable.of(RelationalDatabaseType.values()); + } } diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/StaticJDBCConnectionBuilder.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/StaticJDBCConnectionBuilder.java index 8cf8c0c910a..6d12df9cdae 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/StaticJDBCConnectionBuilder.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/java/org/finos/legend/connection/impl/StaticJDBCConnectionBuilder.java @@ -17,7 +17,6 @@ import org.finos.legend.connection.Authenticator; import org.finos.legend.connection.Connection; import org.finos.legend.connection.DatabaseSupport; -import org.finos.legend.connection.JDBCConnectionBuilder; import org.finos.legend.engine.protocol.pure.v1.model.connection.StaticJDBCConnectionSpecification; import org.finos.legend.engine.shared.core.identity.Credential; import org.finos.legend.engine.shared.core.identity.Identity; diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/resources/META-INF/services/org.finos.legend.connection.ConnectionExtension b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/resources/META-INF/services/org.finos.legend.connection.ConnectionExtension new file mode 100644 index 00000000000..460c36f956e --- /dev/null +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-connection/src/main/resources/META-INF/services/org.finos.legend.connection.ConnectionExtension @@ -0,0 +1 @@ +org.finos.legend.connection.impl.RelationalConnectionExtension \ No newline at end of file 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/SnowflakeConnectionBuilder.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/SnowflakeConnectionBuilder.java index d06af65d43c..9b01d03bd6d 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/SnowflakeConnectionBuilder.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/SnowflakeConnectionBuilder.java @@ -17,7 +17,6 @@ import org.finos.legend.connection.Authenticator; import org.finos.legend.connection.Connection; import org.finos.legend.connection.DatabaseSupport; -import org.finos.legend.connection.JDBCConnectionBuilder; import org.finos.legend.engine.protocol.pure.v1.connection.SnowflakeConnectionSpecification; import org.finos.legend.engine.shared.core.identity.Credential; import org.finos.legend.engine.shared.core.identity.Identity;