Changesets · Branches · Tags · Compare
| Changeset | a438d076d2c5b2d995f21e91fcf181eca901a42c7712a652fbf06a4ff978e45d |
|---|---|
| Author | ndr_brt <andrea.bertagnolli@gmail.com> · 2024-08-07 08:52 +02:00 |
| Committer | GitHub <noreply@github.com> · 2024-08-07 08:52 +02:00 |
| Parents | 017a6b9f61cd |
27 files changed
modified docs/developer/README.md +1 −0
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | ## Guides |
| 12 | 12 | - [Customize Policy Engine](policy-engine.md) |
| 13 | 13 | - [Performance Tuning](performance-tuning.md) |
| 14 | +- [Sql persistence](sql-persistence.md) | |
| 14 | 15 | |
| 15 | 16 | ## Build and testing |
| 16 | 17 | - [OpenApi Spec Generation](openapi.md) |
added docs/developer/sql-persistence.md +41 −0
| @@ -0,0 +1,41 @@ | ||
| 1 | +# SQL persistence | |
| 2 | + | |
| 3 | +Every store in the EDC, intended as persistence for state, comes out of the box with two implementations: | |
| 4 | +- in-memory | |
| 5 | +- sql (postgresql dialect) | |
| 6 | + | |
| 7 | +By default, the `in-memory` stores are provided by the dependency injection, the `sql` implementations can be used by | |
| 8 | +simply registering the relative extensions (e.g. `asset-index-sql`, `contract-negotiation-store-sql`, ...). | |
| 9 | + | |
| 10 | +## Configuration | |
| 11 | + | |
| 12 | +### DataSources | |
| 13 | + | |
| 14 | +For using `sql` extensions, a `DataSource` is needed, and it should be registered on the `DataSourceRegistry` service. | |
| 15 | + | |
| 16 | +The `sql-pool-apache-commons` extension takes care to create and register pooled data sources starting from configuration. | |
| 17 | +It expects at least one data source called `default` that can be configured with `Vault` keys: | |
| 18 | +``` | |
| 19 | +edc.datasource.default.url=... | |
| 20 | +edc.datasource.default.name=... | |
| 21 | +edc.datasource.default.password=... | |
| 22 | +``` | |
| 23 | +(note: if no vault entries are found for such keys, they will be obtained from the configuration). | |
| 24 | + | |
| 25 | +Other datasources can be defined using the same settings structure: | |
| 26 | +``` | |
| 27 | +edc.datasource.<datasource-name>.url=... | |
| 28 | +edc.datasource.<datasource-name>.name=... | |
| 29 | +edc.datasource.<datasource-name>.password=... | |
| 30 | +``` | |
| 31 | + | |
| 32 | +`<datasource-name>` can be a string that then can be used by the stores configuration to use specific data sources. | |
| 33 | + | |
| 34 | +### Using custom datasource in stores | |
| 35 | + | |
| 36 | +Using a custom datasource in a store can be done by configuring the setting: | |
| 37 | +``` | |
| 38 | +edc.sql.store.<store-context>.datasource=<datasource-name> | |
| 39 | +``` | |
| 40 | + | |
| 41 | +This way the `<store-context>` (that could be `asset`, `contractnegotiation`...) will use the `<datasource-name>` datasource. |
added extensions/common/sql/sql-core/src/main/java/org/eclipse/edc/sql/configuration/DataSourceName.java +56 −0
| @@ -0,0 +1,56 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.sql.configuration; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.spi.monitor.Monitor; | |
| 18 | +import org.eclipse.edc.spi.system.configuration.Config; | |
| 19 | + | |
| 20 | +import static org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry.DEFAULT_DATASOURCE; | |
| 21 | + | |
| 22 | +/** | |
| 23 | + * This interface is only functional to the migration from the old format to the new one. | |
| 24 | + * Ref. <a href="https://github.com/eclipse-edc/Connector/issues/3811">https://github.com/eclipse-edc/Connector/issues/3811</a> | |
| 25 | + */ | |
| 26 | +public interface DataSourceName { | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Extracts datasource name from configuration considering deprecated key as fallback. | |
| 30 | + * | |
| 31 | + * @param key the setting key. | |
| 32 | + * @param deprecatedKey the deprecate setting key. | |
| 33 | + * @param config the config. | |
| 34 | + * @param monitor the monitor. | |
| 35 | + * @return the datasource name | |
| 36 | + * @deprecated will be removed together with the deprecated settings. | |
| 37 | + */ | |
| 38 | + @Deprecated(since = "0.8.1") | |
| 39 | + static String getDataSourceName(String key, String deprecatedKey, Config config, Monitor monitor) { | |
| 40 | + var datasourceName = config.getString(key, null); | |
| 41 | + | |
| 42 | + if (datasourceName != null) { | |
| 43 | + return datasourceName; | |
| 44 | + } | |
| 45 | + | |
| 46 | + var name = config.getString(deprecatedKey, null); | |
| 47 | + | |
| 48 | + if (name != null) { | |
| 49 | + monitor.warning("Datasource name setting key %s has been deprecated, please switch to %s".formatted(deprecatedKey, key)); | |
| 50 | + return name; | |
| 51 | + } | |
| 52 | + | |
| 53 | + return DEFAULT_DATASOURCE; | |
| 54 | + } | |
| 55 | + | |
| 56 | +} |
modified extensions/common/sql/sql-pool/sql-pool-apache-commons/src/main/java/org/eclipse/edc/sql/pool/commons/CommonsConnectionPoolServiceExtension.java +57 −91
| @@ -27,17 +27,13 @@ | ||
| 27 | 27 | import org.eclipse.edc.sql.datasource.ConnectionFactoryDataSource; |
| 28 | 28 | import org.eclipse.edc.sql.datasource.ConnectionPoolDataSource; |
| 29 | 29 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 30 | -import org.jetbrains.annotations.NotNull; | |
| 31 | -import org.jetbrains.annotations.Nullable; | |
| 32 | 30 | |
| 33 | -import java.util.HashMap; | |
| 34 | 31 | import java.util.LinkedList; |
| 35 | 32 | import java.util.List; |
| 36 | -import java.util.Map; | |
| 33 | +import java.util.Optional; | |
| 37 | 34 | import java.util.Properties; |
| 38 | 35 | import java.util.function.BiFunction; |
| 39 | 36 | import java.util.function.Consumer; |
| 40 | -import java.util.function.Supplier; | |
| 41 | 37 | import javax.sql.DataSource; |
| 42 | 38 | |
| 43 | 39 | import static java.util.Optional.ofNullable; |
| @@ -48,24 +44,32 @@ | ||
| 48 | 44 | public static final String NAME = "Commons Connection Pool"; |
| 49 | 45 | |
| 50 | 46 | public static final String EDC_DATASOURCE_PREFIX = "edc.datasource"; |
| 47 | + private static final String EDC_DATASOURCE_CONFIG_CONTEXT = EDC_DATASOURCE_PREFIX + ".<name>"; | |
| 48 | + | |
| 49 | + @Setting(value = "JDBC url", required = true, context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 50 | + public static final String URL = "url"; | |
| 51 | + @Setting(value = "Username to be used for the JDBC connection. Can be omitted if not required, or if the user is encoded in the JDBC url.", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 52 | + public static final String USER = "user"; | |
| 53 | + @Setting(value = "Username to be used for the JDBC connection. Can be omitted if not required, or if the password is encoded in the JDBC url.", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 54 | + public static final String PASSWORD = "password"; | |
| 55 | + | |
| 56 | + @Setting(value = "Pool max idle connections", type = "int", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 51 | 57 | public static final String POOL_CONNECTIONS_MAX_IDLE = "pool.connections.max-idle"; |
| 58 | + @Setting(value = "Pool max total connections", type = "int", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 52 | 59 | public static final String POOL_CONNECTIONS_MAX_TOTAL = "pool.connections.max-total"; |
| 60 | + @Setting(value = "Pool min idle connections", type = "int", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 53 | 61 | public static final String POOL_CONNECTIONS_MIN_IDLE = "pool.connections.min-idle"; |
| 62 | + @Setting(value = "Pool test on borrow", type = "boolean", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 54 | 63 | public static final String POOL_CONNECTION_TEST_ON_BORROW = "pool.connection.test.on-borrow"; |
| 64 | + @Setting(value = "Pool test on create", type = "boolean", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 55 | 65 | public static final String POOL_CONNECTION_TEST_ON_CREATE = "pool.connection.test.on-create"; |
| 66 | + @Setting(value = "Pool test on return", type = "boolean", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 56 | 67 | public static final String POOL_CONNECTION_TEST_ON_RETURN = "pool.connection.test.on-return"; |
| 68 | + @Setting(value = "Pool test while idle", type = "boolean", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 57 | 69 | public static final String POOL_CONNECTION_TEST_WHILE_IDLE = "pool.connection.test.while-idle"; |
| 70 | + @Setting(value = "Pool test query", context = EDC_DATASOURCE_CONFIG_CONTEXT) | |
| 58 | 71 | public static final String POOL_CONNECTION_TEST_QUERY = "pool.connection.test.query"; |
| 59 | 72 | |
| 60 | - @Setting(required = true) | |
| 61 | - public static final String URL = "url"; | |
| 62 | - | |
| 63 | - @Setting(value = "Username to be used for the JDBC connection. Can be omitted if not required, or if the user is encoded in the JDBC url.") | |
| 64 | - public static final String USER = "user"; | |
| 65 | - @Setting(value = "Username to be used for the JDBC connection. Can be omitted if not required, or if the password is encoded in the JDBC url.") | |
| 66 | - public static final String PASSWORD = "password"; | |
| 67 | - | |
| 68 | - private final List<CommonsConnectionPool> commonsConnectionPools = new LinkedList<>(); | |
| 69 | 73 | @Inject |
| 70 | 74 | private DataSourceRegistry dataSourceRegistry; |
| 71 | 75 | |
| @@ -78,6 +82,8 @@ | ||
| 78 | 82 | @Inject |
| 79 | 83 | private Vault vault; |
| 80 | 84 | |
| 85 | + private final List<CommonsConnectionPool> commonsConnectionPools = new LinkedList<>(); | |
| 86 | + | |
| 81 | 87 | @Override |
| 82 | 88 | public String name() { |
| 83 | 89 | return NAME; |
| @@ -85,17 +91,14 @@ | ||
| 85 | 91 | |
| 86 | 92 | @Override |
| 87 | 93 | public void initialize(ServiceExtensionContext context) { |
| 88 | - var config = context.getConfig(EDC_DATASOURCE_PREFIX); | |
| 89 | - | |
| 90 | - var namedConnectionPools = createConnectionPools(config); | |
| 91 | - | |
| 92 | - for (var entry : namedConnectionPools.entrySet()) { | |
| 93 | - var dataSourceName = entry.getKey(); | |
| 94 | - var commonsConnectionPool = entry.getValue(); | |
| 95 | - commonsConnectionPools.add(commonsConnectionPool); | |
| 96 | - var connectionPoolDataSource = new ConnectionPoolDataSource(commonsConnectionPool); | |
| 94 | + context.getConfig(EDC_DATASOURCE_PREFIX).partition().forEach(config -> { | |
| 95 | + var dataSourceName = config.currentNode(); | |
| 96 | + var dataSource = createDataSource(config); | |
| 97 | + var connectionPool = createConnectionPool(dataSource, config); | |
| 98 | + commonsConnectionPools.add(connectionPool); | |
| 99 | + var connectionPoolDataSource = new ConnectionPoolDataSource(connectionPool); | |
| 97 | 100 | dataSourceRegistry.register(dataSourceName, connectionPoolDataSource); |
| 98 | - } | |
| 101 | + }); | |
| 99 | 102 | } |
| 100 | 103 | |
| 101 | 104 | @Override |
| @@ -103,88 +106,51 @@ | ||
| 103 | 106 | commonsConnectionPools.forEach(CommonsConnectionPool::close); |
| 104 | 107 | } |
| 105 | 108 | |
| 106 | - public List<CommonsConnectionPool> getCommonsConnectionPools() { | |
| 107 | - return commonsConnectionPools; | |
| 108 | - } | |
| 109 | - | |
| 110 | - private @NotNull Supplier<@Nullable String> readFromConfig(Config config, String value) { | |
| 111 | - return () -> { | |
| 112 | - var entry = EDC_DATASOURCE_PREFIX + "." + config.currentNode() + "." + value; | |
| 113 | - monitor.warning("Database configuration value '%s' not found in vault, will fall back to Config. Please consider putting database configuration into the vault.".formatted(entry)); | |
| 114 | - return config.getString(value, null); | |
| 115 | - }; | |
| 116 | - } | |
| 117 | - | |
| 118 | - private void setIfProvidedString(String key, Consumer<String> setter, Config config) { | |
| 119 | - setIfProvided(key, setter, config::getString); | |
| 120 | - } | |
| 121 | - | |
| 122 | - private void setIfProvidedBoolean(String key, Consumer<Boolean> setter, Config config) { | |
| 123 | - setIfProvided(key, setter, config::getBoolean); | |
| 124 | - } | |
| 125 | - | |
| 126 | - private void setIfProvidedInt(String key, Consumer<Integer> setter, Config config) { | |
| 127 | - setIfProvided(key, setter, config::getInteger); | |
| 128 | - } | |
| 129 | - | |
| 130 | - private <T> void setIfProvided(String key, Consumer<T> setter, BiFunction<String, T, T> getter) { | |
| 131 | - var value = getter.apply(key, null); | |
| 132 | - if (value != null) { | |
| 133 | - setter.accept(value); | |
| 134 | - } | |
| 135 | - } | |
| 136 | - | |
| 137 | - private Map<String, CommonsConnectionPool> createConnectionPools(Config parent) { | |
| 138 | - Map<String, CommonsConnectionPool> commonsConnectionPools = new HashMap<>(); | |
| 139 | - for (var config : parent.partition().toList()) { | |
| 140 | - var dataSourceName = config.currentNode(); | |
| 141 | - | |
| 142 | - var dataSource = createDataSource(config); | |
| 143 | - | |
| 144 | - var commonsConnectionPool = createConnectionPool(dataSource, config); | |
| 145 | - commonsConnectionPools.put(dataSourceName, commonsConnectionPool); | |
| 146 | - } | |
| 147 | - return commonsConnectionPools; | |
| 148 | - } | |
| 149 | - | |
| 150 | 109 | private DataSource createDataSource(Config config) { |
| 151 | 110 | var rootPath = EDC_DATASOURCE_PREFIX + "." + config.currentNode(); |
| 152 | 111 | |
| 153 | - // read values from the vault first, fall back to config | |
| 154 | - var urlProperty = rootPath + "." + URL; | |
| 155 | - var jdbcUrl = ofNullable(vault.resolveSecret(urlProperty)).orElseGet(readFromConfig(config, URL)); | |
| 156 | - | |
| 157 | - if (jdbcUrl == null) { | |
| 158 | - throw new EdcException("Mandatory config '%s' not found. Please provide a value for the '%s' property, either as a secret in the vault or an application property.".formatted(urlProperty, urlProperty)); | |
| 159 | - } | |
| 160 | - | |
| 161 | - var jdbcUser = ofNullable(vault.resolveSecret(rootPath + "." + USER)) | |
| 162 | - .orElseGet(readFromConfig(config, USER)); | |
| 163 | - var jdbcPassword = ofNullable(vault.resolveSecret(rootPath + "." + PASSWORD)) | |
| 164 | - .orElseGet(readFromConfig(config, PASSWORD)); | |
| 112 | + var jdbcUrl = getSecretOrSetting(rootPath, URL, config) | |
| 113 | + .orElseThrow(() -> new EdcException("Mandatory url for datasource '%s' not found. Please provide a value for it, either as a secret in the vault or an application property.".formatted(config.currentNode()))); | |
| 114 | + var jdbcUser = getSecretOrSetting(rootPath, USER, config); | |
| 115 | + var jdbcPassword = getSecretOrSetting(rootPath, PASSWORD, config); | |
| 165 | 116 | |
| 166 | 117 | var properties = new Properties(); |
| 167 | 118 | properties.putAll(config.getRelativeEntries()); |
| 168 | 119 | |
| 169 | - // only set if not-null, otherwise Properties#add throws a NPE | |
| 170 | - ofNullable(jdbcUser).ifPresent(u -> properties.put(USER, u)); | |
| 171 | - ofNullable(jdbcPassword).ifPresent(p -> properties.put(PASSWORD, p)); | |
| 120 | + jdbcUser.ifPresent(u -> properties.put(USER, u)); | |
| 121 | + jdbcPassword.ifPresent(p -> properties.put(PASSWORD, p)); | |
| 172 | 122 | |
| 173 | 123 | return new ConnectionFactoryDataSource(connectionFactory, jdbcUrl, properties); |
| 174 | 124 | } |
| 175 | 125 | |
| 126 | + private Optional<String> getSecretOrSetting(String rootPath, String key, Config config) { | |
| 127 | + var fullKey = rootPath + "." + key; | |
| 128 | + return ofNullable(vault.resolveSecret(fullKey)) | |
| 129 | + .or(() -> { | |
| 130 | + monitor.warning("Datasource configuration value '%s' not found in vault, will fall back to Config. Please consider putting datasource configuration into the vault.".formatted(fullKey)); | |
| 131 | + return Optional.ofNullable(config.getString(key, null)); | |
| 132 | + }); | |
| 133 | + } | |
| 134 | + | |
| 176 | 135 | private CommonsConnectionPool createConnectionPool(DataSource unPooledDataSource, Config config) { |
| 177 | 136 | var builder = CommonsConnectionPoolConfig.Builder.newInstance(); |
| 178 | 137 | |
| 179 | - setIfProvidedInt(POOL_CONNECTIONS_MAX_IDLE, builder::maxIdleConnections, config); | |
| 180 | - setIfProvidedInt(POOL_CONNECTIONS_MAX_TOTAL, builder::maxTotalConnections, config); | |
| 181 | - setIfProvidedInt(POOL_CONNECTIONS_MIN_IDLE, builder::minIdleConnections, config); | |
| 182 | - setIfProvidedBoolean(POOL_CONNECTION_TEST_ON_BORROW, builder::testConnectionOnBorrow, config); | |
| 183 | - setIfProvidedBoolean(POOL_CONNECTION_TEST_ON_CREATE, builder::testConnectionOnCreate, config); | |
| 184 | - setIfProvidedBoolean(POOL_CONNECTION_TEST_ON_RETURN, builder::testConnectionOnReturn, config); | |
| 185 | - setIfProvidedBoolean(POOL_CONNECTION_TEST_WHILE_IDLE, builder::testConnectionWhileIdle, config); | |
| 186 | - setIfProvidedString(POOL_CONNECTION_TEST_QUERY, builder::testQuery, config); | |
| 138 | + setIfProvided(POOL_CONNECTIONS_MAX_IDLE, config::getInteger, builder::maxIdleConnections); | |
| 139 | + setIfProvided(POOL_CONNECTIONS_MAX_TOTAL, config::getInteger, builder::maxTotalConnections); | |
| 140 | + setIfProvided(POOL_CONNECTIONS_MIN_IDLE, config::getInteger, builder::minIdleConnections); | |
| 141 | + setIfProvided(POOL_CONNECTION_TEST_ON_BORROW, config::getBoolean, builder::testConnectionOnBorrow); | |
| 142 | + setIfProvided(POOL_CONNECTION_TEST_ON_CREATE, config::getBoolean, builder::testConnectionOnCreate); | |
| 143 | + setIfProvided(POOL_CONNECTION_TEST_ON_RETURN, config::getBoolean, builder::testConnectionOnReturn); | |
| 144 | + setIfProvided(POOL_CONNECTION_TEST_WHILE_IDLE, config::getBoolean, builder::testConnectionWhileIdle); | |
| 145 | + setIfProvided(POOL_CONNECTION_TEST_QUERY, config::getString, builder::testQuery); | |
| 187 | 146 | |
| 188 | 147 | return new CommonsConnectionPool(unPooledDataSource, builder.build(), monitor); |
| 189 | 148 | } |
| 149 | + | |
| 150 | + private <T> void setIfProvided(String key, BiFunction<String, T, T> getter, Consumer<T> setter) { | |
| 151 | + var value = getter.apply(key, null); | |
| 152 | + if (value != null) { | |
| 153 | + setter.accept(value); | |
| 154 | + } | |
| 155 | + } | |
| 190 | 156 | } |
modified extensions/common/sql/sql-pool/sql-pool-apache-commons/src/test/java/org/eclipse/edc/sql/pool/commons/CommonsConnectionPoolServiceExtensionTest.java +17 −19
| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | import org.eclipse.edc.spi.EdcException; |
| 21 | 21 | import org.eclipse.edc.spi.security.Vault; |
| 22 | 22 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| 23 | -import org.eclipse.edc.spi.system.configuration.Config; | |
| 24 | 23 | import org.eclipse.edc.spi.system.configuration.ConfigFactory; |
| 25 | 24 | import org.eclipse.edc.sql.ConnectionFactory; |
| 25 | +import org.eclipse.edc.sql.datasource.ConnectionPoolDataSource; | |
| 26 | 26 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 27 | 27 | import org.junit.jupiter.api.BeforeEach; |
| 28 | 28 | import org.junit.jupiter.api.Test; |
| @@ -32,6 +32,7 @@ | ||
| 32 | 32 | import org.junit.jupiter.params.provider.Arguments; |
| 33 | 33 | import org.junit.jupiter.params.provider.ArgumentsProvider; |
| 34 | 34 | import org.junit.jupiter.params.provider.ArgumentsSource; |
| 35 | +import org.mockito.ArgumentCaptor; | |
| 35 | 36 | |
| 36 | 37 | import java.util.Map; |
| 37 | 38 | import java.util.stream.Collectors; |
| @@ -39,6 +40,7 @@ | ||
| 39 | 40 | |
| 40 | 41 | import static org.assertj.core.api.Assertions.assertThat; |
| 41 | 42 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 43 | +import static org.assertj.core.api.InstanceOfAssertFactories.type; | |
| 42 | 44 | import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.EDC_DATASOURCE_PREFIX; |
| 43 | 45 | import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTIONS_MAX_IDLE; |
| 44 | 46 | import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTIONS_MAX_TOTAL; |
| @@ -48,14 +50,12 @@ | ||
| 48 | 50 | import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTION_TEST_ON_RETURN; |
| 49 | 51 | import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTION_TEST_QUERY; |
| 50 | 52 | import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTION_TEST_WHILE_IDLE; |
| 51 | -import static org.mockito.ArgumentMatchers.any; | |
| 52 | 53 | import static org.mockito.ArgumentMatchers.argThat; |
| 53 | 54 | import static org.mockito.ArgumentMatchers.eq; |
| 54 | 55 | import static org.mockito.Mockito.mock; |
| 55 | 56 | import static org.mockito.Mockito.verify; |
| 56 | 57 | import static org.mockito.Mockito.when; |
| 57 | 58 | |
| 58 | -//sometimes hangs and causes the test to never finish. | |
| 59 | 59 | @ExtendWith(DependencyInjectionExtension.class) |
| 60 | 60 | class CommonsConnectionPoolServiceExtensionTest { |
| 61 | 61 | private static final String DS_1_NAME = "ds1"; |
| @@ -74,21 +74,16 @@ | ||
| 74 | 74 | void initialize_withConfig(Map<String, String> configuration, ThrowingConsumer<CommonsConnectionPoolConfig> checker, |
| 75 | 75 | boolean isEnv, |
| 76 | 76 | CommonsConnectionPoolServiceExtension extension, ServiceExtensionContext context) { |
| 77 | - Config config; | |
| 78 | - if (isEnv) { | |
| 79 | - config = ConfigFactory.fromEnvironment(configuration); | |
| 80 | - } else { | |
| 81 | - config = ConfigFactory.fromMap(configuration); | |
| 82 | - } | |
| 77 | + var config = isEnv ? ConfigFactory.fromEnvironment(configuration) : ConfigFactory.fromMap(configuration); | |
| 83 | 78 | when(context.getConfig(EDC_DATASOURCE_PREFIX)).thenReturn(config); |
| 84 | 79 | |
| 85 | 80 | extension.initialize(context); |
| 86 | 81 | |
| 87 | - verify(dataSourceRegistry).register(eq(DS_1_NAME), any()); | |
| 88 | - | |
| 89 | - assertThat(extension.getCommonsConnectionPools()).hasSize(1).first() | |
| 90 | - .extracting(CommonsConnectionPool::getPoolConfig) | |
| 91 | - .satisfies(checker); | |
| 82 | + var captor = ArgumentCaptor.forClass(ConnectionPoolDataSource.class); | |
| 83 | + verify(dataSourceRegistry).register(eq(DS_1_NAME), captor.capture()); | |
| 84 | + assertThat(captor.getAllValues()).hasSize(1).first() | |
| 85 | + .extracting("connectionPool").asInstanceOf(type(CommonsConnectionPool.class)) | |
| 86 | + .extracting(CommonsConnectionPool::getPoolConfig).satisfies(checker); | |
| 92 | 87 | } |
| 93 | 88 | |
| 94 | 89 | @Test |
| @@ -103,8 +98,10 @@ | ||
| 103 | 98 | |
| 104 | 99 | extension.initialize(context); |
| 105 | 100 | |
| 106 | - verify(dataSourceRegistry).register(eq(DS_1_NAME), any()); | |
| 107 | - assertThat(extension.getCommonsConnectionPools()).hasSize(1).first() | |
| 101 | + var captor = ArgumentCaptor.forClass(ConnectionPoolDataSource.class); | |
| 102 | + verify(dataSourceRegistry).register(eq(DS_1_NAME), captor.capture()); | |
| 103 | + assertThat(captor.getAllValues()).hasSize(1).first() | |
| 104 | + .extracting("connectionPool").asInstanceOf(type(CommonsConnectionPool.class)) | |
| 108 | 105 | .satisfies(pool -> { |
| 109 | 106 | assertThatThrownBy(pool::getConnection).isInstanceOf(EdcException.class); //we need this only to invoke the connection factory |
| 110 | 107 | verify(connectionFactory).create(eq("jdbc://whatever"), argThat(p -> |
| @@ -129,8 +126,10 @@ | ||
| 129 | 126 | |
| 130 | 127 | extension.initialize(context); |
| 131 | 128 | |
| 132 | - verify(dataSourceRegistry).register(eq(DS_1_NAME), any()); | |
| 133 | - assertThat(extension.getCommonsConnectionPools()).hasSize(1).first() | |
| 129 | + var captor = ArgumentCaptor.forClass(ConnectionPoolDataSource.class); | |
| 130 | + verify(dataSourceRegistry).register(eq(DS_1_NAME), captor.capture()); | |
| 131 | + assertThat(captor.getAllValues()).hasSize(1).first() | |
| 132 | + .extracting("connectionPool").asInstanceOf(type(CommonsConnectionPool.class)) | |
| 134 | 133 | .satisfies(pool -> { |
| 135 | 134 | assertThatThrownBy(pool::getConnection).isInstanceOf(EdcException.class); //we need this only to invoke the connection factory |
| 136 | 135 | verify(connectionFactory).create(eq("jdbc://whatever"), argThat(p -> |
| @@ -140,7 +139,6 @@ | ||
| 140 | 139 | }); |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | - | |
| 144 | 142 | static class ConfigProvider implements ArgumentsProvider { |
| 145 | 143 | |
| 146 | 144 | private final Map<String, String> defaultConfig = Map.of(DS_1_NAME + ".url", DS_1_NAME); |
modified extensions/common/store/sql/edr-index-sql/src/main/java/org/eclipse/edc/edr/store/index/SqlEndpointDataReferenceEntryIndexExtension.java +6 −5
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | import org.eclipse.edc.spi.types.TypeManager; |
| 28 | 28 | import org.eclipse.edc.sql.QueryExecutor; |
| 29 | 29 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 30 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 30 | 31 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 31 | 32 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 32 | 33 | |
| @@ -34,12 +35,12 @@ | ||
| 34 | 35 | @Extension(value = "SQL edr entry store") |
| 35 | 36 | public class SqlEndpointDataReferenceEntryIndexExtension implements ServiceExtension { |
| 36 | 37 | |
| 37 | - /** | |
| 38 | - * Name of the datasource to use for accessing edr entries. | |
| 39 | - */ | |
| 40 | - @Setting(required = true) | |
| 38 | + @Deprecated(since = "0.8.1") | |
| 41 | 39 | public static final String DATASOURCE_SETTING_NAME = "edc.datasource.edr.name"; |
| 42 | 40 | |
| 41 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 42 | + public static final String DATASOURCE_NAME = "edc.sql.store.edr.datasource"; | |
| 43 | + | |
| 43 | 44 | @Inject |
| 44 | 45 | private DataSourceRegistry dataSourceRegistry; |
| 45 | 46 | |
| @@ -60,7 +61,7 @@ | ||
| 60 | 61 | |
| 61 | 62 | @Override |
| 62 | 63 | public void initialize(ServiceExtensionContext context) { |
| 63 | - var dataSourceName = context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 64 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 64 | 65 | |
| 65 | 66 | var sqlStore = new SqlEndpointDataReferenceEntryIndex(dataSourceRegistry, dataSourceName, transactionContext, typeManager.getMapper(), |
| 66 | 67 | getStatementImpl(), queryExecutor); |
modified extensions/common/store/sql/edr-index-sql/src/test/java/org/eclipse/edc/edr/store/index/sql/SqlEndpointDataReferenceEntryIndexExtensionTest.java +3 −4
| @@ -22,14 +22,14 @@ | ||
| 22 | 22 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| 23 | 23 | import org.eclipse.edc.spi.system.configuration.Config; |
| 24 | 24 | import org.eclipse.edc.spi.types.TypeManager; |
| 25 | -import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; | |
| 26 | 25 | import org.junit.jupiter.api.BeforeEach; |
| 27 | 26 | import org.junit.jupiter.api.Test; |
| 28 | 27 | import org.junit.jupiter.api.extension.ExtendWith; |
| 29 | 28 | |
| 30 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| 31 | -import static org.eclipse.edc.edr.store.index.SqlEndpointDataReferenceEntryIndexExtension.DATASOURCE_SETTING_NAME; | |
| 30 | +import static org.eclipse.edc.edr.store.index.SqlEndpointDataReferenceEntryIndexExtension.DATASOURCE_NAME; | |
| 32 | 31 | import static org.mockito.ArgumentMatchers.any; |
| 32 | +import static org.mockito.ArgumentMatchers.eq; | |
| 33 | 33 | import static org.mockito.Mockito.mock; |
| 34 | 34 | import static org.mockito.Mockito.verify; |
| 35 | 35 | import static org.mockito.Mockito.when; |
| @@ -37,7 +37,6 @@ | ||
| 37 | 37 | @ExtendWith(DependencyInjectionExtension.class) |
| 38 | 38 | public class SqlEndpointDataReferenceEntryIndexExtensionTest { |
| 39 | 39 | |
| 40 | - | |
| 41 | 40 | @BeforeEach |
| 42 | 41 | void setUp(ServiceExtensionContext context) { |
| 43 | 42 | context.registerService(TypeManager.class, new JacksonTypeManager()); |
| @@ -54,6 +53,6 @@ | ||
| 54 | 53 | var service = context.getService(EndpointDataReferenceEntryIndex.class); |
| 55 | 54 | assertThat(service).isInstanceOf(SqlEndpointDataReferenceEntryIndex.class); |
| 56 | 55 | |
| 57 | - verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 56 | + verify(config).getString(eq(DATASOURCE_NAME), any()); | |
| 58 | 57 | } |
| 59 | 58 | } |
modified extensions/control-plane/store/sql/asset-index-sql/README.md +0 −6
| @@ -37,12 +37,6 @@ | ||
| 37 | 37 | ``` |
| 38 | 38 | --> |
| 39 | 39 | |
| 40 | -## Configuration | |
| 41 | - | |
| 42 | -| Key | Description | Mandatory | | |
| 43 | -|:--------------------------|:----------------------------------|-----------| | |
| 44 | -| edc.datasource.asset.name | Datasource used by this extension | X | | |
| 45 | - | |
| 46 | 40 | ## Migrate from 0.3.1 to 0.3.2 |
| 47 | 41 | |
| 48 | 42 | This table structure has been changed, from 3 tables (one for the asset, one for properties and one for data address) to |
modified extensions/control-plane/store/sql/asset-index-sql/src/main/java/org/eclipse/edc/connector/controlplane/store/sql/assetindex/SqlAssetIndexServiceExtension.java +6 −5
| @@ -28,6 +28,7 @@ | ||
| 28 | 28 | import org.eclipse.edc.spi.types.TypeManager; |
| 29 | 29 | import org.eclipse.edc.sql.QueryExecutor; |
| 30 | 30 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 31 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 31 | 32 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 32 | 33 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 33 | 34 | |
| @@ -35,12 +36,12 @@ | ||
| 35 | 36 | @Extension(value = "SQL asset index") |
| 36 | 37 | public class SqlAssetIndexServiceExtension implements ServiceExtension { |
| 37 | 38 | |
| 38 | - /** | |
| 39 | - * Name of the datasource to use for accessing assets. | |
| 40 | - */ | |
| 41 | - @Setting(required = true) | |
| 39 | + @Deprecated(since = "0.8.1") | |
| 42 | 40 | public static final String DATASOURCE_SETTING_NAME = "edc.datasource.asset.name"; |
| 43 | 41 | |
| 42 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 43 | + public static final String DATASOURCE_NAME = "edc.sql.store.asset.datasource"; | |
| 44 | + | |
| 44 | 45 | @Inject |
| 45 | 46 | private DataSourceRegistry dataSourceRegistry; |
| 46 | 47 | |
| @@ -61,7 +62,7 @@ | ||
| 61 | 62 | |
| 62 | 63 | @Override |
| 63 | 64 | public void initialize(ServiceExtensionContext context) { |
| 64 | - var dataSourceName = context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 65 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 65 | 66 | |
| 66 | 67 | var sqlAssetLoader = new SqlAssetIndex(dataSourceRegistry, dataSourceName, transactionContext, typeManager.getMapper(), getDialect(), queryExecutor); |
| 67 | 68 |
modified extensions/control-plane/store/sql/asset-index-sql/src/test/java/org/eclipse/edc/connector/controlplane/store/sql/assetindex/SqlAssetIndexServiceExtensionTest.java +3 −3
| @@ -21,14 +21,14 @@ | ||
| 21 | 21 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| 22 | 22 | import org.eclipse.edc.spi.system.configuration.Config; |
| 23 | 23 | import org.eclipse.edc.spi.types.TypeManager; |
| 24 | -import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; | |
| 25 | 24 | import org.junit.jupiter.api.BeforeEach; |
| 26 | 25 | import org.junit.jupiter.api.Test; |
| 27 | 26 | import org.junit.jupiter.api.extension.ExtendWith; |
| 28 | 27 | |
| 29 | 28 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | -import static org.eclipse.edc.connector.controlplane.store.sql.assetindex.SqlAssetIndexServiceExtension.DATASOURCE_SETTING_NAME; | |
| 29 | +import static org.eclipse.edc.connector.controlplane.store.sql.assetindex.SqlAssetIndexServiceExtension.DATASOURCE_NAME; | |
| 31 | 30 | import static org.mockito.ArgumentMatchers.any; |
| 31 | +import static org.mockito.ArgumentMatchers.eq; | |
| 32 | 32 | import static org.mockito.Mockito.mock; |
| 33 | 33 | import static org.mockito.Mockito.verify; |
| 34 | 34 | import static org.mockito.Mockito.when; |
| @@ -55,6 +55,6 @@ | ||
| 55 | 55 | var dataAddressResolver = context.getService(DataAddressResolver.class); |
| 56 | 56 | assertThat(dataAddressResolver).isInstanceOf(SqlAssetIndex.class); |
| 57 | 57 | |
| 58 | - verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 58 | + verify(config).getString(eq(DATASOURCE_NAME), any()); | |
| 59 | 59 | } |
| 60 | 60 | } |
modified extensions/control-plane/store/sql/contract-definition-store-sql/README.md +0 −6
| @@ -10,12 +10,6 @@ | ||
| 10 | 10 | |
| 11 | 11 |  |
| 12 | 12 | |
| 13 | -## Configuration | |
| 14 | - | |
| 15 | -| Key | Description | Mandatory | | |
| 16 | -|:---------------------------------------|:----------------------------------|-----------| | |
| 17 | -| edc.datasource.contractdefinition.name | Datasource used by this extension | X | | |
| 18 | - | |
| 19 | 13 | ## Create a flexible query API to accommodate `QuerySpec` |
| 20 | 14 | |
| 21 | 15 | _For the first version, only the `limit` and `offset` arguments from the `QuerySpec` will be used._ |
modified extensions/control-plane/store/sql/contract-definition-store-sql/src/main/java/org/eclipse/edc/connector/controlplane/store/sql/contractdefinition/SqlContractDefinitionStoreExtension.java +6 −5
| @@ -28,6 +28,7 @@ | ||
| 28 | 28 | import org.eclipse.edc.spi.types.TypeManager; |
| 29 | 29 | import org.eclipse.edc.sql.QueryExecutor; |
| 30 | 30 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 31 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 31 | 32 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 32 | 33 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 33 | 34 | |
| @@ -35,12 +36,12 @@ | ||
| 35 | 36 | @Extension(value = "SQL contract definition store") |
| 36 | 37 | public class SqlContractDefinitionStoreExtension implements ServiceExtension { |
| 37 | 38 | |
| 38 | - /** | |
| 39 | - * Name of the datasource to use for accessing contract definitions. | |
| 40 | - */ | |
| 41 | - @Setting(required = true) | |
| 39 | + @Deprecated(since = "0.8.1") | |
| 42 | 40 | public static final String DATASOURCE_SETTING_NAME = "edc.datasource.contractdefinition.name"; |
| 43 | 41 | |
| 42 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 43 | + public static final String DATASOURCE_NAME = "edc.sql.store.contractdefinition.datasource"; | |
| 44 | + | |
| 44 | 45 | @Inject |
| 45 | 46 | private DataSourceRegistry dataSourceRegistry; |
| 46 | 47 | |
| @@ -61,7 +62,7 @@ | ||
| 61 | 62 | |
| 62 | 63 | @Override |
| 63 | 64 | public void initialize(ServiceExtensionContext context) { |
| 64 | - var dataSourceName = context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 65 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 65 | 66 | |
| 66 | 67 | var sqlContractDefinitionStore = new SqlContractDefinitionStore(dataSourceRegistry, dataSourceName, transactionContext, |
| 67 | 68 | getStatementImpl(), typeManager.getMapper(), queryExecutor); |
modified extensions/control-plane/store/sql/contract-definition-store-sql/src/test/java/org/eclipse/edc/connector/controlplane/store/sql/contractdefinition/SqlContractDefinitionStoreExtensionTest.java +3 −4
| @@ -20,14 +20,14 @@ | ||
| 20 | 20 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| 21 | 21 | import org.eclipse.edc.spi.system.configuration.Config; |
| 22 | 22 | import org.eclipse.edc.spi.types.TypeManager; |
| 23 | -import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; | |
| 24 | 23 | import org.junit.jupiter.api.BeforeEach; |
| 25 | 24 | import org.junit.jupiter.api.Test; |
| 26 | 25 | import org.junit.jupiter.api.extension.ExtendWith; |
| 27 | 26 | |
| 28 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
| 29 | -import static org.eclipse.edc.connector.controlplane.store.sql.contractdefinition.SqlContractDefinitionStoreExtension.DATASOURCE_SETTING_NAME; | |
| 28 | +import static org.eclipse.edc.connector.controlplane.store.sql.contractdefinition.SqlContractDefinitionStoreExtension.DATASOURCE_NAME; | |
| 30 | 29 | import static org.mockito.ArgumentMatchers.any; |
| 30 | +import static org.mockito.ArgumentMatchers.eq; | |
| 31 | 31 | import static org.mockito.Mockito.mock; |
| 32 | 32 | import static org.mockito.Mockito.verify; |
| 33 | 33 | import static org.mockito.Mockito.when; |
| @@ -35,7 +35,6 @@ | ||
| 35 | 35 | @ExtendWith(DependencyInjectionExtension.class) |
| 36 | 36 | public class SqlContractDefinitionStoreExtensionTest { |
| 37 | 37 | |
| 38 | - | |
| 39 | 38 | @BeforeEach |
| 40 | 39 | void setUp(ServiceExtensionContext context) { |
| 41 | 40 | context.registerService(TypeManager.class, new JacksonTypeManager()); |
| @@ -52,6 +51,6 @@ | ||
| 52 | 51 | var service = context.getService(ContractDefinitionStore.class); |
| 53 | 52 | assertThat(service).isInstanceOf(ContractDefinitionStore.class); |
| 54 | 53 | |
| 55 | - verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 54 | + verify(config).getString(eq(DATASOURCE_NAME), any()); | |
| 56 | 55 | } |
| 57 | 56 | } |
modified extensions/control-plane/store/sql/contract-negotiation-store-sql/src/main/java/org/eclipse/edc/connector/controlplane/store/sql/contractnegotiation/SqlContractNegotiationStoreExtension.java +10 −3
| @@ -21,11 +21,13 @@ | ||
| 21 | 21 | import org.eclipse.edc.runtime.metamodel.annotation.Extension; |
| 22 | 22 | import org.eclipse.edc.runtime.metamodel.annotation.Inject; |
| 23 | 23 | import org.eclipse.edc.runtime.metamodel.annotation.Provides; |
| 24 | +import org.eclipse.edc.runtime.metamodel.annotation.Setting; | |
| 24 | 25 | import org.eclipse.edc.spi.system.ServiceExtension; |
| 25 | 26 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| 26 | 27 | import org.eclipse.edc.spi.types.TypeManager; |
| 27 | 28 | import org.eclipse.edc.sql.QueryExecutor; |
| 28 | 29 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 30 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 29 | 31 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 30 | 32 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 31 | 33 | |
| @@ -35,7 +37,11 @@ | ||
| 35 | 37 | @Extension(value = "SQL contract negotiation store") |
| 36 | 38 | public class SqlContractNegotiationStoreExtension implements ServiceExtension { |
| 37 | 39 | |
| 38 | - public static final String DATASOURCE_NAME_SETTING = "edc.datasource.contractnegotiation.name"; | |
| 40 | + @Deprecated(since = "0.8.1") | |
| 41 | + public static final String DATASOURCE_SETTING_NAME = "edc.datasource.contractnegotiation.name"; | |
| 42 | + | |
| 43 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 44 | + public static final String DATASOURCE_NAME = "edc.sql.store.contractnegotiation.datasource"; | |
| 39 | 45 | |
| 40 | 46 | @Inject |
| 41 | 47 | private DataSourceRegistry dataSourceRegistry; |
| @@ -60,7 +66,8 @@ | ||
| 60 | 66 | |
| 61 | 67 | @Override |
| 62 | 68 | public void initialize(ServiceExtensionContext context) { |
| 63 | - var dataSourceName = getDataSourceName(context); | |
| 69 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 70 | + | |
| 64 | 71 | var sqlStore = new SqlContractNegotiationStore(dataSourceRegistry, dataSourceName, trxContext, |
| 65 | 72 | typeManager.getMapper(), getStatementImpl(), context.getRuntimeId(), clock, queryExecutor); |
| 66 | 73 | context.registerService(ContractNegotiationStore.class, sqlStore); |
| @@ -76,6 +83,6 @@ | ||
| 76 | 83 | } |
| 77 | 84 | |
| 78 | 85 | private String getDataSourceName(ServiceExtensionContext context) { |
| 79 | - return context.getConfig().getString(DATASOURCE_NAME_SETTING, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 86 | + return context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 80 | 87 | } |
| 81 | 88 | } |
modified extensions/control-plane/store/sql/contract-negotiation-store-sql/src/test/java/org/eclipse/edc/connector/controlplane/store/sql/contractnegotiation/SqlContractNegotiationStoreExtensionTest.java +6 −3
| @@ -33,7 +33,10 @@ | ||
| 33 | 33 | |
| 34 | 34 | import static org.assertj.core.api.Assertions.assertThat; |
| 35 | 35 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 36 | -import static org.eclipse.edc.connector.controlplane.store.sql.contractnegotiation.SqlContractNegotiationStoreExtension.DATASOURCE_NAME_SETTING; | |
| 36 | +import static org.eclipse.edc.connector.controlplane.store.sql.contractnegotiation.SqlContractNegotiationStoreExtension.DATASOURCE_NAME; | |
| 37 | +import static org.eclipse.edc.connector.controlplane.store.sql.contractnegotiation.SqlContractNegotiationStoreExtension.DATASOURCE_SETTING_NAME; | |
| 38 | +import static org.mockito.ArgumentMatchers.any; | |
| 39 | +import static org.mockito.ArgumentMatchers.eq; | |
| 37 | 40 | import static org.mockito.Mockito.mock; |
| 38 | 41 | import static org.mockito.Mockito.verify; |
| 39 | 42 | import static org.mockito.Mockito.when; |
| @@ -47,7 +50,7 @@ | ||
| 47 | 50 | void initialize(ServiceExtensionContext context, ObjectFactory factory) { |
| 48 | 51 | var config = mock(Config.class); |
| 49 | 52 | when(context.getConfig()).thenReturn(config); |
| 50 | - when(config.getString(DATASOURCE_NAME_SETTING, DataSourceRegistry.DEFAULT_DATASOURCE)).thenReturn("test"); | |
| 53 | + when(config.getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE)).thenReturn("test"); | |
| 51 | 54 | |
| 52 | 55 | context.registerService(DataSourceRegistry.class, mock(DataSourceRegistry.class)); |
| 53 | 56 | context.registerService(TransactionContext.class, mock(TransactionContext.class)); |
| @@ -61,7 +64,7 @@ | ||
| 61 | 64 | var service = context.getService(ContractNegotiationStore.class); |
| 62 | 65 | assertThat(service).isInstanceOf(SqlContractNegotiationStore.class); |
| 63 | 66 | assertThat(service).extracting("statements").isInstanceOf(BaseSqlDialectStatements.class); |
| 64 | - verify(config).getString(DATASOURCE_NAME_SETTING, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 67 | + verify(config).getString(eq(DATASOURCE_NAME), any()); | |
| 65 | 68 | |
| 66 | 69 | } |
| 67 | 70 |
modified extensions/control-plane/store/sql/policy-definition-store-sql/README.md +0 −6
| @@ -34,9 +34,3 @@ | ||
| 34 | 34 | @enduml |
| 35 | 35 | ``` |
| 36 | 36 | --> |
| 37 | - | |
| 38 | -## Configuration | |
| 39 | - | |
| 40 | -| Key | Description | Mandatory | | |
| 41 | -|:---------------------------|:----------------------------------|-----------| | |
| 42 | -| edc.datasource.policy.name | Datasource used by this extension | X | |
modified extensions/control-plane/store/sql/policy-definition-store-sql/src/main/java/org/eclipse/edc/connector/controlplane/store/sql/policydefinition/SqlPolicyStoreExtension.java +7 −2
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | import org.eclipse.edc.spi.types.TypeManager; |
| 28 | 28 | import org.eclipse.edc.sql.QueryExecutor; |
| 29 | 29 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 30 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 30 | 31 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 31 | 32 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 32 | 33 | |
| @@ -34,9 +35,12 @@ | ||
| 34 | 35 | @Extension("SQL policy store") |
| 35 | 36 | public class SqlPolicyStoreExtension implements ServiceExtension { |
| 36 | 37 | |
| 37 | - @Setting(required = true) | |
| 38 | + @Deprecated(since = "0.8.1") | |
| 38 | 39 | public static final String DATASOURCE_SETTING_NAME = "edc.datasource.policy.name"; |
| 39 | 40 | |
| 41 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 42 | + public static final String DATASOURCE_NAME = "edc.sql.store.policy.datasource"; | |
| 43 | + | |
| 40 | 44 | @Inject |
| 41 | 45 | private DataSourceRegistry dataSourceRegistry; |
| 42 | 46 | |
| @@ -56,7 +60,8 @@ | ||
| 56 | 60 | |
| 57 | 61 | @Override |
| 58 | 62 | public void initialize(ServiceExtensionContext context) { |
| 59 | - var dataSourceName = getDataSourceName(context); | |
| 63 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 64 | + | |
| 60 | 65 | var sqlPolicyStore = new SqlPolicyDefinitionStore(dataSourceRegistry, dataSourceName, transactionContext, |
| 61 | 66 | typeManager.getMapper(), getStatementImpl(), queryExecutor); |
| 62 | 67 |
modified extensions/control-plane/store/sql/policy-definition-store-sql/src/test/java/org/eclipse/edc/connector/controlplane/store/sql/policydefinition/SqlPolicyDefinitionStoreExtensionTest.java +3 −3
| @@ -21,14 +21,14 @@ | ||
| 21 | 21 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| 22 | 22 | import org.eclipse.edc.spi.system.configuration.Config; |
| 23 | 23 | import org.eclipse.edc.spi.types.TypeManager; |
| 24 | -import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; | |
| 25 | 24 | import org.junit.jupiter.api.BeforeEach; |
| 26 | 25 | import org.junit.jupiter.api.Test; |
| 27 | 26 | import org.junit.jupiter.api.extension.ExtendWith; |
| 28 | 27 | |
| 29 | 28 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | -import static org.eclipse.edc.connector.controlplane.store.sql.policydefinition.SqlPolicyStoreExtension.DATASOURCE_SETTING_NAME; | |
| 29 | +import static org.eclipse.edc.connector.controlplane.store.sql.policydefinition.SqlPolicyStoreExtension.DATASOURCE_NAME; | |
| 31 | 30 | import static org.mockito.ArgumentMatchers.any; |
| 31 | +import static org.mockito.ArgumentMatchers.eq; | |
| 32 | 32 | import static org.mockito.Mockito.mock; |
| 33 | 33 | import static org.mockito.Mockito.verify; |
| 34 | 34 | import static org.mockito.Mockito.when; |
| @@ -53,6 +53,6 @@ | ||
| 53 | 53 | var service = context.getService(PolicyDefinitionStore.class); |
| 54 | 54 | assertThat(service).isInstanceOf(SqlPolicyDefinitionStore.class); |
| 55 | 55 | |
| 56 | - verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 56 | + verify(config).getString(eq(DATASOURCE_NAME), any()); | |
| 57 | 57 | } |
| 58 | 58 | } |
modified extensions/control-plane/store/sql/transfer-process-store-sql/src/main/java/org/eclipse/edc/connector/controlplane/store/sql/transferprocess/SqlTransferProcessStoreExtension.java +8 −6
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | import org.eclipse.edc.spi.types.TypeManager; |
| 28 | 28 | import org.eclipse.edc.sql.QueryExecutor; |
| 29 | 29 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 30 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 30 | 31 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 31 | 32 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 32 | 33 | |
| @@ -36,8 +37,11 @@ | ||
| 36 | 37 | @Extension(value = "SQL transfer process store") |
| 37 | 38 | public class SqlTransferProcessStoreExtension implements ServiceExtension { |
| 38 | 39 | |
| 39 | - @Setting | |
| 40 | - public static final String DATASOURCE_NAME_SETTING = "edc.datasource.transferprocess.name"; | |
| 40 | + @Deprecated(since = "0.8.1") | |
| 41 | + public static final String DATASOURCE_SETTING_NAME = "edc.datasource.transferprocess.name"; | |
| 42 | + | |
| 43 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 44 | + public static final String DATASOURCE_NAME = "edc.sql.store.transferprocess.datasource"; | |
| 41 | 45 | |
| 42 | 46 | @Inject |
| 43 | 47 | private DataSourceRegistry dataSourceRegistry; |
| @@ -60,7 +64,8 @@ | ||
| 60 | 64 | |
| 61 | 65 | @Override |
| 62 | 66 | public void initialize(ServiceExtensionContext context) { |
| 63 | - var dataSourceName = getDataSourceName(context); | |
| 67 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 68 | + | |
| 64 | 69 | var store = new SqlTransferProcessStore(dataSourceRegistry, dataSourceName, trxContext, |
| 65 | 70 | typeManager.getMapper(), getStatementImpl(), context.getRuntimeId(), clock, queryExecutor); |
| 66 | 71 | context.registerService(TransferProcessStore.class, store); |
| @@ -75,7 +80,4 @@ | ||
| 75 | 80 | return statements != null ? statements : new PostgresDialectStatements(); |
| 76 | 81 | } |
| 77 | 82 | |
| 78 | - private String getDataSourceName(ServiceExtensionContext context) { | |
| 79 | - return context.getConfig().getString(DATASOURCE_NAME_SETTING, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 80 | - } | |
| 81 | 83 | } |
modified extensions/control-plane/store/sql/transfer-process-store-sql/src/test/java/org/eclipse/edc/connector/controlplane/store/sql/transferprocess/SqlTransferProcessStoreExtensionTest.java +3 −3
| @@ -21,14 +21,14 @@ | ||
| 21 | 21 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| 22 | 22 | import org.eclipse.edc.spi.system.configuration.Config; |
| 23 | 23 | import org.eclipse.edc.spi.types.TypeManager; |
| 24 | -import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; | |
| 25 | 24 | import org.junit.jupiter.api.BeforeEach; |
| 26 | 25 | import org.junit.jupiter.api.Test; |
| 27 | 26 | import org.junit.jupiter.api.extension.ExtendWith; |
| 28 | 27 | |
| 29 | 28 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | -import static org.eclipse.edc.connector.controlplane.store.sql.transferprocess.SqlTransferProcessStoreExtension.DATASOURCE_NAME_SETTING; | |
| 29 | +import static org.eclipse.edc.connector.controlplane.store.sql.transferprocess.SqlTransferProcessStoreExtension.DATASOURCE_NAME; | |
| 31 | 30 | import static org.mockito.ArgumentMatchers.any; |
| 31 | +import static org.mockito.ArgumentMatchers.eq; | |
| 32 | 32 | import static org.mockito.Mockito.mock; |
| 33 | 33 | import static org.mockito.Mockito.verify; |
| 34 | 34 | import static org.mockito.Mockito.when; |
| @@ -52,6 +52,6 @@ | ||
| 52 | 52 | var service = context.getService(TransferProcessStore.class); |
| 53 | 53 | assertThat(service).isInstanceOf(SqlTransferProcessStore.class); |
| 54 | 54 | |
| 55 | - verify(config).getString(DATASOURCE_NAME_SETTING, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 55 | + verify(config).getString(eq(DATASOURCE_NAME), any()); | |
| 56 | 56 | } |
| 57 | 57 | } |
modified extensions/data-plane-selector/store/sql/data-plane-instance-store-sql/src/main/java/org/eclipse/edc/connector/dataplane/selector/store/sql/SqlDataPlaneInstanceStoreExtension.java +8 −4
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | import org.eclipse.edc.spi.types.TypeManager; |
| 28 | 28 | import org.eclipse.edc.sql.QueryExecutor; |
| 29 | 29 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 30 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 30 | 31 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 31 | 32 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 32 | 33 | |
| @@ -40,8 +41,13 @@ | ||
| 40 | 41 | public class SqlDataPlaneInstanceStoreExtension implements ServiceExtension { |
| 41 | 42 | public static final String NAME = "Sql Data Plane Instance Store"; |
| 42 | 43 | |
| 44 | + @Deprecated(since = "0.8.1") | |
| 43 | 45 | @Setting(value = "Name of the datasource to use for accessing data plane instances") |
| 44 | 46 | public static final String DATASOURCE_SETTING_NAME = "edc.datasource.dataplaneinstance.name"; |
| 47 | + | |
| 48 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 49 | + public static final String DATASOURCE_NAME = "edc.sql.store.dataplaneinstance.datasource"; | |
| 50 | + | |
| 45 | 51 | @Inject |
| 46 | 52 | private DataSourceRegistry dataSourceRegistry; |
| 47 | 53 | |
| @@ -70,7 +76,8 @@ | ||
| 70 | 76 | |
| 71 | 77 | @Provider |
| 72 | 78 | public DataPlaneInstanceStore dataPlaneInstanceStore(ServiceExtensionContext context) { |
| 73 | - var dataSourceName = getDataSourceName(context); | |
| 79 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 80 | + | |
| 74 | 81 | sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "dataplane-instance-schema.sql"); |
| 75 | 82 | return new SqlDataPlaneInstanceStore(dataSourceRegistry, dataSourceName, transactionContext, |
| 76 | 83 | getStatementImpl(), typeManager.getMapper(), queryExecutor, clock, context.getRuntimeId()); |
| @@ -83,7 +90,4 @@ | ||
| 83 | 90 | return statements != null ? statements : new PostgresDataPlaneInstanceStatements(); |
| 84 | 91 | } |
| 85 | 92 | |
| 86 | - private String getDataSourceName(ServiceExtensionContext context) { | |
| 87 | - return context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 88 | - } | |
| 89 | 93 | } |
modified extensions/data-plane-selector/store/sql/data-plane-instance-store-sql/src/test/java/org/eclipse/edc/connector/dataplane/selector/store/sql/SqlDataPlaneInstanceStoreExtensionTest.java +3 −3
| @@ -19,14 +19,14 @@ | ||
| 19 | 19 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| 20 | 20 | import org.eclipse.edc.spi.system.configuration.Config; |
| 21 | 21 | import org.eclipse.edc.spi.types.TypeManager; |
| 22 | -import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; | |
| 23 | 22 | import org.junit.jupiter.api.BeforeEach; |
| 24 | 23 | import org.junit.jupiter.api.Test; |
| 25 | 24 | import org.junit.jupiter.api.extension.ExtendWith; |
| 26 | 25 | |
| 27 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 28 | -import static org.eclipse.edc.connector.dataplane.selector.store.sql.SqlDataPlaneInstanceStoreExtension.DATASOURCE_SETTING_NAME; | |
| 27 | +import static org.eclipse.edc.connector.dataplane.selector.store.sql.SqlDataPlaneInstanceStoreExtension.DATASOURCE_NAME; | |
| 29 | 28 | import static org.mockito.ArgumentMatchers.any; |
| 29 | +import static org.mockito.ArgumentMatchers.eq; | |
| 30 | 30 | import static org.mockito.Mockito.mock; |
| 31 | 31 | import static org.mockito.Mockito.verify; |
| 32 | 32 | import static org.mockito.Mockito.when; |
| @@ -48,6 +48,6 @@ | ||
| 48 | 48 | var store = extension.dataPlaneInstanceStore(context); |
| 49 | 49 | assertThat(store).isInstanceOf(SqlDataPlaneInstanceStore.class); |
| 50 | 50 | |
| 51 | - verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 51 | + verify(config).getString(eq(DATASOURCE_NAME), any()); | |
| 52 | 52 | } |
| 53 | 53 | } |
modified extensions/data-plane/store/sql/accesstokendata-store-sql/src/main/java/org/eclipse/edc/connector/dataplane/store/sql/SqlAccessTokenDataStoreExtension.java +7 −4
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | import org.eclipse.edc.spi.types.TypeManager; |
| 28 | 28 | import org.eclipse.edc.sql.QueryExecutor; |
| 29 | 29 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 30 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 30 | 31 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 31 | 32 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 32 | 33 | |
| @@ -40,9 +41,13 @@ | ||
| 40 | 41 | |
| 41 | 42 | public static final String NAME = "Sql AccessTokenData Store"; |
| 42 | 43 | |
| 44 | + @Deprecated(since = "0.8.1") | |
| 43 | 45 | @Setting(value = "Name of the datasource to use for accessing data plane store") |
| 44 | 46 | private static final String DATASOURCE_SETTING_NAME = "edc.datasource.accesstokendata.name"; |
| 45 | 47 | |
| 48 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 49 | + public static final String DATASOURCE_NAME = "edc.sql.store.accesstokendata.datasource"; | |
| 50 | + | |
| 46 | 51 | @Inject |
| 47 | 52 | private DataSourceRegistry dataSourceRegistry; |
| 48 | 53 | |
| @@ -70,7 +75,8 @@ | ||
| 70 | 75 | |
| 71 | 76 | @Provider |
| 72 | 77 | public AccessTokenDataStore dataPlaneStore(ServiceExtensionContext context) { |
| 73 | - var dataSourceName = getDataSourceName(context); | |
| 78 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 79 | + | |
| 74 | 80 | sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "accesstoken-data-schema.sql"); |
| 75 | 81 | return new SqlAccessTokenDataStore(dataSourceRegistry, dataSourceName, transactionContext, |
| 76 | 82 | getStatementImpl(), typeManager.getMapper(), queryExecutor); |
| @@ -83,7 +89,4 @@ | ||
| 83 | 89 | return statements != null ? statements : new PostgresAccessTokenDataStatements(); |
| 84 | 90 | } |
| 85 | 91 | |
| 86 | - private String getDataSourceName(ServiceExtensionContext context) { | |
| 87 | - return context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 88 | - } | |
| 89 | 92 | } |
modified extensions/data-plane/store/sql/data-plane-store-sql/README.md +0 −6
| @@ -20,9 +20,3 @@ | ||
| 20 | 20 | ``` |
| 21 | 21 | |
| 22 | 22 | --> |
| 23 | - | |
| 24 | -## Configuration | |
| 25 | - | |
| 26 | -| Key | Description | Mandatory | | |
| 27 | -|:------------------------------|:----------------------------------|-----------| | |
| 28 | -| edc.datasource.dataplane.name | Datasource used by this extension | X | |
modified extensions/data-plane/store/sql/data-plane-store-sql/src/main/java/org/eclipse/edc/connector/dataplane/store/sql/SqlDataPlaneStoreExtension.java +7 −5
| @@ -26,6 +26,7 @@ | ||
| 26 | 26 | import org.eclipse.edc.spi.types.TypeManager; |
| 27 | 27 | import org.eclipse.edc.sql.QueryExecutor; |
| 28 | 28 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 29 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 29 | 30 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 30 | 31 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 31 | 32 | |
| @@ -39,9 +40,13 @@ | ||
| 39 | 40 | |
| 40 | 41 | public static final String NAME = "Sql Data Plane Store"; |
| 41 | 42 | |
| 43 | + @Deprecated(since = "0.8.1") | |
| 42 | 44 | @Setting(value = "Name of the datasource to use for accessing data plane store") |
| 43 | 45 | private static final String DATASOURCE_SETTING_NAME = "edc.datasource.dataplane.name"; |
| 44 | 46 | |
| 47 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 48 | + public static final String DATASOURCE_NAME = "edc.sql.store.dataplane.datasource"; | |
| 49 | + | |
| 45 | 50 | @Inject |
| 46 | 51 | private DataSourceRegistry dataSourceRegistry; |
| 47 | 52 | |
| @@ -69,7 +74,8 @@ | ||
| 69 | 74 | |
| 70 | 75 | @Provider |
| 71 | 76 | public DataPlaneStore dataPlaneStore(ServiceExtensionContext context) { |
| 72 | - var dataSourceName = getDataSourceName(context); | |
| 77 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 78 | + | |
| 73 | 79 | sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "dataplane-schema.sql"); |
| 74 | 80 | return new SqlDataPlaneStore(dataSourceRegistry, dataSourceName, transactionContext, |
| 75 | 81 | getStatementImpl(), typeManager.getMapper(), clock, queryExecutor, context.getRuntimeId()); |
| @@ -81,8 +87,4 @@ | ||
| 81 | 87 | private DataPlaneStatements getStatementImpl() { |
| 82 | 88 | return statements != null ? statements : new PostgresDataPlaneStatements(); |
| 83 | 89 | } |
| 84 | - | |
| 85 | - private String getDataSourceName(ServiceExtensionContext context) { | |
| 86 | - return context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 87 | - } | |
| 88 | 90 | } |
modified extensions/policy-monitor/store/sql/policy-monitor-store-sql/src/main/java/org/eclipse/edc/connector/policy/monitor/store/sql/SqlPolicyMonitorStoreExtension.java +7 −1
| @@ -25,6 +25,7 @@ | ||
| 25 | 25 | import org.eclipse.edc.spi.types.TypeManager; |
| 26 | 26 | import org.eclipse.edc.sql.QueryExecutor; |
| 27 | 27 | import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; |
| 28 | +import org.eclipse.edc.sql.configuration.DataSourceName; | |
| 28 | 29 | import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; |
| 29 | 30 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 30 | 31 | |
| @@ -34,9 +35,13 @@ | ||
| 34 | 35 | |
| 35 | 36 | public class SqlPolicyMonitorStoreExtension implements ServiceExtension { |
| 36 | 37 | |
| 38 | + @Deprecated(since = "0.8.1") | |
| 37 | 39 | @Setting(value = "Name of the datasource to use for accessing policy monitor store", defaultValue = DEFAULT_DATASOURCE) |
| 38 | 40 | private static final String DATASOURCE_SETTING_NAME = "edc.datasource.policy-monitor.name"; |
| 39 | 41 | |
| 42 | + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) | |
| 43 | + public static final String DATASOURCE_NAME = "edc.sql.store.policy-monitor.datasource"; | |
| 44 | + | |
| 40 | 45 | @Inject |
| 41 | 46 | private DataSourceRegistry dataSourceRegistry; |
| 42 | 47 | |
| @@ -60,7 +65,8 @@ | ||
| 60 | 65 | |
| 61 | 66 | @Provider |
| 62 | 67 | public PolicyMonitorStore policyMonitorStore(ServiceExtensionContext context) { |
| 63 | - var dataSourceName = context.getConfig().getString(DATASOURCE_SETTING_NAME, DEFAULT_DATASOURCE); | |
| 68 | + var dataSourceName = DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); | |
| 69 | + | |
| 64 | 70 | sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "policy-monitor-schema.sql"); |
| 65 | 71 | |
| 66 | 72 | return new SqlPolicyMonitorStore(dataSourceRegistry, dataSourceName, transactionContext, |
added system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/sql/configuration/DataSourceNameTest.java +63 −0
| @@ -0,0 +1,63 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.sql.configuration; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.spi.monitor.Monitor; | |
| 18 | +import org.eclipse.edc.spi.system.configuration.ConfigFactory; | |
| 19 | +import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; | |
| 20 | +import org.junit.jupiter.api.Test; | |
| 21 | + | |
| 22 | +import java.util.Map; | |
| 23 | + | |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | +import static org.mockito.ArgumentMatchers.anyString; | |
| 26 | +import static org.mockito.Mockito.mock; | |
| 27 | +import static org.mockito.Mockito.verify; | |
| 28 | +import static org.mockito.Mockito.verifyNoInteractions; | |
| 29 | + | |
| 30 | +class DataSourceNameTest { | |
| 31 | + | |
| 32 | + private final Monitor monitor = mock(); | |
| 33 | + | |
| 34 | + @Test | |
| 35 | + void shouldReturnDefaultDatasource_whenNoConfiguration() { | |
| 36 | + var config = ConfigFactory.empty(); | |
| 37 | + | |
| 38 | + var datasourceName = DataSourceName.getDataSourceName("key", "deprecatedKey", config, monitor); | |
| 39 | + | |
| 40 | + assertThat(datasourceName).isEqualTo(DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 41 | + verifyNoInteractions(monitor); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @Test | |
| 45 | + void shouldReturnDatasource_whenIsInConfiguration() { | |
| 46 | + var config = ConfigFactory.fromMap(Map.of("key", "value")); | |
| 47 | + | |
| 48 | + var datasourceName = DataSourceName.getDataSourceName("key", "deprecatedKey", config, monitor); | |
| 49 | + | |
| 50 | + assertThat(datasourceName).isEqualTo("value"); | |
| 51 | + verifyNoInteractions(monitor); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Test | |
| 55 | + void shouldLogWarning_whenDeprecatedKeyIsUsed() { | |
| 56 | + var config = ConfigFactory.fromMap(Map.of("deprecatedKey", "value")); | |
| 57 | + | |
| 58 | + var datasourceName = DataSourceName.getDataSourceName("key", "deprecatedKey", config, monitor); | |
| 59 | + | |
| 60 | + assertThat(datasourceName).isEqualTo("value"); | |
| 61 | + verify(monitor).warning(anyString()); | |
| 62 | + } | |
| 63 | +} |