Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce boot-lib and http-lib modules #4030

Merged
merged 6 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/common/connector-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ dependencies {
implementation(project(":core:common:transform-core"))
implementation(project(":core:common:util"))
implementation(project(":core:common:validator-core"))
implementation(project(":core:common:lib:boot-lib"))
implementation(project(":core:common:lib:http-lib"))

implementation(libs.dnsOverHttps)
implementation(libs.bouncyCastle.bcpkixJdk18on)
implementation(libs.nimbus.jwt)
implementation(libs.tink)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import dev.failsafe.RetryPolicy;
import okhttp3.EventListener;
import okhttp3.OkHttpClient;
import org.eclipse.edc.connector.core.base.EdcHttpClientImpl;
import org.eclipse.edc.boot.vault.InMemoryVault;
import org.eclipse.edc.connector.core.base.OkHttpClientConfiguration;
import org.eclipse.edc.connector.core.base.OkHttpClientFactory;
import org.eclipse.edc.connector.core.base.RetryPolicyConfiguration;
import org.eclipse.edc.connector.core.base.RetryPolicyFactory;
import org.eclipse.edc.connector.core.base.agent.NoOpParticipantIdMapper;
import org.eclipse.edc.connector.core.event.EventExecutorServiceContainer;
import org.eclipse.edc.connector.core.vault.InMemoryVault;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
Expand All @@ -39,6 +38,7 @@
import org.eclipse.edc.transaction.datasource.spi.DefaultDataSourceRegistry;
import org.eclipse.edc.transaction.spi.NoopTransactionContext;
import org.eclipse.edc.transaction.spi.TransactionContext;
import org.eclipse.http.client.EdcHttpClientImpl;

import java.util.concurrent.Executors;

Expand Down
2 changes: 2 additions & 0 deletions core/common/edr-store-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ dependencies {
implementation(project(":core:common:connector-core"))

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

testImplementation(testFixtures(project(":spi:common:edr-store-spi")))
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.eclipse.edc.core.edr.defaults;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.edc.connector.core.vault.InMemoryVault;
import org.eclipse.edc.boot.vault.InMemoryVault;
import org.eclipse.edc.edr.spi.store.EndpointDataReferenceCache;
import org.eclipse.tractusx.edc.edr.spi.store.EndpointDataReferenceCacheTestBase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package org.eclipse.edc.core.edr.store;

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.connector.core.vault.InMemoryVault;
import org.eclipse.edc.core.edr.defaults.InMemoryEndpointDataReferenceEntryIndex;
import org.eclipse.edc.core.edr.defaults.VaultEndpointDataReferenceCache;
import org.eclipse.edc.edr.spi.store.EndpointDataReferenceStore;
Expand All @@ -30,7 +30,7 @@ public class EndpointDataReferenceStoreImplTest extends EndpointDataReferenceSto
private final InMemoryEndpointDataReferenceEntryIndex store = new InMemoryEndpointDataReferenceEntryIndex(CriterionOperatorRegistryImpl.ofDefaults());
private final VaultEndpointDataReferenceCache cache = new VaultEndpointDataReferenceCache(new InMemoryVault(mock()), "", new ObjectMapper());
private final EndpointDataReferenceStoreImpl endpointDataReferenceService = new EndpointDataReferenceStoreImpl(store, cache, new NoopTransactionContext());

@Override
protected EndpointDataReferenceStore getStore() {
return endpointDataReferenceService;
Expand Down
9 changes: 8 additions & 1 deletion core/common/junit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@ plugins {
dependencies {
api(project(":spi:common:core-spi"))
api(project(":core:common:boot"))
api(project(":core:common:connector-core"))
api(project(":core:common:util"))
api(project(":core:common:lib:http-lib"))

implementation(project(":spi:common:http-spi"))
implementation(libs.okhttp)
implementation(libs.mockito.core)
implementation(libs.assertj)
implementation(libs.junit.jupiter.api)

runtimeOnly(libs.junit.jupiter.engine)

implementation(libs.junit.pioneer)
implementation(libs.testcontainers.junit)
testImplementation(project(":core:common:connector-core"))


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


Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,26 @@
import dev.failsafe.RetryPolicy;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import org.eclipse.edc.connector.core.base.EdcHttpClientImpl;
import org.eclipse.edc.spi.http.EdcHttpClient;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.http.client.EdcHttpClientImpl;
import org.opentest4j.AssertionFailedError;

import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.Objects;
import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

import static java.lang.String.format;
import static org.mockito.Mockito.mock;

public class TestUtils {
public static final int MAX_TCP_PORT = 65_535;
public static final String GRADLE_WRAPPER;
private static final String GRADLE_WRAPPER_UNIX = "gradlew";
private static final String GRADLE_WRAPPER_WINDOWS = "gradlew.bat";
private static final Random RANDOM = new Random();
private static File buildRoot = null;

static {
Expand Down Expand Up @@ -73,65 +68,6 @@ public static String getResourceFileContentAsString(String resourceName) {
}
}

/**
* Gets a free port in the range 1024 - 65535 by trying them in ascending order.
*
* @return the first free port
* @throws IllegalArgumentException if no free port is available
*/
public static int getFreePort() {
var rnd = 1024 + RANDOM.nextInt(MAX_TCP_PORT - 1024);
return getFreePort(rnd);
}

/**
* Gets a free port in the range lowerBound - 65535 by trying them in ascending order.
*
* @return the first free port
* @throws IllegalArgumentException if no free port is available
*/
public static int getFreePort(int lowerBound) {
if (lowerBound <= 0 || lowerBound >= MAX_TCP_PORT) {
throw new IllegalArgumentException("Lower bound must be > 0 and < " + MAX_TCP_PORT);
}
return getFreePort(lowerBound, MAX_TCP_PORT);
}

/**
* Gets a free port in the range lowerBound - upperBound by trying them in ascending order.
*
* @return the first free port
* @throws IllegalArgumentException if no free port is available or if the bounds are invalid.
*/
public static int getFreePort(int lowerBound, int upperBound) {

if (lowerBound <= 0 || lowerBound >= MAX_TCP_PORT || lowerBound >= upperBound) {
throw new IllegalArgumentException("Lower bound must be > 0 and < " + MAX_TCP_PORT + " and be < upperBound");
}
if (upperBound > MAX_TCP_PORT) {
throw new IllegalArgumentException("Upper bound must be < " + MAX_TCP_PORT);
}
var port = lowerBound;
boolean found = false;

while (!found && port <= upperBound) {
try (ServerSocket serverSocket = new ServerSocket(port)) {
serverSocket.setReuseAddress(true);
port = serverSocket.getLocalPort();

found = true;
} catch (IOException e) {
found = false;
port++;
}
}

if (!found) {
throw new IllegalArgumentException(format("No free ports in the range [%d - %d]", lowerBound, upperBound));
}
return port;
}

/**
* Helper method to create a temporary directory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package org.eclipse.edc.junit.extension;

import org.eclipse.edc.connector.core.vault.InMemoryVault;
import org.eclipse.edc.boot.vault.InMemoryVault;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.http.EdcHttpClient;
Expand Down

This file was deleted.

27 changes: 27 additions & 0 deletions core/common/lib/boot-lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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`
`java-test-fixtures`
`maven-publish`
}

dependencies {

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

}


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

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

import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;
Expand All @@ -32,7 +32,7 @@ public InMemoryVault(Monitor monitor) {

@Override
public @Nullable String resolveSecret(String s) {
monitor.debug("resolving secret " + s);
monitor.debug("Resolving secret " + s);
if (s == null) {
monitor.warning("Secret name is null - skipping");
return null;
Expand All @@ -42,14 +42,14 @@ public InMemoryVault(Monitor monitor) {

@Override
public Result<Void> storeSecret(String s, String s1) {
monitor.debug("storing secret " + s);
monitor.debug("Storing secret " + s);
secrets.put(s, s1);
return Result.success();
}

@Override
public Result<Void> deleteSecret(String s) {
monitor.debug("deleting secret " + s);
monitor.debug("Deleting secret " + s);
return secrets.remove(s) == null ?
Result.failure("Secret with key " + s + " does not exist") :
Result.success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
*
*/

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

import org.eclipse.edc.boot.vault.InMemoryVault;
import org.eclipse.edc.spi.monitor.Monitor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
32 changes: 32 additions & 0 deletions core/common/lib/http-lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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`
`java-test-fixtures`
`maven-publish`
}

dependencies {
api(project(":spi:common:http-spi"))

implementation(libs.okhttp)
implementation(libs.dnsOverHttps)

testImplementation(project(":core:common:util"))

testImplementation(libs.mockserver.netty)
}


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

package org.eclipse.edc.connector.core.base;
package org.eclipse.http.client;

import dev.failsafe.RetryPolicy;
import okhttp3.HttpUrl;
Expand All @@ -35,7 +35,7 @@
import static java.util.Objects.requireNonNull;

public class EdcHttpClientImpl implements EdcHttpClient {

private final OkHttpClient okHttpClient;
private final RetryPolicy<Response> retryPolicy;
private final Monitor monitor;
Expand Down
Loading
Loading