Elffuss BraidHub

kikocis/EDC public

refactor: separate sql stores from datasources (#4381)

Changeseta438d076d2c5b2d995f21e91fcf181eca901a42c7712a652fbf06a4ff978e45d
Authorndr_brt <andrea.bertagnolli@gmail.com> · 2024-08-07 08:52 +02:00
CommitterGitHub <noreply@github.com> · 2024-08-07 08:52 +02:00
Parents017a6b9f61cd

Browse the files at this changeset

27 files changed

modified docs/developer/README.md +1 −0
@@ -11,6 +11,7 @@
1111 ## Guides
1212 - [Customize Policy Engine](policy-engine.md)
1313 - [Performance Tuning](performance-tuning.md)
14+- [Sql persistence](sql-persistence.md)
1415
1516 ## Build and testing
1617 - [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 @@
2727 import org.eclipse.edc.sql.datasource.ConnectionFactoryDataSource;
2828 import org.eclipse.edc.sql.datasource.ConnectionPoolDataSource;
2929 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
30-import org.jetbrains.annotations.NotNull;
31-import org.jetbrains.annotations.Nullable;
3230
33-import java.util.HashMap;
3431 import java.util.LinkedList;
3532 import java.util.List;
36-import java.util.Map;
33+import java.util.Optional;
3734 import java.util.Properties;
3835 import java.util.function.BiFunction;
3936 import java.util.function.Consumer;
40-import java.util.function.Supplier;
4137 import javax.sql.DataSource;
4238
4339 import static java.util.Optional.ofNullable;
@@ -48,24 +44,32 @@
4844 public static final String NAME = "Commons Connection Pool";
4945
5046 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)
5157 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)
5259 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)
5361 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)
5463 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)
5565 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)
5667 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)
5769 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)
5871 public static final String POOL_CONNECTION_TEST_QUERY = "pool.connection.test.query";
5972
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<>();
6973 @Inject
7074 private DataSourceRegistry dataSourceRegistry;
7175
@@ -78,6 +82,8 @@
7882 @Inject
7983 private Vault vault;
8084
85+ private final List<CommonsConnectionPool> commonsConnectionPools = new LinkedList<>();
86+
8187 @Override
8288 public String name() {
8389 return NAME;
@@ -85,17 +91,14 @@
8591
8692 @Override
8793 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);
97100 dataSourceRegistry.register(dataSourceName, connectionPoolDataSource);
98- }
101+ });
99102 }
100103
101104 @Override
@@ -103,88 +106,51 @@
103106 commonsConnectionPools.forEach(CommonsConnectionPool::close);
104107 }
105108
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-
150109 private DataSource createDataSource(Config config) {
151110 var rootPath = EDC_DATASOURCE_PREFIX + "." + config.currentNode();
152111
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);
165116
166117 var properties = new Properties();
167118 properties.putAll(config.getRelativeEntries());
168119
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));
172122
173123 return new ConnectionFactoryDataSource(connectionFactory, jdbcUrl, properties);
174124 }
175125
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+
176135 private CommonsConnectionPool createConnectionPool(DataSource unPooledDataSource, Config config) {
177136 var builder = CommonsConnectionPoolConfig.Builder.newInstance();
178137
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);
187146
188147 return new CommonsConnectionPool(unPooledDataSource, builder.build(), monitor);
189148 }
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+ }
190156 }
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 @@
2020 import org.eclipse.edc.spi.EdcException;
2121 import org.eclipse.edc.spi.security.Vault;
2222 import org.eclipse.edc.spi.system.ServiceExtensionContext;
23-import org.eclipse.edc.spi.system.configuration.Config;
2423 import org.eclipse.edc.spi.system.configuration.ConfigFactory;
2524 import org.eclipse.edc.sql.ConnectionFactory;
25+import org.eclipse.edc.sql.datasource.ConnectionPoolDataSource;
2626 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
2727 import org.junit.jupiter.api.BeforeEach;
2828 import org.junit.jupiter.api.Test;
@@ -32,6 +32,7 @@
3232 import org.junit.jupiter.params.provider.Arguments;
3333 import org.junit.jupiter.params.provider.ArgumentsProvider;
3434 import org.junit.jupiter.params.provider.ArgumentsSource;
35+import org.mockito.ArgumentCaptor;
3536
3637 import java.util.Map;
3738 import java.util.stream.Collectors;
@@ -39,6 +40,7 @@
3940
4041 import static org.assertj.core.api.Assertions.assertThat;
4142 import static org.assertj.core.api.Assertions.assertThatThrownBy;
43+import static org.assertj.core.api.InstanceOfAssertFactories.type;
4244 import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.EDC_DATASOURCE_PREFIX;
4345 import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTIONS_MAX_IDLE;
4446 import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTIONS_MAX_TOTAL;
@@ -48,14 +50,12 @@
4850 import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTION_TEST_ON_RETURN;
4951 import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTION_TEST_QUERY;
5052 import static org.eclipse.edc.sql.pool.commons.CommonsConnectionPoolServiceExtension.POOL_CONNECTION_TEST_WHILE_IDLE;
51-import static org.mockito.ArgumentMatchers.any;
5253 import static org.mockito.ArgumentMatchers.argThat;
5354 import static org.mockito.ArgumentMatchers.eq;
5455 import static org.mockito.Mockito.mock;
5556 import static org.mockito.Mockito.verify;
5657 import static org.mockito.Mockito.when;
5758
58-//sometimes hangs and causes the test to never finish.
5959 @ExtendWith(DependencyInjectionExtension.class)
6060 class CommonsConnectionPoolServiceExtensionTest {
6161 private static final String DS_1_NAME = "ds1";
@@ -74,21 +74,16 @@
7474 void initialize_withConfig(Map<String, String> configuration, ThrowingConsumer<CommonsConnectionPoolConfig> checker,
7575 boolean isEnv,
7676 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);
8378 when(context.getConfig(EDC_DATASOURCE_PREFIX)).thenReturn(config);
8479
8580 extension.initialize(context);
8681
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);
9287 }
9388
9489 @Test
@@ -103,8 +98,10 @@
10398
10499 extension.initialize(context);
105100
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))
108105 .satisfies(pool -> {
109106 assertThatThrownBy(pool::getConnection).isInstanceOf(EdcException.class); //we need this only to invoke the connection factory
110107 verify(connectionFactory).create(eq("jdbc://whatever"), argThat(p ->
@@ -129,8 +126,10 @@
129126
130127 extension.initialize(context);
131128
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))
134133 .satisfies(pool -> {
135134 assertThatThrownBy(pool::getConnection).isInstanceOf(EdcException.class); //we need this only to invoke the connection factory
136135 verify(connectionFactory).create(eq("jdbc://whatever"), argThat(p ->
@@ -140,7 +139,6 @@
140139 });
141140 }
142141
143-
144142 static class ConfigProvider implements ArgumentsProvider {
145143
146144 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 @@
2727 import org.eclipse.edc.spi.types.TypeManager;
2828 import org.eclipse.edc.sql.QueryExecutor;
2929 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
30+import org.eclipse.edc.sql.configuration.DataSourceName;
3031 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3132 import org.eclipse.edc.transaction.spi.TransactionContext;
3233
@@ -34,12 +35,12 @@
3435 @Extension(value = "SQL edr entry store")
3536 public class SqlEndpointDataReferenceEntryIndexExtension implements ServiceExtension {
3637
37- /**
38- * Name of the datasource to use for accessing edr entries.
39- */
40- @Setting(required = true)
38+ @Deprecated(since = "0.8.1")
4139 public static final String DATASOURCE_SETTING_NAME = "edc.datasource.edr.name";
4240
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+
4344 @Inject
4445 private DataSourceRegistry dataSourceRegistry;
4546
@@ -60,7 +61,7 @@
6061
6162 @Override
6263 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());
6465
6566 var sqlStore = new SqlEndpointDataReferenceEntryIndex(dataSourceRegistry, dataSourceName, transactionContext, typeManager.getMapper(),
6667 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 @@
2222 import org.eclipse.edc.spi.system.ServiceExtensionContext;
2323 import org.eclipse.edc.spi.system.configuration.Config;
2424 import org.eclipse.edc.spi.types.TypeManager;
25-import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
2625 import org.junit.jupiter.api.BeforeEach;
2726 import org.junit.jupiter.api.Test;
2827 import org.junit.jupiter.api.extension.ExtendWith;
2928
3029 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;
3231 import static org.mockito.ArgumentMatchers.any;
32+import static org.mockito.ArgumentMatchers.eq;
3333 import static org.mockito.Mockito.mock;
3434 import static org.mockito.Mockito.verify;
3535 import static org.mockito.Mockito.when;
@@ -37,7 +37,6 @@
3737 @ExtendWith(DependencyInjectionExtension.class)
3838 public class SqlEndpointDataReferenceEntryIndexExtensionTest {
3939
40-
4140 @BeforeEach
4241 void setUp(ServiceExtensionContext context) {
4342 context.registerService(TypeManager.class, new JacksonTypeManager());
@@ -54,6 +53,6 @@
5453 var service = context.getService(EndpointDataReferenceEntryIndex.class);
5554 assertThat(service).isInstanceOf(SqlEndpointDataReferenceEntryIndex.class);
5655
57- verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
56+ verify(config).getString(eq(DATASOURCE_NAME), any());
5857 }
5958 }
modified extensions/control-plane/store/sql/asset-index-sql/README.md +0 −6
@@ -37,12 +37,6 @@
3737 ```
3838 -->
3939
40-## Configuration
41-
42-| Key | Description | Mandatory |
43-|:--------------------------|:----------------------------------|-----------|
44-| edc.datasource.asset.name | Datasource used by this extension | X |
45-
4640 ## Migrate from 0.3.1 to 0.3.2
4741
4842 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 @@
2828 import org.eclipse.edc.spi.types.TypeManager;
2929 import org.eclipse.edc.sql.QueryExecutor;
3030 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
31+import org.eclipse.edc.sql.configuration.DataSourceName;
3132 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3233 import org.eclipse.edc.transaction.spi.TransactionContext;
3334
@@ -35,12 +36,12 @@
3536 @Extension(value = "SQL asset index")
3637 public class SqlAssetIndexServiceExtension implements ServiceExtension {
3738
38- /**
39- * Name of the datasource to use for accessing assets.
40- */
41- @Setting(required = true)
39+ @Deprecated(since = "0.8.1")
4240 public static final String DATASOURCE_SETTING_NAME = "edc.datasource.asset.name";
4341
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+
4445 @Inject
4546 private DataSourceRegistry dataSourceRegistry;
4647
@@ -61,7 +62,7 @@
6162
6263 @Override
6364 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());
6566
6667 var sqlAssetLoader = new SqlAssetIndex(dataSourceRegistry, dataSourceName, transactionContext, typeManager.getMapper(), getDialect(), queryExecutor);
6768
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 @@
2121 import org.eclipse.edc.spi.system.ServiceExtensionContext;
2222 import org.eclipse.edc.spi.system.configuration.Config;
2323 import org.eclipse.edc.spi.types.TypeManager;
24-import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
2524 import org.junit.jupiter.api.BeforeEach;
2625 import org.junit.jupiter.api.Test;
2726 import org.junit.jupiter.api.extension.ExtendWith;
2827
2928 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;
3130 import static org.mockito.ArgumentMatchers.any;
31+import static org.mockito.ArgumentMatchers.eq;
3232 import static org.mockito.Mockito.mock;
3333 import static org.mockito.Mockito.verify;
3434 import static org.mockito.Mockito.when;
@@ -55,6 +55,6 @@
5555 var dataAddressResolver = context.getService(DataAddressResolver.class);
5656 assertThat(dataAddressResolver).isInstanceOf(SqlAssetIndex.class);
5757
58- verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
58+ verify(config).getString(eq(DATASOURCE_NAME), any());
5959 }
6060 }
modified extensions/control-plane/store/sql/contract-definition-store-sql/README.md +0 −6
@@ -10,12 +10,6 @@
1010
1111 ![ER Diagram](docs/er.png)
1212
13-## Configuration
14-
15-| Key | Description | Mandatory |
16-|:---------------------------------------|:----------------------------------|-----------|
17-| edc.datasource.contractdefinition.name | Datasource used by this extension | X |
18-
1913 ## Create a flexible query API to accommodate `QuerySpec`
2014
2115 _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 @@
2828 import org.eclipse.edc.spi.types.TypeManager;
2929 import org.eclipse.edc.sql.QueryExecutor;
3030 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
31+import org.eclipse.edc.sql.configuration.DataSourceName;
3132 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3233 import org.eclipse.edc.transaction.spi.TransactionContext;
3334
@@ -35,12 +36,12 @@
3536 @Extension(value = "SQL contract definition store")
3637 public class SqlContractDefinitionStoreExtension implements ServiceExtension {
3738
38- /**
39- * Name of the datasource to use for accessing contract definitions.
40- */
41- @Setting(required = true)
39+ @Deprecated(since = "0.8.1")
4240 public static final String DATASOURCE_SETTING_NAME = "edc.datasource.contractdefinition.name";
4341
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+
4445 @Inject
4546 private DataSourceRegistry dataSourceRegistry;
4647
@@ -61,7 +62,7 @@
6162
6263 @Override
6364 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());
6566
6667 var sqlContractDefinitionStore = new SqlContractDefinitionStore(dataSourceRegistry, dataSourceName, transactionContext,
6768 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 @@
2020 import org.eclipse.edc.spi.system.ServiceExtensionContext;
2121 import org.eclipse.edc.spi.system.configuration.Config;
2222 import org.eclipse.edc.spi.types.TypeManager;
23-import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
2423 import org.junit.jupiter.api.BeforeEach;
2524 import org.junit.jupiter.api.Test;
2625 import org.junit.jupiter.api.extension.ExtendWith;
2726
2827 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;
3029 import static org.mockito.ArgumentMatchers.any;
30+import static org.mockito.ArgumentMatchers.eq;
3131 import static org.mockito.Mockito.mock;
3232 import static org.mockito.Mockito.verify;
3333 import static org.mockito.Mockito.when;
@@ -35,7 +35,6 @@
3535 @ExtendWith(DependencyInjectionExtension.class)
3636 public class SqlContractDefinitionStoreExtensionTest {
3737
38-
3938 @BeforeEach
4039 void setUp(ServiceExtensionContext context) {
4140 context.registerService(TypeManager.class, new JacksonTypeManager());
@@ -52,6 +51,6 @@
5251 var service = context.getService(ContractDefinitionStore.class);
5352 assertThat(service).isInstanceOf(ContractDefinitionStore.class);
5453
55- verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
54+ verify(config).getString(eq(DATASOURCE_NAME), any());
5655 }
5756 }
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 @@
2121 import org.eclipse.edc.runtime.metamodel.annotation.Extension;
2222 import org.eclipse.edc.runtime.metamodel.annotation.Inject;
2323 import org.eclipse.edc.runtime.metamodel.annotation.Provides;
24+import org.eclipse.edc.runtime.metamodel.annotation.Setting;
2425 import org.eclipse.edc.spi.system.ServiceExtension;
2526 import org.eclipse.edc.spi.system.ServiceExtensionContext;
2627 import org.eclipse.edc.spi.types.TypeManager;
2728 import org.eclipse.edc.sql.QueryExecutor;
2829 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
30+import org.eclipse.edc.sql.configuration.DataSourceName;
2931 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3032 import org.eclipse.edc.transaction.spi.TransactionContext;
3133
@@ -35,7 +37,11 @@
3537 @Extension(value = "SQL contract negotiation store")
3638 public class SqlContractNegotiationStoreExtension implements ServiceExtension {
3739
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";
3945
4046 @Inject
4147 private DataSourceRegistry dataSourceRegistry;
@@ -60,7 +66,8 @@
6066
6167 @Override
6268 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+
6471 var sqlStore = new SqlContractNegotiationStore(dataSourceRegistry, dataSourceName, trxContext,
6572 typeManager.getMapper(), getStatementImpl(), context.getRuntimeId(), clock, queryExecutor);
6673 context.registerService(ContractNegotiationStore.class, sqlStore);
@@ -76,6 +83,6 @@
7683 }
7784
7885 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);
8087 }
8188 }
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 @@
3333
3434 import static org.assertj.core.api.Assertions.assertThat;
3535 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;
3740 import static org.mockito.Mockito.mock;
3841 import static org.mockito.Mockito.verify;
3942 import static org.mockito.Mockito.when;
@@ -47,7 +50,7 @@
4750 void initialize(ServiceExtensionContext context, ObjectFactory factory) {
4851 var config = mock(Config.class);
4952 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");
5154
5255 context.registerService(DataSourceRegistry.class, mock(DataSourceRegistry.class));
5356 context.registerService(TransactionContext.class, mock(TransactionContext.class));
@@ -61,7 +64,7 @@
6164 var service = context.getService(ContractNegotiationStore.class);
6265 assertThat(service).isInstanceOf(SqlContractNegotiationStore.class);
6366 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());
6568
6669 }
6770
modified extensions/control-plane/store/sql/policy-definition-store-sql/README.md +0 −6
@@ -34,9 +34,3 @@
3434 @enduml
3535 ```
3636 -->
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 @@
2727 import org.eclipse.edc.spi.types.TypeManager;
2828 import org.eclipse.edc.sql.QueryExecutor;
2929 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
30+import org.eclipse.edc.sql.configuration.DataSourceName;
3031 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3132 import org.eclipse.edc.transaction.spi.TransactionContext;
3233
@@ -34,9 +35,12 @@
3435 @Extension("SQL policy store")
3536 public class SqlPolicyStoreExtension implements ServiceExtension {
3637
37- @Setting(required = true)
38+ @Deprecated(since = "0.8.1")
3839 public static final String DATASOURCE_SETTING_NAME = "edc.datasource.policy.name";
3940
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+
4044 @Inject
4145 private DataSourceRegistry dataSourceRegistry;
4246
@@ -56,7 +60,8 @@
5660
5761 @Override
5862 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+
6065 var sqlPolicyStore = new SqlPolicyDefinitionStore(dataSourceRegistry, dataSourceName, transactionContext,
6166 typeManager.getMapper(), getStatementImpl(), queryExecutor);
6267
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 @@
2121 import org.eclipse.edc.spi.system.ServiceExtensionContext;
2222 import org.eclipse.edc.spi.system.configuration.Config;
2323 import org.eclipse.edc.spi.types.TypeManager;
24-import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
2524 import org.junit.jupiter.api.BeforeEach;
2625 import org.junit.jupiter.api.Test;
2726 import org.junit.jupiter.api.extension.ExtendWith;
2827
2928 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;
3130 import static org.mockito.ArgumentMatchers.any;
31+import static org.mockito.ArgumentMatchers.eq;
3232 import static org.mockito.Mockito.mock;
3333 import static org.mockito.Mockito.verify;
3434 import static org.mockito.Mockito.when;
@@ -53,6 +53,6 @@
5353 var service = context.getService(PolicyDefinitionStore.class);
5454 assertThat(service).isInstanceOf(SqlPolicyDefinitionStore.class);
5555
56- verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
56+ verify(config).getString(eq(DATASOURCE_NAME), any());
5757 }
5858 }
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 @@
2727 import org.eclipse.edc.spi.types.TypeManager;
2828 import org.eclipse.edc.sql.QueryExecutor;
2929 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
30+import org.eclipse.edc.sql.configuration.DataSourceName;
3031 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3132 import org.eclipse.edc.transaction.spi.TransactionContext;
3233
@@ -36,8 +37,11 @@
3637 @Extension(value = "SQL transfer process store")
3738 public class SqlTransferProcessStoreExtension implements ServiceExtension {
3839
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";
4145
4246 @Inject
4347 private DataSourceRegistry dataSourceRegistry;
@@ -60,7 +64,8 @@
6064
6165 @Override
6266 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+
6469 var store = new SqlTransferProcessStore(dataSourceRegistry, dataSourceName, trxContext,
6570 typeManager.getMapper(), getStatementImpl(), context.getRuntimeId(), clock, queryExecutor);
6671 context.registerService(TransferProcessStore.class, store);
@@ -75,7 +80,4 @@
7580 return statements != null ? statements : new PostgresDialectStatements();
7681 }
7782
78- private String getDataSourceName(ServiceExtensionContext context) {
79- return context.getConfig().getString(DATASOURCE_NAME_SETTING, DataSourceRegistry.DEFAULT_DATASOURCE);
80- }
8183 }
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 @@
2121 import org.eclipse.edc.spi.system.ServiceExtensionContext;
2222 import org.eclipse.edc.spi.system.configuration.Config;
2323 import org.eclipse.edc.spi.types.TypeManager;
24-import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
2524 import org.junit.jupiter.api.BeforeEach;
2625 import org.junit.jupiter.api.Test;
2726 import org.junit.jupiter.api.extension.ExtendWith;
2827
2928 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;
3130 import static org.mockito.ArgumentMatchers.any;
31+import static org.mockito.ArgumentMatchers.eq;
3232 import static org.mockito.Mockito.mock;
3333 import static org.mockito.Mockito.verify;
3434 import static org.mockito.Mockito.when;
@@ -52,6 +52,6 @@
5252 var service = context.getService(TransferProcessStore.class);
5353 assertThat(service).isInstanceOf(SqlTransferProcessStore.class);
5454
55- verify(config).getString(DATASOURCE_NAME_SETTING, DataSourceRegistry.DEFAULT_DATASOURCE);
55+ verify(config).getString(eq(DATASOURCE_NAME), any());
5656 }
5757 }
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 @@
2727 import org.eclipse.edc.spi.types.TypeManager;
2828 import org.eclipse.edc.sql.QueryExecutor;
2929 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
30+import org.eclipse.edc.sql.configuration.DataSourceName;
3031 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3132 import org.eclipse.edc.transaction.spi.TransactionContext;
3233
@@ -40,8 +41,13 @@
4041 public class SqlDataPlaneInstanceStoreExtension implements ServiceExtension {
4142 public static final String NAME = "Sql Data Plane Instance Store";
4243
44+ @Deprecated(since = "0.8.1")
4345 @Setting(value = "Name of the datasource to use for accessing data plane instances")
4446 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+
4551 @Inject
4652 private DataSourceRegistry dataSourceRegistry;
4753
@@ -70,7 +76,8 @@
7076
7177 @Provider
7278 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+
7481 sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "dataplane-instance-schema.sql");
7582 return new SqlDataPlaneInstanceStore(dataSourceRegistry, dataSourceName, transactionContext,
7683 getStatementImpl(), typeManager.getMapper(), queryExecutor, clock, context.getRuntimeId());
@@ -83,7 +90,4 @@
8390 return statements != null ? statements : new PostgresDataPlaneInstanceStatements();
8491 }
8592
86- private String getDataSourceName(ServiceExtensionContext context) {
87- return context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
88- }
8993 }
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 @@
1919 import org.eclipse.edc.spi.system.ServiceExtensionContext;
2020 import org.eclipse.edc.spi.system.configuration.Config;
2121 import org.eclipse.edc.spi.types.TypeManager;
22-import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
2322 import org.junit.jupiter.api.BeforeEach;
2423 import org.junit.jupiter.api.Test;
2524 import org.junit.jupiter.api.extension.ExtendWith;
2625
2726 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;
2928 import static org.mockito.ArgumentMatchers.any;
29+import static org.mockito.ArgumentMatchers.eq;
3030 import static org.mockito.Mockito.mock;
3131 import static org.mockito.Mockito.verify;
3232 import static org.mockito.Mockito.when;
@@ -48,6 +48,6 @@
4848 var store = extension.dataPlaneInstanceStore(context);
4949 assertThat(store).isInstanceOf(SqlDataPlaneInstanceStore.class);
5050
51- verify(config).getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
51+ verify(config).getString(eq(DATASOURCE_NAME), any());
5252 }
5353 }
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 @@
2727 import org.eclipse.edc.spi.types.TypeManager;
2828 import org.eclipse.edc.sql.QueryExecutor;
2929 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
30+import org.eclipse.edc.sql.configuration.DataSourceName;
3031 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3132 import org.eclipse.edc.transaction.spi.TransactionContext;
3233
@@ -40,9 +41,13 @@
4041
4142 public static final String NAME = "Sql AccessTokenData Store";
4243
44+ @Deprecated(since = "0.8.1")
4345 @Setting(value = "Name of the datasource to use for accessing data plane store")
4446 private static final String DATASOURCE_SETTING_NAME = "edc.datasource.accesstokendata.name";
4547
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+
4651 @Inject
4752 private DataSourceRegistry dataSourceRegistry;
4853
@@ -70,7 +75,8 @@
7075
7176 @Provider
7277 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+
7480 sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "accesstoken-data-schema.sql");
7581 return new SqlAccessTokenDataStore(dataSourceRegistry, dataSourceName, transactionContext,
7682 getStatementImpl(), typeManager.getMapper(), queryExecutor);
@@ -83,7 +89,4 @@
8389 return statements != null ? statements : new PostgresAccessTokenDataStatements();
8490 }
8591
86- private String getDataSourceName(ServiceExtensionContext context) {
87- return context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
88- }
8992 }
modified extensions/data-plane/store/sql/data-plane-store-sql/README.md +0 −6
@@ -20,9 +20,3 @@
2020 ```
2121
2222 -->
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 @@
2626 import org.eclipse.edc.spi.types.TypeManager;
2727 import org.eclipse.edc.sql.QueryExecutor;
2828 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
29+import org.eclipse.edc.sql.configuration.DataSourceName;
2930 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3031 import org.eclipse.edc.transaction.spi.TransactionContext;
3132
@@ -39,9 +40,13 @@
3940
4041 public static final String NAME = "Sql Data Plane Store";
4142
43+ @Deprecated(since = "0.8.1")
4244 @Setting(value = "Name of the datasource to use for accessing data plane store")
4345 private static final String DATASOURCE_SETTING_NAME = "edc.datasource.dataplane.name";
4446
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+
4550 @Inject
4651 private DataSourceRegistry dataSourceRegistry;
4752
@@ -69,7 +74,8 @@
6974
7075 @Provider
7176 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+
7379 sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "dataplane-schema.sql");
7480 return new SqlDataPlaneStore(dataSourceRegistry, dataSourceName, transactionContext,
7581 getStatementImpl(), typeManager.getMapper(), clock, queryExecutor, context.getRuntimeId());
@@ -81,8 +87,4 @@
8187 private DataPlaneStatements getStatementImpl() {
8288 return statements != null ? statements : new PostgresDataPlaneStatements();
8389 }
84-
85- private String getDataSourceName(ServiceExtensionContext context) {
86- return context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
87- }
8890 }
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 @@
2525 import org.eclipse.edc.spi.types.TypeManager;
2626 import org.eclipse.edc.sql.QueryExecutor;
2727 import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper;
28+import org.eclipse.edc.sql.configuration.DataSourceName;
2829 import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
2930 import org.eclipse.edc.transaction.spi.TransactionContext;
3031
@@ -34,9 +35,13 @@
3435
3536 public class SqlPolicyMonitorStoreExtension implements ServiceExtension {
3637
38+ @Deprecated(since = "0.8.1")
3739 @Setting(value = "Name of the datasource to use for accessing policy monitor store", defaultValue = DEFAULT_DATASOURCE)
3840 private static final String DATASOURCE_SETTING_NAME = "edc.datasource.policy-monitor.name";
3941
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+
4045 @Inject
4146 private DataSourceRegistry dataSourceRegistry;
4247
@@ -60,7 +65,8 @@
6065
6166 @Provider
6267 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+
6470 sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "policy-monitor-schema.sql");
6571
6672 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+}