Skip to content

Commit

Permalink
feat: Improve modularity by introducing lib modules for cross depeden…
Browse files Browse the repository at this point in the history
…cies (#4046)

* Split modules into libs

* Fix test

* Fix tests

* Fix tests
  • Loading branch information
jimmarino authored Mar 26, 2024
1 parent ba139fd commit 83611ff
Show file tree
Hide file tree
Showing 168 changed files with 446 additions and 261 deletions.
7 changes: 4 additions & 3 deletions core/common/connector-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ dependencies {
api(project(":spi:common:transform-spi"))
api(project(":spi:common:validator-spi"))

implementation(project(":core:common:policy-engine"))
implementation(project(":core:common:state-machine"))
implementation(project(":core:common:transform-core"))
implementation(project(":core:common:lib:policy-engine-lib"))
implementation(project(":core:common:util"))
implementation(project(":core:common:transform-core"))
implementation(project(":core:common:validator-core"))
implementation(project(":core:common:lib:state-machine-lib"))
implementation(project(":core:common:lib:boot-lib"))
implementation(project(":core:common:lib:query-lib"))
implementation(project(":core:common:lib:http-lib"))
implementation(project(":core:common:lib:keys-lib"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

package org.eclipse.edc.connector.core;

import org.eclipse.edc.boot.health.HealthCheckServiceConfiguration;
import org.eclipse.edc.boot.health.HealthCheckServiceImpl;
import org.eclipse.edc.connector.core.base.CommandHandlerRegistryImpl;
import org.eclipse.edc.connector.core.base.RemoteMessageDispatcherRegistryImpl;
import org.eclipse.edc.connector.core.base.agent.ParticipantAgentServiceImpl;
import org.eclipse.edc.connector.core.event.EventExecutorServiceContainer;
import org.eclipse.edc.connector.core.event.EventRouterImpl;
import org.eclipse.edc.connector.core.health.HealthCheckServiceConfiguration;
import org.eclipse.edc.connector.core.health.HealthCheckServiceImpl;
import org.eclipse.edc.connector.core.store.CriterionOperatorRegistryImpl;
import org.eclipse.edc.connector.core.validator.DataAddressValidatorRegistryImpl;
import org.eclipse.edc.connector.core.validator.JsonObjectValidatorRegistryImpl;
import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl;
Expand All @@ -31,6 +30,7 @@
import org.eclipse.edc.policy.engine.spi.PolicyEngine;
import org.eclipse.edc.policy.engine.spi.RuleBindingRegistry;
import org.eclipse.edc.policy.model.PolicyRegistrationTypes;
import org.eclipse.edc.query.CriterionOperatorRegistryImpl;
import org.eclipse.edc.runtime.metamodel.annotation.BaseExtension;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
Expand Down Expand Up @@ -97,7 +97,6 @@ public class CoreServicesExtension implements ServiceExtension {
private HealthCheckServiceImpl healthCheckService;
private RuleBindingRegistry ruleBindingRegistry;


@Override
public String name() {
return NAME;
Expand Down Expand Up @@ -167,7 +166,6 @@ public EventRouter eventRouter(ServiceExtensionContext context) {
return new EventRouterImpl(context.getMonitor(), eventExecutorServiceContainer.getExecutorService());
}


@Provider
public HealthCheckService healthCheckService() {
return healthCheckService;
Expand Down
5 changes: 4 additions & 1 deletion core/common/edr-store-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ plugins {

dependencies {
api(project(":spi:common:edr-store-spi"))
implementation(project(":core:common:connector-core"))

implementation(project(":spi:common:transaction-spi"))
implementation(project(":core:common:lib:store-lib"))

testImplementation(project(":core:common:junit"))
testImplementation(project(":core:common:lib:boot-lib"))

testImplementation(project(":core:common:lib:query-lib"))
testImplementation(testFixtures(project(":spi:common:edr-store-spi")))
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

package org.eclipse.edc.core.edr.defaults;

import org.eclipse.edc.connector.core.store.ReflectionBasedQueryResolver;
import org.eclipse.edc.edr.spi.store.EndpointDataReferenceEntryIndex;
import org.eclipse.edc.edr.spi.types.EndpointDataReferenceEntry;
import org.eclipse.edc.spi.query.CriterionOperatorRegistry;
import org.eclipse.edc.spi.query.QueryResolver;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.result.StoreResult;
import org.eclipse.edc.store.ReflectionBasedQueryResolver;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

package org.eclipse.edc.core.edr.defaults;

import org.eclipse.edc.connector.core.store.CriterionOperatorRegistryImpl;
import org.eclipse.edc.edr.spi.store.EndpointDataReferenceEntryIndex;
import org.eclipse.edc.query.CriterionOperatorRegistryImpl;
import org.eclipse.tractusx.edc.edr.spi.store.EndpointDataReferenceEntryIndexTestBase;

public class InMemoryEndpointDataReferenceEntryStoreTest extends EndpointDataReferenceEntryIndexTestBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.edc.boot.vault.InMemoryVault;
import org.eclipse.edc.connector.core.store.CriterionOperatorRegistryImpl;
import org.eclipse.edc.core.edr.defaults.InMemoryEndpointDataReferenceEntryIndex;
import org.eclipse.edc.core.edr.defaults.VaultEndpointDataReferenceCache;
import org.eclipse.edc.edr.spi.store.EndpointDataReferenceStore;
import org.eclipse.edc.query.CriterionOperatorRegistryImpl;
import org.eclipse.edc.transaction.spi.NoopTransactionContext;
import org.eclipse.tractusx.edc.edr.spi.store.EndpointDataReferenceStoreTestBase;

Expand Down
1 change: 1 addition & 0 deletions core/common/lib/boot-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {

api(project(":spi:common:core-spi"))

testImplementation(libs.awaitility)
}


Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.connector.core.health;
package org.eclipse.edc.boot.health;

import org.eclipse.edc.spi.system.health.LivenessProvider;
import org.eclipse.edc.spi.system.health.ReadinessProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.connector.core.health;
package org.eclipse.edc.boot.health;

import org.eclipse.edc.spi.system.ExecutorInstrumentation;
import org.eclipse.edc.spi.system.health.HealthCheckResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
*
*/

package org.eclipse.edc.connector.core.health;
package org.eclipse.edc.core.health;

import org.awaitility.Awaitility;
import org.eclipse.edc.boot.health.HealthCheckServiceConfiguration;
import org.eclipse.edc.boot.health.HealthCheckServiceImpl;
import org.eclipse.edc.spi.system.ExecutorInstrumentation;
import org.eclipse.edc.spi.system.health.HealthCheckResult;
import org.eclipse.edc.spi.system.health.LivenessProvider;
Expand All @@ -26,7 +29,6 @@
import java.time.Duration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -62,7 +64,7 @@ void isLive() {
when(lpm.get()).thenReturn(successResult());
service.addLivenessProvider(lpm);

await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(AWAIT_TIMEOUT)
.untilAsserted(() -> {
assertThat(service.isLive().isHealthy()).isTrue();
Expand All @@ -77,7 +79,7 @@ void isLive_throwsException() {
when(lpm.get()).thenReturn(successResult()).thenThrow(new RuntimeException("test exception"));
service.addLivenessProvider(lpm);

await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(AWAIT_TIMEOUT)
.untilAsserted(() -> {
assertThat(service.isLive().isHealthy()).isFalse();
Expand All @@ -93,7 +95,7 @@ void isLive_failed() {
service.addLivenessProvider(lpm);


await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(AWAIT_TIMEOUT)
.untilAsserted(() -> {
assertThat(service.isLive().isHealthy()).isFalse();
Expand All @@ -108,7 +110,7 @@ void isReady() {
when(provider.get()).thenReturn(successResult());
service.addReadinessProvider(provider);

await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(AWAIT_TIMEOUT)
.untilAsserted(() -> {
assertThat(service.isReady().isHealthy()).isTrue();
Expand All @@ -124,7 +126,7 @@ void isReady_throwsException() {
when(provider.get()).thenReturn(successResult()).thenThrow(new RuntimeException("test-exception"));
service.addReadinessProvider(provider);

await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(AWAIT_TIMEOUT)
.untilAsserted(() -> {
assertThat(service.isReady().isHealthy()).isFalse();
Expand All @@ -140,7 +142,7 @@ void isReady_failed() {
when(provider.get()).thenReturn(failedResult());
service.addReadinessProvider(provider);

await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(AWAIT_TIMEOUT)
.untilAsserted(() -> {
assertThat(service.isReady().isHealthy()).isFalse();
Expand All @@ -156,7 +158,7 @@ void hasStartupFinished() {
when(provider.get()).thenReturn(successResult());
service.addStartupStatusProvider(provider);

await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(AWAIT_TIMEOUT)
.untilAsserted(() -> {
assertThat(service.getStartupStatus().isHealthy()).isTrue();
Expand All @@ -175,7 +177,7 @@ void cacheCanBeRefreshed() {

service.refresh();

await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(PERIOD.multipliedBy(2))
.untilAsserted(() -> {
assertThat(service.getStartupStatus().isHealthy()).isTrue();
Expand All @@ -192,7 +194,7 @@ void hasStartupFinished_throwsException() {
when(provider.get()).thenReturn(successResult()).thenThrow(new RuntimeException("test-exception"));
service.addStartupStatusProvider(provider);

await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(AWAIT_TIMEOUT)
.untilAsserted(() -> {
assertThat(service.getStartupStatus().isHealthy()).isFalse();
Expand All @@ -209,7 +211,7 @@ void hasStartupFinished_failed() {
when(provider.get()).thenReturn(failedResult());
service.addStartupStatusProvider(provider);

await().pollInterval(POLL_INTERVAL)
Awaitility.await().pollInterval(POLL_INTERVAL)
.atMost(AWAIT_TIMEOUT)
.untilAsserted(() -> {
assertThat(service.getStartupStatus().isHealthy()).isFalse();
Expand Down
31 changes: 31 additions & 0 deletions core/common/lib/json-ld-lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

plugins {
`java-library`
}

dependencies {
api(libs.jakartaJson)
api(libs.jacksonJsonP)
api(libs.titaniumJsonLd)

implementation(project(":spi:common:core-spi"))
implementation(project(":spi:common:json-ld-spi"))
testImplementation(project(":core:common:util"))
testImplementation(project(":tests:junit-base"))

testImplementation(libs.mockserver.netty)
testImplementation(libs.mockserver.client)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import jakarta.json.JsonValue;
import org.eclipse.edc.jsonld.document.JarLoader;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.jsonld.spi.JsonLdKeywords;
import org.eclipse.edc.spi.CoreConstants;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;

Expand All @@ -45,9 +47,6 @@
import static jakarta.json.Json.createBuilderFactory;
import static jakarta.json.Json.createObjectBuilder;
import static java.util.Optional.ofNullable;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB;
import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE;

/**
* Implementation of the {@link JsonLd} interface that uses the Titanium library for all JSON-LD operations.
Expand Down Expand Up @@ -94,7 +93,7 @@ public Result<JsonObject> compact(JsonObject json, String scope) {
var document = JsonDocument.of(json);
var jsonFactory = createBuilderFactory(Map.of());
var contextDocument = JsonDocument.of(jsonFactory.createObjectBuilder()
.add(CONTEXT, createContext(scope))
.add(JsonLdKeywords.CONTEXT, createContext(scope))
.build());
var compacted = com.apicatalog.jsonld.JsonLd.compact(document, contextDocument)
.options(new JsonLdOptions(documentLoader))
Expand Down Expand Up @@ -127,14 +126,14 @@ private JsonObject injectVocab(JsonObject json) {
var jsonObjectBuilder = createObjectBuilder(json);

//only inject the vocab if the @context is an object, not a URL
if (json.get(CONTEXT) instanceof JsonObject) {
var contextObject = ofNullable(json.getJsonObject(CONTEXT)).orElseGet(() -> createObjectBuilder().build());
if (json.get(JsonLdKeywords.CONTEXT) instanceof JsonObject) {
var contextObject = ofNullable(json.getJsonObject(JsonLdKeywords.CONTEXT)).orElseGet(() -> createObjectBuilder().build());
var contextBuilder = createObjectBuilder(contextObject);
if (!contextObject.containsKey(VOCAB)) {
if (!contextObject.containsKey(JsonLdKeywords.VOCAB)) {
var newContextObject = contextBuilder
.add(VOCAB, EDC_NAMESPACE)
.add(JsonLdKeywords.VOCAB, CoreConstants.EDC_NAMESPACE)
.build();
jsonObjectBuilder.add(CONTEXT, newContextObject);
jsonObjectBuilder.add(JsonLdKeywords.CONTEXT, newContextObject);
}
}
return jsonObjectBuilder.build();
Expand All @@ -143,11 +142,11 @@ private JsonObject injectVocab(JsonObject json) {
private JsonValue createContext(String scope) {
var builder = createObjectBuilder();
// Adds the configured namespaces for * and the input scope
Stream.concat(namespacesForScope(DEFAULT_SCOPE), namespacesForScope(scope))
Stream.concat(namespacesForScope(JsonLd.DEFAULT_SCOPE), namespacesForScope(scope))
.forEach(entry -> builder.add(entry.getKey(), entry.getValue()));

// Compute the additional context IRI defined for * and the input scope
var contexts = Stream.concat(contextsForScope(DEFAULT_SCOPE), contextsForScope(scope))
var contexts = Stream.concat(contextsForScope(JsonLd.DEFAULT_SCOPE), contextsForScope(scope))
.collect(Collectors.toSet());

var contextObject = builder.build();
Expand Down
Loading

0 comments on commit 83611ff

Please sign in to comment.