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

fix(api): dataplane selector control API #4291

Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
* Fraunhofer Institute for Software and Systems Engineering - register missing transformer
*
*/

Expand All @@ -19,16 +20,21 @@
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer;
import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataPlaneInstanceTransformer;
import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry;
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.ApiContext;

import java.time.Clock;
import java.util.Map;

import static jakarta.json.Json.createBuilderFactory;
import static org.eclipse.edc.connector.dataplane.selector.control.api.DataplaneSelectorControlApiExtension.NAME;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_TYPE;
import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD;

@Extension(NAME)
public class DataplaneSelectorControlApiExtension implements ServiceExtension {
Expand All @@ -41,6 +47,9 @@ public class DataplaneSelectorControlApiExtension implements ServiceExtension {
@Inject
private JsonObjectValidatorRegistry validatorRegistry;

@Inject
private TypeManager typeManager;

@Inject
private TypeTransformerRegistry typeTransformerRegistry;

Expand All @@ -60,6 +69,7 @@ public void initialize(ServiceExtensionContext context) {
validatorRegistry.register(DATAPLANE_INSTANCE_TYPE, DataPlaneInstanceValidator.instance());

typeTransformerRegistry.register(new JsonObjectToDataPlaneInstanceTransformer());
typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), typeManager.getMapper(JSON_LD)));

var controller = new DataplaneSelectorControlApiController(validatorRegistry, typeTransformerRegistry, dataPlaneSelectorService, clock);
webService.registerResource(ApiContext.CONTROL, controller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
* Fraunhofer Institute for Software and Systems Engineering - register missing transformer
*
*/

Expand All @@ -18,6 +19,7 @@
import org.eclipse.edc.junit.extensions.DependencyInjectionExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer;
import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataPlaneInstanceTransformer;
import org.eclipse.edc.validator.jsonobject.JsonObjectValidator;
import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry;
Expand Down Expand Up @@ -65,5 +67,6 @@ void shouldRegisterTransformers(DataplaneSelectorControlApiExtension extension,
extension.initialize(context);

verify(typeTransformerRegistry).register(isA(JsonObjectToDataPlaneInstanceTransformer.class));
verify(typeTransformerRegistry).register(isA(JsonObjectFromDataPlaneInstanceTransformer.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2024 Fraunhofer Institute for Software and Systems Engineering
*
* 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:
* Fraunhofer Institute for Software and Systems Engineering - initial implementation
*
*/

package org.eclipse.edc.test.e2e;

import io.restassured.http.ContentType;
import jakarta.json.JsonArray;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.junit.extensions.EmbeddedRuntime;
import org.eclipse.edc.junit.extensions.RuntimeExtension;
import org.eclipse.edc.junit.extensions.RuntimePerMethodExtension;
import org.eclipse.edc.spi.protocol.ProtocolWebhook;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.util.Map;

import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.mockito.Mockito.mock;

@EndToEndTest
public class DataplaneSelectorControlApiEndToEndTest {

private final int controlPlaneControlPort = getFreePort();

@RegisterExtension
private final RuntimeExtension controlPlane = new RuntimePerMethodExtension(new EmbeddedRuntime(
"control-plane",
Map.of(
"web.http.control.port", String.valueOf(controlPlaneControlPort),
"web.http.control.path", "/control"
),
":core:control-plane:control-plane-core",
":core:data-plane-selector:data-plane-selector-core",
":extensions:control-plane:transfer:transfer-data-plane-signaling",
":extensions:common:iam:iam-mock",
":extensions:common:http",
":extensions:common:api:control-api-configuration",
":extensions:data-plane-selector:data-plane-selector-control-api"
)).registerServiceMock(ProtocolWebhook.class, mock());

@RegisterExtension
private final RuntimeExtension dataPlane = new RuntimePerMethodExtension(new EmbeddedRuntime(
"data-plane",
Map.of(
"web.http.port", String.valueOf(getFreePort()),
"web.http.path", "/api",
"web.http.control.port", String.valueOf(getFreePort()),
"web.http.control.path", "/control",
"edc.dpf.selector.url", String.format("http://localhost:%d/control/v1/dataplanes", controlPlaneControlPort)
),
":core:data-plane:data-plane-core",
paullatzelsperger marked this conversation as resolved.
Show resolved Hide resolved
":extensions:data-plane:data-plane-http",
":extensions:data-plane:data-plane-signaling:data-plane-signaling-api",
":extensions:common:api:control-api-configuration",
":extensions:control-plane:api:control-plane-api-client",
":extensions:data-plane:data-plane-self-registration",
":extensions:data-plane-selector:data-plane-selector-client",
":extensions:common:http"
));

@Test
void shouldReturnSelfRegisteredDataplane() {
var result = given()
.baseUri("http://localhost:" + controlPlaneControlPort + "/control")
.when()
.get("/v1/dataplanes")
.then()
.statusCode(200)
.contentType(ContentType.JSON)
.extract().body().as(JsonArray.class);

assertThat(result).hasSize(1);
}
}
Loading