Skip to content

Commit

Permalink
feat: introduce configuration f. SignalinAPI (#3938)
Browse files Browse the repository at this point in the history
* chore: rename parameters

* feat: introduce configuration module for the signaling API extension
  • Loading branch information
paullatzelsperger authored Feb 29, 2024
1 parent a477eba commit 4ec736b
Show file tree
Hide file tree
Showing 18 changed files with 337 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ maven/mavencentral/com.lmax/disruptor/3.4.4, Apache-2.0, approved, clearlydefine
maven/mavencentral/com.networknt/json-schema-validator/1.0.76, Apache-2.0, approved, CQ22638
maven/mavencentral/com.nimbusds/nimbus-jose-jwt/9.28, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.nimbusds/nimbus-jose-jwt/9.37.3, Apache-2.0, approved, #11701
maven/mavencentral/com.puppycrawl.tools/checkstyle/10.13.0, LGPL-2.1-or-later AND (Apache-2.0 AND LGPL-2.1-or-later) AND Apache-2.0, approved, #13403
maven/mavencentral/com.puppycrawl.tools/checkstyle/10.14.0, , restricted, clearlydefined
maven/mavencentral/com.samskivert/jmustache/1.15, BSD-2-Clause, approved, clearlydefined
maven/mavencentral/com.squareup.okhttp3/okhttp-dnsoverhttps/4.12.0, Apache-2.0, approved, #11159
maven/mavencentral/com.squareup.okhttp3/okhttp/4.12.0, Apache-2.0, approved, #11156
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.edc.spi.system.configuration.Config;
import org.eclipse.edc.spi.system.configuration.ConfigFactory;
import org.eclipse.edc.spi.system.injection.ObjectFactory;
import org.eclipse.edc.web.jersey.jsonld.JerseyJsonLdInterceptor;
import org.eclipse.edc.web.jersey.jsonld.ObjectMapperProvider;
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.WebServiceConfiguration;
Expand All @@ -44,10 +45,10 @@
@ExtendWith(DependencyInjectionExtension.class)
class ManagementApiConfigurationExtensionTest {

private ManagementApiConfigurationExtension extension;
private final WebServiceConfigurer configurer = mock(WebServiceConfigurer.class);
private final Monitor monitor = mock(Monitor.class);
private final WebService webService = mock(WebService.class);
private ManagementApiConfigurationExtension extension;

@BeforeEach
void setUp(ServiceExtensionContext context, ObjectFactory factory) {
Expand All @@ -66,6 +67,7 @@ void initialize_shouldConfigureAndRegisterResource() {

verify(configurer).configure(any(), any(), eq(SETTINGS));
verify(webService).registerResource(eq("alias"), isA(AuthenticationRequestFilter.class));
verify(webService).registerResource(eq("alias"), isA(JerseyJsonLdInterceptor.class));
verify(webService).registerResource(eq("alias"), isA(ObjectMapperProvider.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@

plugins {
`java-library`
id("io.swagger.core.v3.swagger-gradle-plugin")
}

dependencies {
api(project(":spi:common:web-spi"))
api(project(":spi:common:json-ld-spi"))
api(project(":spi:common:web-spi"))
api(project(":spi:data-plane:data-plane-spi"))

implementation(project(":core:common:jersey-providers"))
implementation(libs.jakarta.rsApi)

testImplementation(project(":core:common:junit"))
}
edcBuild {
swagger {
Expand Down
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
*
*/

package org.eclipse.edc.connector.api.signaling.configuration;

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

public class SignalingApiConfiguration extends WebServiceConfiguration {

public SignalingApiConfiguration(String contextAlias) {
super();
this.contextAlias = contextAlias;
}

public SignalingApiConfiguration(WebServiceConfiguration webServiceConfiguration) {
this.contextAlias = webServiceConfiguration.getContextAlias();
this.path = webServiceConfiguration.getPath();
this.port = webServiceConfiguration.getPort();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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
*
*/

package org.eclipse.edc.connector.api.signaling.configuration;

import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provides;
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.web.jersey.jsonld.JerseyJsonLdInterceptor;
import org.eclipse.edc.web.jersey.jsonld.ObjectMapperProvider;
import org.eclipse.edc.web.spi.WebServer;
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer;
import org.eclipse.edc.web.spi.configuration.WebServiceSettings;

import static org.eclipse.edc.connector.api.signaling.configuration.SignalingApiConfigurationExtension.NAME;
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.CoreConstants.JSON_LD;

@Provides(SignalingApiConfiguration.class)
@Extension(value = NAME)
public class SignalingApiConfigurationExtension implements ServiceExtension {
public static final String NAME = "DataPlane Signaling API Configuration Extension";
public static final String WEB_SERVICE_NAME = "DataPlane Signaling API";

private static final String SIGNALING_CONTEXT_ALIAS = "signaling";
private static final String DEFAULT_SIGNALING_API_CONTEXT_PATH = "/api/signaling";
private static final int DEFAULT_SIGNALING_API_PORT = 10080;
public static final WebServiceSettings SETTINGS = WebServiceSettings.Builder.newInstance()
.apiConfigKey("web.http." + SIGNALING_CONTEXT_ALIAS)
.contextAlias(SIGNALING_CONTEXT_ALIAS)
.defaultPath(DEFAULT_SIGNALING_API_CONTEXT_PATH)
.defaultPort(DEFAULT_SIGNALING_API_PORT)
.useDefaultContext(true)
.name(WEB_SERVICE_NAME)
.build();
private static final String SIGNALING_SCOPE = "SIGNALING_API";

@Inject
private WebService webService;
@Inject
private WebServiceConfigurer configurer;
@Inject
private WebServer webServer;
@Inject
private JsonLd jsonLd;
@Inject
private TypeManager typeManager;

@Override
public String name() {
return NAME;
}

@Override
public void initialize(ServiceExtensionContext context) {
var webServiceConfiguration = configurer.configure(context, webServer, SETTINGS);
context.registerService(SignalingApiConfiguration.class, new SignalingApiConfiguration(webServiceConfiguration));

jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, SIGNALING_SCOPE);
var jsonLdMapper = typeManager.getMapper(JSON_LD);
webService.registerResource(webServiceConfiguration.getContextAlias(), new ObjectMapperProvider(jsonLdMapper));
webService.registerResource(webServiceConfiguration.getContextAlias(), new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, SIGNALING_SCOPE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# 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
#
#

org.eclipse.edc.connector.api.signaling.configuration.SignalingApiConfigurationExtension
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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
*
*/

package org.eclipse.edc.connector.api.signaling.configuration;

import org.eclipse.edc.boot.system.DefaultServiceExtensionContext;
import org.eclipse.edc.junit.extensions.DependencyInjectionExtension;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.configuration.Config;
import org.eclipse.edc.spi.system.configuration.ConfigFactory;
import org.eclipse.edc.web.jersey.jsonld.JerseyJsonLdInterceptor;
import org.eclipse.edc.web.jersey.jsonld.ObjectMapperProvider;
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.WebServiceConfiguration;
import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.List;

import static org.eclipse.edc.connector.api.signaling.configuration.SignalingApiConfigurationExtension.SETTINGS;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(DependencyInjectionExtension.class)
class SignalingApiConfigurationExtensionTest {
private final WebServiceConfigurer configurer = mock(WebServiceConfigurer.class);
private final Monitor monitor = mock(Monitor.class);
private final WebService webService = mock(WebService.class);
private SignalingApiConfigurationExtension extension;

@BeforeEach
void setUp(ServiceExtensionContext context) {
context.registerService(WebService.class, webService);
context.registerService(WebServiceConfigurer.class, configurer);
}

@Test
void initialize_shouldConfigureAndRegisterResource(SignalingApiConfigurationExtension extension) {
var context = contextWithConfig(ConfigFactory.empty());
var configuration = WebServiceConfiguration.Builder.newInstance().contextAlias("alias").path("/path").port(1234).build();
when(configurer.configure(any(), any(), any())).thenReturn(configuration);

extension.initialize(context);

verify(configurer).configure(any(), any(), eq(SETTINGS));
verify(webService).registerResource(eq("alias"), isA(ObjectMapperProvider.class));
verify(webService).registerResource(eq("alias"), isA(JerseyJsonLdInterceptor.class));
}

@NotNull
private DefaultServiceExtensionContext contextWithConfig(Config config) {
var context = new DefaultServiceExtensionContext(monitor, List.of(() -> config));
context.initialize();
return context;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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`
id("io.swagger.core.v3.swagger-gradle-plugin")
}

dependencies {
api(project(":spi:common:web-spi"))
api(project(":spi:common:json-ld-spi"))
api(project(":spi:data-plane:data-plane-spi"))

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

}
edcBuild {
swagger {
apiGroup.set("control-api")
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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
*
*/

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

import org.eclipse.edc.connector.api.signaling.configuration.SignalingApiConfiguration;
import org.eclipse.edc.connector.dataplane.api.controller.v1.DataPlaneSignalingApiController;
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.web.spi.WebService;

import static org.eclipse.edc.connector.dataplane.api.DataPlaneSignalingApiExtension.NAME;

@Extension(NAME)
public class DataPlaneSignalingApiExtension implements ServiceExtension {
public static final String NAME = "DataPlane Signaling API extension";

@Inject
private WebService webService;

@Inject
private SignalingApiConfiguration controlApiConfiguration;

@Override
public String name() {
return NAME;
}

@Override
public void initialize(ServiceExtensionContext context) {
webService.registerResource(controlApiConfiguration.getContextAlias(), new DataPlaneSignalingApiController());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface DataPlaneSignalingApi {
content = @Content(schema = @Schema(implementation = DataFlowResponseMessageSchema.class))),
}
)
JsonObject start(JsonObject request, AsyncResponse response);
JsonObject start(JsonObject dataFlowStartMessage, AsyncResponse response);

@Operation(description = "Get the current state of a data transfer.",
responses = {
Expand All @@ -60,7 +60,7 @@ public interface DataPlaneSignalingApi {
@ApiResponse(responseCode = "404", description = "Data transfer not found in the data plane")
}
)
JsonObject getTransferState(String id);
JsonObject getTransferState(String transferProcessId);

@Operation(description = "Terminates a data transfer.",
requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = DataFlowTerminateMessageSchema.class))),
Expand All @@ -70,7 +70,7 @@ public interface DataPlaneSignalingApi {
@ApiResponse(responseCode = "409", description = "Cannot terminate the transfer"),
}
)
void terminate(String id, JsonObject body);
void terminate(String transferProcessId, JsonObject terminationMessage);

@Operation(description = "Suspend a data transfer.",
requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = DataFlowSuspendMessageSchema.class))),
Expand All @@ -80,7 +80,7 @@ public interface DataPlaneSignalingApi {
@ApiResponse(responseCode = "409", description = "Cannot suspend the transfer"),
}
)
void suspend(String transferProcessId, JsonObject body);
void suspend(String transferProcessId, JsonObject suspendMessage);


@Schema(name = "DataFlowStartMessage", example = DataFlowStartMessageSchema.DATA_FLOW_START_EXAMPLE)
Expand Down
Loading

0 comments on commit 4ec736b

Please sign in to comment.