Skip to content

Commit

Permalink
feat: register default PublicEndpointGenerator fct (eclipse-edc#3991)
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger authored Mar 12, 2024
1 parent 108dfe6 commit 20bb0a4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
package org.eclipse.edc.connector.dataplane.api;

import org.eclipse.edc.connector.dataplane.api.controller.DataPlanePublicApiV2Controller;
import org.eclipse.edc.connector.dataplane.spi.Endpoint;
import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAuthorizationService;
import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService;
import org.eclipse.edc.connector.dataplane.spi.pipeline.PipelineService;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.system.ExecutorInstrumentation;
import org.eclipse.edc.spi.system.Hostname;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.web.spi.WebServer;
Expand All @@ -36,13 +40,17 @@
@Extension(value = DataPlanePublicApiExtension.NAME)
public class DataPlanePublicApiExtension implements ServiceExtension {
public static final String NAME = "Data Plane Public API";
private static final int DEFAULT_PUBLIC_PORT = 8185;
private static final String PUBLIC_API_CONFIG = "web.http.public";
private static final String PUBLIC_CONTEXT_ALIAS = "public";
private static final String PUBLIC_CONTEXT_PATH = "/api/v2/public";

private static final int DEFAULT_THREAD_POOL = 10;

public static final int DEFAULT_PUBLIC_PORT = 8185;
public static final String PUBLIC_API_CONFIG = "web.http.public";
public static final String PUBLIC_CONTEXT_ALIAS = "public";
public static final String PUBLIC_CONTEXT_PATH = "/api/v2/public";
@Setting(value = "Base url of the public API endpoint without the trailing slash. This should correspond to the values configured " +
"in '" + DEFAULT_PUBLIC_PORT + "' and '" + PUBLIC_CONTEXT_PATH + "'.", defaultValue = "http://<HOST>:" + DEFAULT_PUBLIC_PORT + PUBLIC_CONTEXT_PATH)
public static final String PUBLIC_ENDPOINT = "edc.dataplane.api.public.baseurl";

private static final int DEFAULT_THREAD_POOL = 10;
private static final WebServiceSettings PUBLIC_SETTINGS = WebServiceSettings.Builder.newInstance()
.apiConfigKey(PUBLIC_API_CONFIG)
.contextAlias(PUBLIC_CONTEXT_ALIAS)
Expand All @@ -65,9 +73,16 @@ public class DataPlanePublicApiExtension implements ServiceExtension {

@Inject
private ExecutorInstrumentation executorInstrumentation;

@Inject
private DataPlaneAuthorizationService authorizationService;

@Inject
private PublicEndpointGeneratorService generatorService;

@Inject
private Hostname hostname;

@Override
public String name() {
return NAME;
Expand All @@ -80,6 +95,15 @@ public void initialize(ServiceExtensionContext context) {
Executors.newFixedThreadPool(DEFAULT_THREAD_POOL),
"Data plane proxy transfers"
);

var publicEndpoint = context.getSetting(PUBLIC_ENDPOINT, null);
if (publicEndpoint == null) {
publicEndpoint = "http://%s:%d%s".formatted(hostname.get(), configuration.getPort(), configuration.getPath());
context.getMonitor().warning("Config property '%s' was not specified, the default '%s' will be used.".formatted(PUBLIC_ENDPOINT, publicEndpoint));
}
var endpoint = Endpoint.url(publicEndpoint);
generatorService.addGeneratorFunction("HttpData", dataAddress -> endpoint);

var publicApiController = new DataPlanePublicApiV2Controller(pipelineService, executorService, authorizationService);
webService.registerResource(configuration.getContextAlias(), publicApiController);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.eclipse.edc.connector.api.signaling.transform.to.JsonObjectToDataFlowResponseMessageTransformer;
import org.eclipse.edc.connector.dataplane.spi.DataFlow;
import org.eclipse.edc.connector.dataplane.spi.DataFlowStates;
import org.eclipse.edc.connector.dataplane.spi.Endpoint;
import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService;
import org.eclipse.edc.connector.dataplane.spi.store.DataPlaneStore;
import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl;
import org.eclipse.edc.core.transform.transformer.dspace.from.JsonObjectFromDataAddressDspaceTransformer;
Expand Down Expand Up @@ -60,7 +58,7 @@
@EndToEndTest
public class DataPlaneSignalingApiEndToEndTest extends AbstractDataPlaneTest {

private static final String DATAPLANE_PUBLIC_ENDPOINT_URL = "http://fizz.buzz/bar";
private static final String DATAPLANE_PUBLIC_ENDPOINT_URL = DATAPLANE.getDataPlanePublicEndpoint().getUrl().toString();
private final TypeTransformerRegistry registry = new TypeTransformerRegistryImpl();
private ObjectMapper mapper;

Expand All @@ -77,8 +75,6 @@ void setup() {
@DisplayName("Verify the POST /v1/dataflows endpoint returns the correct EDR")
@Test
void startTransfer() throws JsonProcessingException {
var generator = runtime.getContext().getService(PublicEndpointGeneratorService.class);
generator.addGeneratorFunction("HttpData", dataAddress -> Endpoint.url(DATAPLANE_PUBLIC_ENDPOINT_URL));
var jsonLd = runtime.getContext().getService(JsonLd.class);

var processId = "test-processId";
Expand Down

0 comments on commit 20bb0a4

Please sign in to comment.