-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce configuration f. SignalinAPI (#3938)
* chore: rename parameters * feat: introduce configuration module for the signaling API extension
- Loading branch information
1 parent
a477eba
commit 4ec736b
Showing
18 changed files
with
337 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...java/org/eclipse/edc/connector/api/signaling/configuration/SignalingApiConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...eclipse/edc/connector/api/signaling/configuration/SignalingApiConfigurationExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...guration/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
75 changes: 75 additions & 0 deletions
75
...pse/edc/connector/api/signaling/configuration/SignalingApiConfigurationExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
extensions/data-plane/data-plane-signaling/data-plane-signaling-api/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
|
||
|
46 changes: 46 additions & 0 deletions
46
...src/main/java/org/eclipse/edc/connector/dataplane/api/DataPlaneSignalingApiExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.