Skip to content

Commit

Permalink
pr remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Dec 16, 2024
1 parent 53511b7 commit 2a148c7
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.ApiContext;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;

import java.util.Map;

Expand Down Expand Up @@ -103,7 +103,7 @@ public class DspApiConfigurationExtension implements ServiceExtension {
@Inject
private Hostname hostname;
@Inject
private PortMappings portMappings;
private PortMappingRegistry portMappingRegistry;

@Override
public String name() {
Expand All @@ -113,7 +113,7 @@ public String name() {
@Override
public void initialize(ServiceExtensionContext context) {
var portMapping = new PortMapping(ApiContext.PROTOCOL, apiConfiguration.port(), apiConfiguration.path());
portMappings.register(portMapping);
portMappingRegistry.register(portMapping);

var dspWebhookAddress = ofNullable(callbackAddress).orElseGet(() -> format("http://%s:%s%s", hostname.get(), portMapping.port(), portMapping.path()));
context.registerService(ProtocolWebhook.class, () -> dspWebhookAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.ApiContext;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -63,12 +63,12 @@ class DspApiConfigurationExtensionTest {
private final WebService webService = mock();
private final TypeManager typeManager = mock();
private final JsonLd jsonLd = mock();
private final PortMappings portMappings = mock();
private final PortMappingRegistry portMappingRegistry = mock();


@BeforeEach
void setUp(ServiceExtensionContext context) {
context.registerService(PortMappings.class, portMappings);
context.registerService(PortMappingRegistry.class, portMappingRegistry);
context.registerService(WebService.class, webService);
context.registerService(TypeManager.class, typeManager);
context.registerService(Hostname.class, () -> "hostname");
Expand All @@ -86,7 +86,7 @@ void shouldComposeProtocolWebhook_whenNotConfigured(DspApiConfigurationExtension

extension.initialize(context);

verify(portMappings).register(new PortMapping(ApiContext.PROTOCOL, DEFAULT_PROTOCOL_PORT, DEFAULT_PROTOCOL_PATH));
verify(portMappingRegistry).register(new PortMapping(ApiContext.PROTOCOL, DEFAULT_PROTOCOL_PORT, DEFAULT_PROTOCOL_PATH));
assertThat(context.getService(ProtocolWebhook.class).url()).isEqualTo("http://hostname:%s%s".formatted(DEFAULT_PROTOCOL_PORT, DEFAULT_PROTOCOL_PATH));
}

Expand All @@ -102,7 +102,7 @@ void shouldUseConfiguredProtocolWebhook(ServiceExtensionContext context, ObjectF

extension.initialize(context);

verify(portMappings).register(new PortMapping(ApiContext.PROTOCOL, 1234, "/path"));
verify(portMappingRegistry).register(new PortMapping(ApiContext.PROTOCOL, 1234, "/path"));
assertThat(context.getService(ProtocolWebhook.class).url()).isEqualTo("http://webhook");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.ApiContext;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;
import org.eclipse.edc.web.spi.configuration.context.ControlApiUrl;

import java.io.IOException;
Expand Down Expand Up @@ -74,7 +74,7 @@ public class ControlApiConfigurationExtension implements ServiceExtension {
private ControlApiConfiguration apiConfiguration;

@Inject
private PortMappings portMappings;
private PortMappingRegistry portMappingRegistry;
@Inject
private WebService webService;
@Inject
Expand All @@ -96,7 +96,7 @@ public String name() {
@Override
public void initialize(ServiceExtensionContext context) {
var portMapping = new PortMapping(ApiContext.CONTROL, apiConfiguration.port(), apiConfiguration.path());
portMappings.register(portMapping);
portMappingRegistry.register(portMapping);
var jsonLdMapper = typeManager.getMapper(JSON_LD);
context.registerService(ControlApiUrl.class, controlApiUrl(context, portMapping));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.ApiContext;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;
import org.eclipse.edc.web.spi.configuration.context.ControlApiUrl;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -56,13 +56,13 @@
@ExtendWith(DependencyInjectionExtension.class)
public class ControlApiConfigurationExtensionTest {

private final PortMappings portMappings = mock();
private final PortMappingRegistry portMappingRegistry = mock();
private final WebService webService = mock();
private final JsonLd jsonLd = mock();

@BeforeEach
void setUp(ServiceExtensionContext context) {
context.registerService(PortMappings.class, portMappings);
context.registerService(PortMappingRegistry.class, portMappingRegistry);
context.registerService(Hostname.class, () -> "hostname");
context.registerService(WebService.class, webService);
context.registerService(TypeManager.class, new JacksonTypeManager());
Expand All @@ -75,7 +75,7 @@ void shouldComposeControlApiUrl(ControlApiConfigurationExtension extension, Serv

extension.initialize(context);

verify(portMappings).register(new PortMapping(ApiContext.CONTROL, DEFAULT_CONTROL_PORT, DEFAULT_CONTROL_PATH));
verify(portMappingRegistry).register(new PortMapping(ApiContext.CONTROL, DEFAULT_CONTROL_PORT, DEFAULT_CONTROL_PATH));
var url = context.getService(ControlApiUrl.class);
assertThat(url.get().toString()).isEqualTo("http://hostname:%s%s".formatted(DEFAULT_CONTROL_PORT, DEFAULT_CONTROL_PATH));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.ApiContext;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;
import org.eclipse.edc.web.spi.configuration.context.ManagementApiUrl;

import java.io.IOException;
Expand Down Expand Up @@ -97,7 +97,7 @@ public class ManagementApiConfigurationExtension implements ServiceExtension {
@Inject
private ApiAuthenticationRegistry authenticationRegistry;
@Inject
private PortMappings portMappings;
private PortMappingRegistry portMappingRegistry;
@Inject
private TypeManager typeManager;
@Inject
Expand All @@ -120,7 +120,7 @@ public String name() {
@Override
public void initialize(ServiceExtensionContext context) {
var portMapping = new PortMapping(ApiContext.MANAGEMENT, apiConfiguration.port(), apiConfiguration.path());
portMappings.register(portMapping);
portMappingRegistry.register(portMapping);

context.registerService(ManagementApiUrl.class, managementApiUrl(context, portMapping));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.ApiContext;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -59,7 +59,7 @@
@ExtendWith(DependencyInjectionExtension.class)
class ManagementApiConfigurationExtensionTest {

private final PortMappings portMappings = mock();
private final PortMappingRegistry portMappingRegistry = mock();
private final Monitor monitor = mock();
private final WebService webService = mock();
private final JsonLd jsonLd = mock();
Expand All @@ -72,7 +72,7 @@ void setUp(ServiceExtensionContext context, ObjectFactory factory) {
when(typeTransformerRegistry.forContext(any())).thenReturn(contextTypeTransformerRegistry);
when(contextTypeTransformerRegistry.forContext(any())).thenReturn(mock());
context.registerService(WebService.class, webService);
context.registerService(PortMappings.class, portMappings);
context.registerService(PortMappingRegistry.class, portMappingRegistry);
context.registerService(TypeTransformerRegistry.class, typeTransformerRegistry);
context.registerService(TypeManager.class, new JacksonTypeManager());
context.registerService(JsonLd.class, jsonLd);
Expand All @@ -85,7 +85,7 @@ void initialize_shouldConfigureAndRegisterResource() {

extension.initialize(context);

verify(portMappings).register(new PortMapping(ApiContext.MANAGEMENT, DEFAULT_MANAGEMENT_PORT, DEFAULT_MANAGEMENT_PATH));
verify(portMappingRegistry).register(new PortMapping(ApiContext.MANAGEMENT, DEFAULT_MANAGEMENT_PORT, DEFAULT_MANAGEMENT_PATH));
verify(webService).registerResource(eq(ApiContext.MANAGEMENT), isA(AuthenticationRequestFilter.class));
verify(webService).registerResource(eq(ApiContext.MANAGEMENT), isA(JerseyJsonLdInterceptor.class));
verify(webService).registerResource(eq(ApiContext.MANAGEMENT), isA(ObjectMapperProvider.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.ApiContext;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;

import java.io.IOException;
import java.util.stream.Stream;
Expand All @@ -53,7 +53,7 @@ public class VersionApiExtension implements ServiceExtension {
@Inject
private ApiVersionService apiVersionService;
@Inject
private PortMappings portMappings;
private PortMappingRegistry portMappingRegistry;

@Override
public String name() {
Expand All @@ -63,7 +63,7 @@ public String name() {
@Override
public void initialize(ServiceExtensionContext context) {
var portMapping = new PortMapping(ApiContext.VERSION, apiConfiguration.port(), apiConfiguration.path());
portMappings.register(portMapping);
portMappingRegistry.register(portMapping);

webService.registerResource(ApiContext.VERSION, new VersionApiController(apiVersionService));
registerVersionInfo(getClass().getClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.web.jetty.JettyConfiguration;
import org.eclipse.edc.web.jetty.JettyService;
import org.eclipse.edc.web.jetty.PortMappingsImpl;
import org.eclipse.edc.web.jetty.PortMappingRegistryImpl;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -271,7 +271,7 @@ void verifyInvalidContextAlias_shouldThrowException() {

private void startJetty(PortMapping... mapping) {
var config = new JettyConfiguration(null, null);
var portMappings = new PortMappingsImpl();
var portMappings = new PortMappingRegistryImpl();
Arrays.stream(mapping).forEach(portMappings::register);
jettyService = new JettyService(config, monitor, portMappings);
jerseyRestService = new JerseyRestService(jettyService, new JacksonTypeManager(), JerseyConfiguration.Builder.newInstance().build(), monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.edc.web.jersey.providers.jsonld.ObjectMapperProvider;
import org.eclipse.edc.web.jetty.JettyConfiguration;
import org.eclipse.edc.web.jetty.JettyService;
import org.eclipse.edc.web.jetty.PortMappingsImpl;
import org.eclipse.edc.web.jetty.PortMappingRegistryImpl;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -45,7 +45,7 @@ public abstract class RestControllerTestBase {
@BeforeEach
final void startJetty() {
var config = new JettyConfiguration(null, null);
var portMappings = new PortMappingsImpl();
var portMappings = new PortMappingRegistryImpl();
portMappings.register(new PortMapping("test", port, "/"));
jetty = new JettyService(config, monitor, portMappings);
var jerseyService = new JerseyRestService(jetty, new JacksonTypeManager(), mock(JerseyConfiguration.class), monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.web.spi.WebServer;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;
import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer;

import java.io.FileInputStream;
Expand All @@ -47,7 +47,7 @@ public class JettyExtension implements ServiceExtension {
private static final String KEYSTORE_TYPE_SETTING = "edc.web.https.keystore.type";

private JettyService jettyService;
private final PortMappingsImpl portMappings = new PortMappingsImpl();
private final PortMappingRegistryImpl portMappings = new PortMappingRegistryImpl();

@Configuration
private JettyConfiguration jettyConfiguration;
Expand Down Expand Up @@ -106,7 +106,7 @@ public WebServiceConfigurer webServiceContextConfigurator(ServiceExtensionContex
}

@Provider
public PortMappings portMappings() {
public PortMappingRegistry portMappings() {
return portMappings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.web.spi.WebServer;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
Expand Down Expand Up @@ -59,18 +59,18 @@ public class JettyService implements WebServer {
private final KeyStore keyStore;
private final Map<String, ServletContextHandler> handlers = new HashMap<>();
private final List<Consumer<ServerConnector>> connectorConfigurationCallbacks = new ArrayList<>();
private final PortMappings portMappings;
private final PortMappingRegistry portMappingRegistry;
private Server server;

public JettyService(JettyConfiguration configuration, Monitor monitor, PortMappings portMappings) {
this(configuration, null, monitor, portMappings);
public JettyService(JettyConfiguration configuration, Monitor monitor, PortMappingRegistry portMappingRegistry) {
this(configuration, null, monitor, portMappingRegistry);
}

public JettyService(JettyConfiguration configuration, KeyStore keyStore, Monitor monitor, PortMappings portMappings) {
public JettyService(JettyConfiguration configuration, KeyStore keyStore, Monitor monitor, PortMappingRegistry portMappingRegistry) {
this.configuration = configuration;
this.keyStore = keyStore;
this.monitor = monitor;
this.portMappings = portMappings;
this.portMappingRegistry = portMappingRegistry;
System.setProperty(LOG_ANNOUNCE, "false");
// for websocket endpoints
handlers.put("/", new ServletContextHandler(null, "/", NO_SESSIONS));
Expand All @@ -79,7 +79,7 @@ public JettyService(JettyConfiguration configuration, KeyStore keyStore, Monitor
public void start() {
try {
server = new Server();
var portMappingsDescription = portMappings.getAll().stream()
var portMappingsDescription = portMappingRegistry.getAll().stream()
.peek(mapping -> {
server.addConnector(createConnector(mapping));
handlers.put(mapping.path(), createHandler(mapping));
Expand Down Expand Up @@ -113,7 +113,7 @@ public void registerServlet(String contextName, Servlet servlet) {
servletHolder.setServlet(servlet);
servletHolder.setInitOrder(1);

var actualPath = portMappings.getAll().stream()
var actualPath = portMappingRegistry.getAll().stream()
.filter(pm -> Objects.equals(contextName, pm.name()))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("No PortMapping for contextName '" + contextName + "' found"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package org.eclipse.edc.web.jetty;

import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PortMappingsImpl implements PortMappings {
public class PortMappingRegistryImpl implements PortMappingRegistry {

private final Map<Integer, PortMapping> portMappings = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.system.configuration.Config;
import org.eclipse.edc.web.spi.configuration.PortMapping;
import org.eclipse.edc.web.spi.configuration.PortMappings;
import org.eclipse.edc.web.spi.configuration.PortMappingRegistry;
import org.eclipse.edc.web.spi.configuration.WebServiceConfiguration;
import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer;
import org.eclipse.edc.web.spi.configuration.WebServiceSettings;
Expand All @@ -29,11 +29,11 @@
public class WebServiceConfigurerImpl implements WebServiceConfigurer {

private final Monitor monitor;
private final PortMappings portMappings;
private final PortMappingRegistry portMappingRegistry;

public WebServiceConfigurerImpl(Monitor monitor, PortMappings portMappings) {
public WebServiceConfigurerImpl(Monitor monitor, PortMappingRegistry portMappingRegistry) {
this.monitor = monitor;
this.portMappings = portMappings;
this.portMappingRegistry = portMappingRegistry;
}

@Override
Expand All @@ -51,7 +51,7 @@ public WebServiceConfiguration configure(Config config, WebServiceSettings setti
path = config.getString("path", path);
}

portMappings.register(new PortMapping(contextAlias, port, path));
portMappingRegistry.register(new PortMapping(contextAlias, port, path));

monitor.debug(format("%s API will be available under port=%s, path=%s", contextAlias, port, path));

Expand Down
Loading

0 comments on commit 2a148c7

Please sign in to comment.