Skip to content

Commit b815d90

Browse files
feat: update codebase to use Config Injection (#265)
* feat: update codebase to use Config Injection * trigger ci * checkstyle
1 parent ff03664 commit b815d90

File tree

8 files changed

+40
-58
lines changed

8 files changed

+40
-58
lines changed

core/federated-catalog-core/src/main/java/org/eclipse/edc/catalog/cache/FederatedCatalogCacheExtension.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import java.util.Map;
5757

5858
import static java.util.Optional.ofNullable;
59-
import static org.eclipse.edc.catalog.cache.FederatedCatalogDefaultServicesExtension.NUM_CRAWLER_SETTING;
6059
import static org.eclipse.edc.catalog.spi.CacheSettings.DEFAULT_NUMBER_OF_CRAWLERS;
6160
import static org.eclipse.edc.catalog.spi.CatalogConstants.DATASPACE_PROTOCOL;
6261
import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_08;
@@ -67,8 +66,11 @@ public class FederatedCatalogCacheExtension implements ServiceExtension {
6766

6867
public static final String NAME = "Federated Catalog Cache";
6968

70-
@Setting
71-
public static final String CRAWLING_ENABLED_PROPERTY = "edc.catalog.cache.execution.enabled";
69+
@Setting(description = "Determines whether catalog crawling is globally enabled or disabled", key = "edc.catalog.cache.execution.enabled", defaultValue = "true")
70+
private boolean executionEnabled;
71+
72+
@Setting(description = "The number of crawlers (execution threads) that should be used. The engine will re-use crawlers when necessary.", key = "edc.catalog.cache.partition.num.crawlers", defaultValue = DEFAULT_NUMBER_OF_CRAWLERS + "")
73+
private int numCrawlers;
7274

7375
@Inject
7476
private FederatedCatalogCache store;
@@ -112,13 +114,9 @@ public void initialize(ServiceExtensionContext context) {
112114
if (healthCheckService != null) {
113115
healthCheckService.addReadinessProvider(() -> HealthCheckResult.Builder.newInstance().component("Crawler Subsystem").build());
114116
}
115-
int numCrawlers = context.getSetting(NUM_CRAWLER_SETTING, DEFAULT_NUMBER_OF_CRAWLERS);
116-
117117
// by default only uses FC nodes that are not "self"
118118
nodeFilter = ofNullable(nodeFilter).orElse(node -> !node.name().equals(context.getRuntimeId()));
119119

120-
var isEnabled = context.getConfig().getBoolean(CRAWLING_ENABLED_PROPERTY, true);
121-
122120
executionManager = ExecutionManager.Builder.newInstance()
123121
.monitor(context.getMonitor().withPrefix("ExecutionManager"))
124122
.preExecutionTask(() -> {
@@ -130,7 +128,7 @@ public void initialize(ServiceExtensionContext context) {
130128
.onSuccess(this::persist)
131129
.nodeDirectory(directory)
132130
.nodeFilterFunction(nodeFilter)
133-
.isEnabled(isEnabled)
131+
.isEnabled(executionEnabled)
134132
.build();
135133

136134
registerTransformers(context);

core/federated-catalog-core/src/main/java/org/eclipse/edc/catalog/cache/FederatedCatalogDefaultServicesExtension.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ public class FederatedCatalogDefaultServicesExtension implements ServiceExtensio
4747

4848
public static final String NAME = "Federated Catalog Default Services";
4949

50-
@Setting("The time to elapse between two crawl runs")
51-
public static final String EXECUTION_PLAN_PERIOD_SECONDS = "edc.catalog.cache.execution.period.seconds";
52-
@Setting("The number of crawlers (execution threads) that should be used. The engine will re-use crawlers when necessary.")
53-
public static final String NUM_CRAWLER_SETTING = "edc.catalog.cache.partition.num.crawlers";
54-
@Setting("The initial delay for the cache crawler engine")
55-
public static final String EXECUTION_PLAN_DELAY_SECONDS = "edc.catalog.cache.execution.delay.seconds";
50+
@Setting(description = "The time to elapse between two crawl runs", key = "edc.catalog.cache.execution.period.seconds", defaultValue = DEFAULT_EXECUTION_PERIOD_SECONDS + "")
51+
private long periodSeconds;
52+
53+
@Setting(description = "The number of crawlers (execution threads) that should be used. The engine will re-use crawlers when necessary.", key = "edc.catalog.cache.partition.num.crawlers", defaultValue = DEFAULT_NUMBER_OF_CRAWLERS + "")
54+
private int numCrawlers;
55+
@Setting(description = "The initial delay for the cache crawler engine", key = "edc.catalog.cache.execution.delay.seconds", required = false)
56+
private Integer delaySeconds;
5657

5758
@Inject
5859
private FederatedCatalogCache store;
@@ -79,23 +80,20 @@ public QueryService defaultQueryEngine() {
7980

8081
@Provider(isDefault = true)
8182
public ExecutionPlan createRecurringExecutionPlan(ServiceExtensionContext context) {
82-
var periodSeconds = context.getSetting(EXECUTION_PLAN_PERIOD_SECONDS, DEFAULT_EXECUTION_PERIOD_SECONDS);
83-
var setting = context.getSetting(EXECUTION_PLAN_DELAY_SECONDS, null);
8483
int initialDelaySeconds;
85-
if ("random".equals(setting) || setting == null) {
84+
if (delaySeconds == null) {
8685
initialDelaySeconds = randomSeconds();
8786
} else {
8887
try {
89-
initialDelaySeconds = Integer.parseInt(setting);
88+
initialDelaySeconds = delaySeconds;
9089
} catch (NumberFormatException ex) {
9190
initialDelaySeconds = 0;
9291
}
9392
}
9493
var monitor = context.getMonitor();
9594
if (periodSeconds < LOW_EXECUTION_PERIOD_SECONDS_THRESHOLD) {
96-
var crawlers = context.getSetting(NUM_CRAWLER_SETTING, DEFAULT_NUMBER_OF_CRAWLERS);
9795
monitor.warning(format("An execution period of %d seconds is very low (threshold = %d). This might result in the work queue to be ever growing." +
98-
" A longer execution period or more crawler threads (currently using %d) should be considered.", periodSeconds, LOW_EXECUTION_PERIOD_SECONDS_THRESHOLD, crawlers));
96+
" A longer execution period or more crawler threads (currently using %d) should be considered.", periodSeconds, LOW_EXECUTION_PERIOD_SECONDS_THRESHOLD, numCrawlers));
9997
}
10098
return new RecurringExecutionPlan(Duration.ofSeconds(periodSeconds), Duration.ofSeconds(initialDelaySeconds), monitor);
10199
}

core/federated-catalog-core/src/test/java/org/eclipse/edc/catalog/cache/FederatedCatalogCacheExtensionTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.eclipse.edc.junit.extensions.DependencyInjectionExtension;
2828
import org.eclipse.edc.spi.monitor.Monitor;
2929
import org.eclipse.edc.spi.system.ServiceExtensionContext;
30-
import org.eclipse.edc.spi.system.configuration.Config;
30+
import org.eclipse.edc.spi.system.configuration.ConfigFactory;
3131
import org.eclipse.edc.spi.system.health.HealthCheckService;
3232
import org.eclipse.edc.spi.types.TypeManager;
3333
import org.junit.jupiter.api.BeforeEach;
@@ -36,18 +36,16 @@
3636

3737
import java.time.Duration;
3838
import java.util.List;
39+
import java.util.Map;
3940

4041
import static java.util.concurrent.CompletableFuture.completedFuture;
4142
import static org.assertj.core.api.Assertions.assertThat;
4243
import static org.awaitility.Awaitility.await;
43-
import static org.eclipse.edc.catalog.cache.FederatedCatalogCacheExtension.CRAWLING_ENABLED_PROPERTY;
4444
import static org.eclipse.edc.catalog.test.TestUtil.TEST_PROTOCOL;
4545
import static org.eclipse.edc.catalog.test.TestUtil.createCatalog;
4646
import static org.eclipse.edc.catalog.test.TestUtil.createNode;
4747
import static org.mockito.ArgumentMatchers.any;
48-
import static org.mockito.ArgumentMatchers.anyBoolean;
4948
import static org.mockito.ArgumentMatchers.anyString;
50-
import static org.mockito.ArgumentMatchers.eq;
5149
import static org.mockito.Mockito.atLeastOnce;
5250
import static org.mockito.Mockito.mock;
5351
import static org.mockito.Mockito.verify;
@@ -86,7 +84,6 @@ void initialize(ServiceExtensionContext context) {
8684
extension.initialize(context);
8785

8886
verify(context, atLeastOnce()).getMonitor();
89-
verify(context).getSetting("edc.catalog.cache.partition.num.crawlers", 2);
9087
}
9188

9289
@Test
@@ -102,8 +99,7 @@ void initialize_withHealthCheck(ServiceExtensionContext context, ObjectFactory f
10299

103100
@Test
104101
void initialize_withDisabledExecution(ServiceExtensionContext context, ObjectFactory factory) {
105-
var mockedConfig = mock(Config.class);
106-
when(mockedConfig.getBoolean(eq(CRAWLING_ENABLED_PROPERTY), anyBoolean())).thenReturn(false);
102+
var mockedConfig = ConfigFactory.fromMap(Map.of("edc.catalog.cache.execution.enabled", Boolean.FALSE.toString()));
107103
when(context.getConfig()).thenReturn(mockedConfig);
108104
var mockedPlan = mock(ExecutionPlan.class);
109105
context.registerService(ExecutionPlan.class, mockedPlan);
@@ -114,7 +110,6 @@ void initialize_withDisabledExecution(ServiceExtensionContext context, ObjectFac
114110
extension.start();
115111

116112
verifyNoInteractions(mockedPlan);
117-
118113
}
119114

120115
@Test

extensions/store/sql/federated-catalog-cache-sql/src/main/java/org/eclipse/edc/catalog/store/sql/SqlFederatedCatalogCacheExtension.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@
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;
3130
import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
3231
import org.eclipse.edc.transaction.spi.TransactionContext;
3332

3433
@Provides(FederatedCatalogCache.class)
3534
@Extension(value = "SQL federated catalog cache")
3635
public class SqlFederatedCatalogCacheExtension implements ServiceExtension {
3736

38-
@Deprecated(since = "0.8.1")
39-
@Setting
40-
public static final String DATASOURCE_SETTING_NAME = "edc.datasource.federatedcatalog.name";
41-
@Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE)
42-
public static final String DATASOURCE_NAME = "edc.sql.store.federatedcatalog.datasource";
37+
@Setting(description = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE, key = "edc.sql.store.federatedcatalog.datasource")
38+
private String dataSourceName;
4339

4440
@Inject
4541
private DataSourceRegistry dataSourceRegistry;
@@ -59,7 +55,6 @@ public class SqlFederatedCatalogCacheExtension implements ServiceExtension {
5955
@Override
6056
public void initialize(ServiceExtensionContext context) {
6157
typeManager.registerTypes(Catalog.class, Dataset.class);
62-
var dataSourceName = getDataSourceName(context);
6358
var store = new SqlFederatedCatalogCache(dataSourceRegistry, dataSourceName, trxContext,
6459
typeManager.getMapper(), queryExecutor, getStatementImpl());
6560
context.registerService(FederatedCatalogCache.class, store);
@@ -73,7 +68,4 @@ private FederatedCatalogCacheStatements getStatementImpl() {
7368
return statements != null ? statements : new PostgresDialectStatements();
7469
}
7570

76-
private String getDataSourceName(ServiceExtensionContext context) {
77-
return DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor());
78-
}
7971
}

extensions/store/sql/federated-catalog-cache-sql/src/test/java/org/eclipse/edc/catalog/store/sql/SqlFederatedCatalogCacheExtensionTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.junit.jupiter.api.extension.ExtendWith;
2828

2929
import static org.assertj.core.api.Assertions.assertThat;
30-
import static org.eclipse.edc.catalog.store.sql.SqlFederatedCatalogCacheExtension.DATASOURCE_NAME;
3130
import static org.mockito.ArgumentMatchers.any;
32-
import static org.mockito.ArgumentMatchers.eq;
3331
import static org.mockito.Mockito.mock;
3432
import static org.mockito.Mockito.verify;
3533
import static org.mockito.Mockito.when;
@@ -57,6 +55,5 @@ void shouldInitializeTheStore(SqlFederatedCatalogCacheExtension extension, Servi
5755
assertThat(service).isInstanceOf(SqlFederatedCatalogCache.class);
5856

5957
verify(typeManager).registerTypes(Catalog.class, Dataset.class);
60-
verify(config).getString(eq(DATASOURCE_NAME), any());
6158
}
6259
}

extensions/store/sql/target-node-directory-sql/src/main/java/org/eclipse/edc/catalog/store/sql/SqlTargetNodeDirectoryExtension.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
@Extension(value = "SQL target node directory")
3434
public class SqlTargetNodeDirectoryExtension implements ServiceExtension {
3535

36-
@Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE)
37-
public static final String DATASOURCE_NAME = "edc.sql.store.targetnodedirectory.datasource";
36+
@Setting(description = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE, key = "edc.sql.store.targetnodedirectory.datasource")
37+
private String dataSourceName;
3838

3939
@Inject
4040
private DataSourceRegistry dataSourceRegistry;
@@ -54,7 +54,6 @@ public class SqlTargetNodeDirectoryExtension implements ServiceExtension {
5454
@Override
5555
public void initialize(ServiceExtensionContext context) {
5656
typeManager.registerTypes(TargetNode.class);
57-
var dataSourceName = context.getSetting(DATASOURCE_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
5857
var targetNodeDirectory = new SqlTargetNodeDirectory(dataSourceRegistry, dataSourceName, trxContext,
5958
typeManager.getMapper(), queryExecutor, getStatementImpl());
6059
context.registerService(TargetNodeDirectory.class, targetNodeDirectory);

extensions/store/sql/target-node-directory-sql/src/test/java/org/eclipse/edc/catalog/store/sql/SqlTargetNodeDirectoryExtensionTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
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.catalog.store.sql.SqlTargetNodeDirectoryExtension.DATASOURCE_NAME;
3129
import static org.mockito.ArgumentMatchers.any;
3230
import static org.mockito.Mockito.mock;
3331
import static org.mockito.Mockito.verify;
@@ -56,6 +54,5 @@ void shouldInitializeTheStore(SqlTargetNodeDirectoryExtension extension, Service
5654
assertThat(service).isInstanceOf(SqlTargetNodeDirectory.class);
5755

5856
verify(typeManager).registerTypes(TargetNode.class);
59-
verify(config).getString(DATASOURCE_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
6057
}
6158
}

system-tests/bom-tests/src/test/java/org/eclipse/edc/test/bom/BomSmokeTests.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.junit.jupiter.api.Test;
2424
import org.junit.jupiter.api.extension.RegisterExtension;
2525

26-
import java.util.Map;
26+
import java.util.HashMap;
2727

2828
import static io.restassured.RestAssured.given;
2929
import static org.awaitility.Awaitility.await;
@@ -55,16 +55,22 @@ class FederatedCatalogDcp extends SmokeTest {
5555
@RegisterExtension
5656
protected RuntimeExtension runtime =
5757
new RuntimePerMethodExtension(new EmbeddedRuntime("fc-dcp-bom",
58-
Map.of(
59-
"edc.iam.sts.oauth.token.url", "https://sts.com/token",
60-
"edc.iam.sts.oauth.client.id", "test-clientid",
61-
"edc.iam.sts.oauth.client.secret.alias", "test-alias",
62-
"web.http.port", "8080",
63-
"web.http.path", "/api",
64-
"web.http.catalog.port", "8081",
65-
"web.http.catalog.path", "/api/catalog",
66-
"edc.catalog.cache.execution.period.seconds", "5",
67-
"edc.catalog.cache.execution.delay.seconds", "0"),
58+
new HashMap<>() {
59+
{
60+
put("edc.iam.sts.oauth.token.url", "https://sts.com/token");
61+
put("edc.iam.sts.oauth.client.id", "test-clientid");
62+
put("edc.iam.sts.oauth.client.secret.alias", "test-alias");
63+
put("web.http.port", "8080");
64+
put("web.http.path", "/api");
65+
put("web.http.catalog.port", "8081");
66+
put("web.http.catalog.path", "/api/catalog");
67+
put("edc.catalog.cache.execution.period.seconds", "5");
68+
put("edc.iam.issuer.id", "did:web:testparticipant");
69+
put("edc.iam.sts.privatekey.alias", "private-alias");
70+
put("edc.iam.sts.publickey.id", "public-key-id");
71+
put("edc.catalog.cache.execution.delay.seconds", "0");
72+
}
73+
},
6874
":dist:bom:federatedcatalog-dcp-bom"
6975
));
7076
}

0 commit comments

Comments
 (0)