Skip to content

Commit

Permalink
feat: introduce configuration module for the signaling API extension
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Feb 29, 2024
1 parent fd0f8aa commit efcc243
Show file tree
Hide file tree
Showing 17 changed files with 329 additions and 17 deletions.
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 @@ -22,6 +22,7 @@
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ws.rs.container.Suspended;
import jakarta.ws.rs.core.MediaType;

@Consumes({ MediaType.APPLICATION_JSON })
Expand All @@ -31,7 +32,7 @@ public class DataPlaneSignalingApiController implements DataPlaneSignalingApi {

@POST
@Override
public JsonObject start(JsonObject dataFlowStartMessage, AsyncResponse response) {
public JsonObject start(JsonObject dataFlowStartMessage, @Suspended AsyncResponse response) {
throw new UnsupportedOperationException();
}

Expand Down
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.dataplane.api.DataPlaneSignalingApiExtension
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ include(":extensions:control-plane:callback:callback-static-endpoint")

include(":extensions:data-plane:data-plane-client")
include(":extensions:data-plane:data-plane-control-api")
include(":extensions:data-plane:data-plane-signaling-api")
include(":extensions:data-plane:data-plane-signaling:data-plane-signaling-api")
include(":extensions:data-plane:data-plane-signaling:data-plane-signaling-api-configuration")
include(":extensions:data-plane:data-plane-public-api")

include(":extensions:data-plane:data-plane-http")
Expand Down
Loading

0 comments on commit efcc243

Please sign in to comment.