Skip to content

Commit

Permalink
refactor(api): merge signaling api context into control (#4176)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored May 16, 2024
1 parent ef7b502 commit 162f5fe
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ plugins {
dependencies {
api(project(":spi:control-plane:transfer-spi"))
api(project(":spi:common:transform-spi"))
api(project(":core:common:lib:transform-lib"))
api(project(":extensions:common:json-ld"))
api(project(":data-protocols:dsp:dsp-spi"))
api(project(":data-protocols:dsp:dsp-http-spi"))
implementation(project(":core:common:lib:transform-lib"))

testImplementation(project(":core:common:lib:json-ld-lib"))
testImplementation(project(":core:common:junit"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
import java.net.URI;

import static java.lang.String.format;
import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_PREFIX;
import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA;
import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_PREFIX;
import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA;
import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD;

/**
Expand Down Expand Up @@ -94,6 +98,9 @@ public void initialize(ServiceExtensionContext context) {
context.registerService(ControlApiConfiguration.class, new ControlApiConfiguration(config));
context.registerService(ControlApiUrl.class, callbackAddress);

jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, CONTROL_SCOPE);
jsonLd.registerNamespace(DSPACE_PREFIX, DSPACE_SCHEMA, CONTROL_SCOPE);

webService.registerResource(SETTINGS.getContextAlias(), new ObjectMapperProvider(jsonLdMapper));
webService.registerResource(SETTINGS.getContextAlias(), new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, CONTROL_SCOPE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

import org.eclipse.edc.web.spi.configuration.WebServiceConfiguration;

/**
* Signaling api configuration
*
* @deprecated ControlApiConfiguration should be used instead.
*/
@Deprecated(since = "0.6.4")
public class SignalingApiConfiguration extends WebServiceConfiguration {

public SignalingApiConfiguration(String contextAlias) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA;
import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD;

@Deprecated(since = "0.6.4")
@Provides(SignalingApiConfiguration.class)
@Extension(value = NAME)
public class SignalingApiConfigurationExtension implements ServiceExtension {
Expand Down Expand Up @@ -87,6 +88,11 @@ public String name() {

@Override
public void initialize(ServiceExtensionContext context) {
var warningMessage = """
The data-plane-signaling-api-configuration extension is deprecated as the related 'web.http.signaling'
settings, please exclude from your build and configure your endpoints to the control-api context
""";
context.getMonitor().warning(warningMessage);
var webServiceConfiguration = configurer.configure(context, webServer, SETTINGS);
context.registerService(SignalingApiConfiguration.class, new SignalingApiConfiguration(webServiceConfiguration));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ dependencies {
api(project(":spi:common:json-ld-spi"))
api(project(":spi:data-plane:data-plane-spi"))

implementation(project(":core:common:lib:transform-lib"))
implementation(project(":extensions:common:api:control-api-configuration"))
implementation(project(":extensions:data-plane:data-plane-signaling:data-plane-signaling-transform"))
implementation(project(":extensions:data-plane:data-plane-signaling:data-plane-signaling-api-configuration"))
implementation(libs.jakarta.rsApi)

testImplementation(libs.restAssured)
testImplementation(testFixtures(project(":extensions:common:http:jersey-core")))

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

package org.eclipse.edc.connector.dataplane.api;

import jakarta.json.Json;
import org.eclipse.edc.connector.api.control.configuration.ControlApiConfiguration;
import org.eclipse.edc.connector.api.signaling.configuration.SignalingApiConfiguration;
import org.eclipse.edc.connector.api.signaling.transform.from.JsonObjectFromDataFlowResponseMessageTransformer;
import org.eclipse.edc.connector.api.signaling.transform.to.JsonObjectToDataFlowStartMessageTransformer;
import org.eclipse.edc.connector.api.signaling.transform.to.JsonObjectToDataFlowSuspendMessageTransformer;
import org.eclipse.edc.connector.api.signaling.transform.to.JsonObjectToDataFlowTerminateMessageTransformer;
import org.eclipse.edc.connector.dataplane.api.controller.v1.DataPlaneSignalingApiController;
import org.eclipse.edc.connector.dataplane.spi.manager.DataPlaneManager;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
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.dspace.from.JsonObjectFromDataAddressDspaceTransformer;
import org.eclipse.edc.transform.transformer.dspace.to.JsonObjectToDataAddressDspaceTransformer;
import org.eclipse.edc.web.spi.WebService;

import java.util.Map;

import static org.eclipse.edc.connector.dataplane.api.DataPlaneSignalingApiExtension.NAME;
import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD;

@Extension(NAME)
public class DataPlaneSignalingApiExtension implements ServiceExtension {

public static final String NAME = "DataPlane Signaling API extension";

@Inject
Expand All @@ -41,6 +53,8 @@ public class DataPlaneSignalingApiExtension implements ServiceExtension {
private TypeTransformerRegistry transformerRegistry;
@Inject
private DataPlaneManager dataPlaneManager;
@Inject
private TypeManager typeManager;

@Override
public String name() {
Expand All @@ -49,10 +63,26 @@ public String name() {

@Override
public void initialize(ServiceExtensionContext context) {
var factory = Json.createBuilderFactory(Map.of());
var jsonLdMapper = typeManager.getMapper(JSON_LD);

var signalingApiTypeTransformerRegistry = transformerRegistry.forContext("signaling-api");
signalingApiTypeTransformerRegistry.register(new JsonObjectToDataFlowStartMessageTransformer());
signalingApiTypeTransformerRegistry.register(new JsonObjectToDataFlowSuspendMessageTransformer());
signalingApiTypeTransformerRegistry.register(new JsonObjectToDataFlowTerminateMessageTransformer());
signalingApiTypeTransformerRegistry.register(new JsonObjectToDataAddressDspaceTransformer());
signalingApiTypeTransformerRegistry.register(new JsonObjectFromDataFlowResponseMessageTransformer(factory));
signalingApiTypeTransformerRegistry.register(new JsonObjectFromDataAddressDspaceTransformer(factory, jsonLdMapper));

var controller = new DataPlaneSignalingApiController(signalingApiTypeTransformerRegistry,
dataPlaneManager, context.getMonitor().withPrefix("SignalingAPI"));
webService.registerResource(signalingApiConfiguration.getContextAlias(), controller);

webService.registerResource(controlApiConfiguration.getContextAlias(), controller);
registerSignalingContext(controller);
}

@Deprecated(since = "0.6.4")
private void registerSignalingContext(DataPlaneSignalingApiController controller) {
webService.registerResource(signalingApiConfiguration.getContextAlias(), controller);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ plugins {
}

dependencies {
// these must be implementation dependencies as opposed to runtimeOnly, because otherwise
// this module isn't getting compiled when the :tests module is compiled
implementation(project(":extensions:data-plane:data-plane-signaling:data-plane-signaling-api"))
implementation(project(":extensions:data-plane:data-plane-signaling:data-plane-signaling-api-configuration"))
implementation(project(":core:data-plane:data-plane-core"))
implementation(project(":extensions:control-plane:api:control-plane-api-client"))
implementation(project(":extensions:data-plane:data-plane-http"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void startTransfer() throws JsonProcessingException {
var flowMessage = createStartMessage(processId);
var startMessage = registry.transform(flowMessage, JsonObject.class).orElseThrow(failTest());

var resultJson = DATAPLANE.getDataPlaneSignalingEndpoint()
var resultJson = DATAPLANE.getDataPlaneControlEndpoint()
.baseRequest()
.contentType(ContentType.JSON)
.body(startMessage)
Expand Down Expand Up @@ -121,7 +121,7 @@ void getState() {
.build();
runtime.getService(DataPlaneStore.class).save(flow);

var resultJson = DATAPLANE.getDataPlaneSignalingEndpoint()
var resultJson = DATAPLANE.getDataPlaneControlEndpoint()
.baseRequest()
.contentType(ContentType.JSON)
.get("/v1/dataflows/%s/state".formatted(dataFlowId))
Expand Down Expand Up @@ -153,7 +153,7 @@ void terminate() {
.add(DATA_FLOW_TERMINATE_MESSAGE_REASON, "test-reason")
.build();

DATAPLANE.getDataPlaneSignalingEndpoint()
DATAPLANE.getDataPlaneControlEndpoint()
.baseRequest()
.body(terminateMessage)
.contentType(ContentType.JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ public class DataPlaneParticipant extends Participant {
private final URI dataPlaneDefault = URI.create("http://localhost:" + getFreePort());
private final URI dataPlaneControl = URI.create("http://localhost:" + getFreePort() + "/control");
private final URI dataPlanePublic = URI.create("http://localhost:" + getFreePort() + "/public");
private final URI dataPlaneSignaling = URI.create("http://localhost:" + getFreePort() + "/api/signaling");

private DataPlaneParticipant() {
super();
}

public Endpoint getDataPlaneSignalingEndpoint() {
return new Endpoint(dataPlaneSignaling);
public Endpoint getDataPlaneControlEndpoint() {
return new Endpoint(dataPlaneControl);
}

public Endpoint getDataPlanePublicEndpoint() {
Expand All @@ -54,8 +53,6 @@ public Map<String, String> dataPlaneConfiguration() {
put("web.http.public.path", "/public");
put("web.http.control.port", String.valueOf(dataPlaneControl.getPort()));
put("web.http.control.path", dataPlaneControl.getPath());
put("web.http.signaling.port", String.valueOf(dataPlaneSignaling.getPort()));
put("web.http.signaling.path", dataPlaneSignaling.getPath());
put("edc.vault", resourceAbsolutePath(getName() + "-vault.properties"));
put("edc.keystore", resourceAbsolutePath("certs/cert.pfx"));
put("edc.keystore.password", "123456");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class TransferEndToEndParticipant extends Participant {
private final URI controlPlaneControl = URI.create("http://localhost:" + getFreePort() + "/control");
private final URI dataPlaneDefault = URI.create("http://localhost:" + getFreePort());
private final URI dataPlaneControl = URI.create("http://localhost:" + getFreePort() + "/control");
private final URI dataPlaneSignaling = URI.create("http://localhost:" + getFreePort() + "/signaling");
private final URI dataPlanePublic = URI.create("http://localhost:" + getFreePort() + "/public");
private final URI backendService = URI.create("http://localhost:" + getFreePort());

Expand Down Expand Up @@ -77,7 +76,7 @@ public URI backendService() {
*/
@Deprecated(since = "0.6.3")
public void registerDataPlane(Set<String> transferTypes) {
registerDataPlane(dataPlaneSignaling + "/v1/dataflows", Set.of("HttpData", "HttpProvision", "Kafka"), Set.of("HttpData", "HttpProvision", "HttpProxy", "Kafka"), transferTypes);
registerDataPlane(dataPlaneControl + "/v1/dataflows", Set.of("HttpData", "HttpProvision", "Kafka"), Set.of("HttpData", "HttpProvision", "HttpProxy", "Kafka"), transferTypes);
}

/**
Expand Down Expand Up @@ -159,8 +158,6 @@ public Map<String, String> dataPlaneConfiguration() {
put("web.http.public.path", "/public");
put("web.http.control.port", String.valueOf(dataPlaneControl.getPort()));
put("web.http.control.path", dataPlaneControl.getPath());
put("web.http.signaling.port", String.valueOf(dataPlaneSignaling.getPort()));
put("web.http.signaling.path", dataPlaneSignaling.getPath());
put("edc.vault", resourceAbsolutePath(getName() + "-vault.properties"));
put("edc.keystore", resourceAbsolutePath("certs/cert.pfx"));
put("edc.keystore.password", "123456");
Expand Down

0 comments on commit 162f5fe

Please sign in to comment.