Skip to content

Commit

Permalink
Merge pull request #158 from carlos-schmidt/edc-v0.10.0
Browse files Browse the repository at this point in the history
Compatibility: edc v0.10.0
  • Loading branch information
carlos-schmidt authored Oct 26, 2024
2 parents 04aceab + b41dea2 commit 9a1bafb
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 82 deletions.
1 change: 0 additions & 1 deletion client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies {
implementation("$group:data-plane-http-spi:$edcVersion") // EDC HttpDataAddress
implementation("$group:dsp-catalog-http-dispatcher:$edcVersion") // DSP HTTP constant
implementation("$group:json-ld-lib:$edcVersion") // JsonLD expansion
implementation("$group:management-api:$edcVersion") // EDC WebService for registering endpoints

testImplementation("$group:junit:$edcVersion")
testImplementation("org.glassfish.jersey.core:jersey-common:$jerseyVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ public class ClientEndpoint {
* Root path for the client
*/
public static final String AUTOMATED_PATH = "automated";
private static final String NEGOTIATE_CONTRACT_PATH = "negotiateContract";
private static final String NEGOTIATE_PATH = "negotiate";

public static final String MISSING_QUERY_PARAMETER_MESSAGE = "Missing query parameter. Required parameters: %s";
public static final String MISSING_REQUEST_BODY_MESSAGE = "Missing request body of type %s";

private static final String NEGOTIATE_CONTRACT_PATH = "negotiateContract";
private static final String NEGOTIATE_PATH = "negotiate";
private final Monitor monitor;

private final NegotiationController negotiationController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@
@Path(ClientEndpoint.AUTOMATED_PATH)
public class DataTransferController {

public static final String OPERATION_FIELD = "operation";
static final String DATA_TRANSFER_API_KEY = "data-transfer-api-key";
static final String TRANSFER_PATH = "transfer";

private static final int WAIT_FOR_TRANSFER_TIMEOUT_DEFAULT = 10;
public static final String OPERATION_FIELD = "operation";

private final Config config;

private final DataTransferObservable dataTransferObservable;
private final DataTransferObservable<String> dataTransferObservable;
private final TransferInitiator transferInitiator;
private final Monitor monitor;

Expand Down Expand Up @@ -90,7 +88,7 @@ public DataTransferController(Monitor monitor, Config config, WebService webServ

transferInitiator = new TransferInitiator(monitor, config, hostname, transferProcessManager);
dataTransferEndpointManager = new DataTransferEndpointManager(publicApiManagementService);
dataTransferObservable = new DataTransferObservable(monitor);
dataTransferObservable = new DataTransferObservable<>(monitor);
var dataTransferEndpoint = new DataTransferEndpoint(monitor, dataTransferObservable);
nonNullNonEmptyObjectMapper = new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -185,7 +183,7 @@ private DataAddress serializeOperation(DataAddress dataAddress) throws JsonProce
* @throws ExecutionException If the data transfer process failed
*/
private StatusResult<String> initiateTransferProcess(URL providerUrl, String agreementId,
DataAddress dataSinkAddress)
DataAddress dataSinkAddress)
throws InterruptedException, ExecutionException {

if (dataSinkAddress == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public class PolicyController {

static final String ACCEPTED_POLICIES_PATH = "acceptedPolicies";
private static final String OFFER_PATH = "offer";
private static final String GET_OFFER_FAILED_MESSAGE = "Getting offer from the provider failed. Check connector output for details.";
private static final String GET_OFFER_FAILED_MESSAGE = "Getting offer from the provider failed. Check connector " +
"output for details.";

private final PolicyDefinitionStore policyDefinitionStore;
private final PolicyService policyService;
Expand Down Expand Up @@ -90,7 +91,8 @@ public PolicyController(Monitor monitor, CatalogService catalogService,
*/
@GET
@Path(OFFER_PATH)
public Response getDataset(@QueryParam("providerUrl") URL providerUrl, @QueryParam("assetId") String assetId, @QueryParam("providerId") String counterPartyId) {
public Response getDataset(@QueryParam("providerUrl") URL providerUrl, @QueryParam("assetId") String assetId,
@QueryParam("providerId") String counterPartyId) {
monitor.info("GET /%s".formatted(OFFER_PATH));
if (Objects.isNull(assetId) || Objects.isNull(providerUrl)) {
return Response.status(Response.Status.BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,60 +51,10 @@
import static org.mockito.Mockito.verify;

class DataTransferControllerTest {
private DataTransferController testSubject;
private static URL url;
private static final String agreementId = UUID.randomUUID().toString();

private static URL url;
private final TransferProcessManager mockTransferProcessManager = mock(TransferProcessManager.class);

@BeforeEach
public void setup() throws IOException {
int port = 8080;
url = new URL(format("http://localhost:%s", port));
testSubject = new DataTransferController(
new ConsoleMonitor().withPrefix("DataTransferControllerTest"),
mockConfig(),
mock(WebService.class),
mock(PublicApiManagementService.class),
mockTransferProcessManager,
mock(TransferProcessObservable.class),
() -> "localhost");
}

private Config mockConfig() {
return ConfigFactory.fromMap(
Map.of(
"edc.dsp.callback.address", "http://localhost:4321/dsp",
"web.http.port", "8080",
"web.http.path", "/api"));
}

@Test
void test_getData_correctlySerializeOperation() throws JsonProcessingException {
Operation operation = getOperation();
var nnneObjectMapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

var operationString = nnneObjectMapper.writeValueAsString(operation);
DataAddress dataSinkAddress = getDataAddress(operation);

testSubject.getData(url, agreementId, dataSinkAddress);
// Verify that operation is serialized before sending it to provider
verify(mockTransferProcessManager).initiateConsumerRequest(argThat(request ->
operationString.equals(request.getDataDestination().getStringProperty(OPERATION_FIELD))));
}

@Test
void test_getData_correctlySerializeNullOperation() {
Operation operation = null;

DataAddress dataSinkAddress = getDataAddress(operation);

testSubject.getData(url, agreementId, dataSinkAddress);
// Verify that operation is serialized before sending it to provider
verify(mockTransferProcessManager).initiateConsumerRequest(argThat(request ->
null == request.getDataDestination().getProperties().get(OPERATION_FIELD)));
}
private DataTransferController testSubject;

private static DataAddress getDataAddress(Object operation) {
return DataAddress.Builder.newInstance()
Expand Down Expand Up @@ -156,6 +106,55 @@ private static Operation getOperation() {
.build();
}

@BeforeEach
public void setup() throws IOException {
int port = 8080;
url = new URL(format("http://localhost:%s", port));
testSubject = new DataTransferController(
new ConsoleMonitor().withPrefix("DataTransferControllerTest"),
mockConfig(),
mock(WebService.class),
mock(PublicApiManagementService.class),
mockTransferProcessManager,
mock(TransferProcessObservable.class),
() -> "localhost");
}

private Config mockConfig() {
return ConfigFactory.fromMap(
Map.of(
"edc.dsp.callback.address", "http://localhost:4321/dsp",
"web.http.port", "8080",
"web.http.path", "/api"));
}

@Test
void test_getData_correctlySerializeOperation() throws JsonProcessingException {
Operation operation = getOperation();
var nnneObjectMapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

var operationString = nnneObjectMapper.writeValueAsString(operation);
DataAddress dataSinkAddress = getDataAddress(operation);

testSubject.getData(url, agreementId, dataSinkAddress);
// Verify that operation is serialized before sending it to provider
verify(mockTransferProcessManager).initiateConsumerRequest(argThat(request ->
operationString.equals(request.getDataDestination().getStringProperty(OPERATION_FIELD))));
}

@Test
void test_getData_correctlySerializeNullOperation() {
Operation operation = null;

DataAddress dataSinkAddress = getDataAddress(operation);

testSubject.getData(url, agreementId, dataSinkAddress);
// Verify that operation is serialized before sending it to provider
verify(mockTransferProcessManager).initiateConsumerRequest(argThat(request ->
null == request.getDataDestination().getProperties().get(OPERATION_FIELD)));
}

@Test
void getDataTest() {
var dataAddress = AasDataAddress.Builder.newInstance().aasProvider(new Service(url)).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;

class DefaultSelfSignedCertificateRetrieverTest {
Expand Down
3 changes: 2 additions & 1 deletion edc-extension4aas/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ dependencies {

implementation("de.fraunhofer.iosb.ilt.faaast.service:starter:${faaastVersion}")
implementation("$group:http-spi:${edcVersion}")
implementation("$group:management-api:$edcVersion")
implementation("$group:asset-api:$edcVersion")
implementation("$group:web-spi:$edcVersion")

testImplementation("$group:junit:$edcVersion")
testImplementation("org.glassfish.jersey.core:jersey-common:$jerseyVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ public AasAgent(AasDataProcessorFactory aasDataProcessorFactory) {
this.aasDataProcessorFactory = aasDataProcessorFactory;
}

protected <K> Result<List<K>> readElements(AasDataProcessor processor, AasProvider provider, String path, Class<K> clazz) {
protected <K> Result<List<K>> readElements(AasDataProcessor processor, AasProvider provider, String path,
Class<K> clazz) {
var dataAddress = AasDataAddress.Builder.newInstance()
.method(GET)
.aasProvider(provider)
.path(path)
.build();

var responseResult = executeRequest(processor, dataAddress);

if (responseResult.failed()) {
Expand All @@ -69,7 +70,7 @@ protected <K> Result<List<K>> readElements(AasDataProcessor processor, AasProvid
if (response.isSuccessful() && response.body() != null) {
return readList(response.body(), clazz);
}

return Result.failure("Reading %s from %s failed: %s, %s"
.formatted(clazz.getSimpleName(), path, response.code(), response.message()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public RegistryAgent(AasDataProcessorFactory aasDataProcessorFactory, AasService
this.aasServiceRegistry = aasServiceRegistry;
}

private static URL convertToUrl(String spec) {
try {
return new URL(spec);
} catch (MalformedURLException e) {
return null;
}
}

@Override
public PipelineResult<Map<Service, Environment>> apply(@Nonnull Registry registry) {
try {
Expand Down Expand Up @@ -246,14 +254,6 @@ private List<URL> sortByHostAndPort(List<String> urls) {
.toList();
}

private static URL convertToUrl(String spec) {
try {
return new URL(spec);
} catch (MalformedURLException e) {
return null;
}
}

private @Nonnull List<String> getEndpointUrls(Collection<Endpoint> endpoints, String identifier) {
return endpoints.stream()
.filter(endpoint ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.eclipse.edc.connector.controlplane.asset.spi.index.AssetIndex;
import org.eclipse.edc.connector.controlplane.contract.spi.offer.store.ContractDefinitionStore;
import org.eclipse.edc.connector.controlplane.policy.spi.store.PolicyDefinitionStore;
import org.eclipse.edc.spi.monitor.ConsoleMonitor;
import org.eclipse.edc.spi.monitor.Monitor;

import java.util.List;
Expand Down Expand Up @@ -110,8 +109,7 @@ public Builder policyDefinitionStore(PolicyDefinitionStore policyDefinitionStore
}

public CleanUpService build() {
monitor = Objects.requireNonNullElseGet(monitor,
() -> new ConsoleMonitor(this.getClass().getName(), ConsoleMonitor.Level.INFO));
Objects.requireNonNull(monitor);

var pipeline = new Pipeline.Builder<Asset, ChangeSet<Asset, String>>()
.initialStep(PipelineStep.create(asset -> new ChangeSet.Builder<Asset, String>()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
javaVersion=17
group=org.eclipse.edc
edcVersion=0.9.1
edcVersion=0.10.0
faaastVersion=1.1.0
aas4jVersion=1.0.2
mockitoVersion=5.2.0
Expand Down

0 comments on commit 9a1bafb

Please sign in to comment.