Skip to content

Commit

Permalink
fix: use constant as API context (#195)
Browse files Browse the repository at this point in the history
* fix: use constant for api context

* fix api tests

* fix component test

* DEPENDENCIES

* fix launcher test
  • Loading branch information
paullatzelsperger authored Jun 4, 2024
1 parent c2cf5d5 commit 494d40a
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 69 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ jobs:

- name: 'Start FCC Container'
run: |
docker run -d --rm --name fcc federated-catalog:latest
docker run -d --rm --name fcc \
-e "WEB_HTTP_CATALOG_PORT=8183" \
-e "WEB_HTTP_CATALOG_PATH=/catalog" \
federated-catalog:latest
- name: 'Wait for Federated Catalog to be healthy'
uses: raschmitt/wait-for-healthy-container@v1
Expand Down
80 changes: 41 additions & 39 deletions DEPENDENCIES

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion extensions/api/federated-catalog-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ plugins {
dependencies {
api(project(":spi:federated-catalog-spi"))
api(libs.edc.spi.core)
api(libs.edc.spi.contract)
implementation(libs.edc.spi.transform)
implementation(libs.edc.spi.web)
implementation(libs.edc.lib.jerseyproviders)

implementation(libs.edc.api.management.config)
runtimeOnly(libs.edc.spi.jsonld)
runtimeOnly(libs.edc.json.ld.lib)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,30 @@

package org.eclipse.edc.catalog.api.query;

import org.eclipse.edc.catalog.spi.FccApiContexts;
import org.eclipse.edc.catalog.spi.QueryEngine;
import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration;
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.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.health.HealthCheckResult;
import org.eclipse.edc.spi.system.health.HealthCheckService;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.web.jersey.providers.jsonld.JerseyJsonLdInterceptor;
import org.eclipse.edc.web.jersey.providers.jsonld.ObjectMapperProvider;
import org.eclipse.edc.web.spi.WebService;

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.constants.CoreConstants.JSON_LD;

@Extension(value = FederatedCatalogCacheQueryApiExtension.NAME)
public class FederatedCatalogCacheQueryApiExtension implements ServiceExtension {

public static final String NAME = "Cache Query API Extension";
private static final String CATALOG_QUERY_SCOPE = "CATALOG_QUERY_API";
@Inject
private WebService webService;

Expand All @@ -37,9 +46,10 @@ public class FederatedCatalogCacheQueryApiExtension implements ServiceExtension

@Inject(required = false)
private HealthCheckService healthCheckService;

@Inject
private ManagementApiConfiguration config;
private JsonLd jsonLd;
@Inject
private TypeManager typeManager;

@Inject
private TypeTransformerRegistry transformerRegistry;
Expand All @@ -51,8 +61,12 @@ public String name() {

@Override
public void initialize(ServiceExtensionContext context) {
jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, CATALOG_QUERY_SCOPE);
var jsonLdMapper = typeManager.getMapper(JSON_LD);
var catalogController = new FederatedCatalogApiController(queryEngine, transformerRegistry);
webService.registerResource(config.getContextAlias(), catalogController);
webService.registerResource(FccApiContexts.CATALOG_QUERY, catalogController);
webService.registerResource(FccApiContexts.CATALOG_QUERY, new ObjectMapperProvider(jsonLdMapper));
webService.registerResource(FccApiContexts.CATALOG_QUERY, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, CATALOG_QUERY_SCOPE));

// contribute to the liveness probe
if (healthCheckService != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@
@ApiTest
@ExtendWith(EdcExtension.class)
class FederatedCatalogApiControllerTest {
private static final String BASE_PATH = "/api";
private static final String BASE_PATH = "/api/catalog";
private final int port = getFreePort();

@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(port),
"web.http.path", BASE_PATH
"web.http.path", "/api",
"web.http.port", String.valueOf(getFreePort()),
"web.http.catalog.port", String.valueOf(port),
"web.http.catalog.path", BASE_PATH
));
extension.registerSystemExtension(ServiceExtension.class, new TransformerRegistrarExtension());
}
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jackson = "2.17.1"
awaitility = { module = "org.awaitility:awaitility", version.ref = "awaitility" }
edc-api-management = { module = "org.eclipse.edc:management-api", version.ref = "edc" }
edc-api-management-config = { module = "org.eclipse.edc:management-api-configuration", version.ref = "edc" }
edc-api-control-config = { module = "org.eclipse.edc:control-api-configuration", version.ref = "edc" }
edc-api-observability = { module = "org.eclipse.edc:api-observability", version.ref = "edc" }
edc-boot = { module = "org.eclipse.edc:boot", version.ref = "edc" }
edc-config-filesystem = { module = "org.eclipse.edc:configuration-filesystem", version.ref = "edc" }
Expand Down Expand Up @@ -48,6 +49,7 @@ edc-lib-boot = { module = "org.eclipse.edc:boot-lib", version.ref = "edc" }
edc-lib-providers-jersey = { module = "org.eclipse.edc:jersey-providers-lib", version.ref = "edc" }
edc-lib-transform = { module = "org.eclipse.edc:transform-lib", version.ref = "edc" }
edc-lib-util = { module = "org.eclipse.edc:util-lib", version.ref = "edc" }
edc-lib-jerseyproviders = { module = "org.eclipse.edc:jersey-providers-lib", version.ref = "edc" }

# protocol modules
edc-dsp-api-configuration = { module = "org.eclipse.edc:dsp-http-api-configuration", version.ref = "edc" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.catalog.spi;

public interface FccApiContexts {
String CATALOG_QUERY = "catalog";
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import static org.eclipse.edc.catalog.spi.CatalogConstants.DATASPACE_PROTOCOL;
import static org.eclipse.edc.catalog.spi.CatalogConstants.PROPERTY_ORIGINATOR;
import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
Expand All @@ -89,8 +90,12 @@ void setup(EdcExtension extension) {
"edc.catalog.cache.partition.num.crawlers", "10",
// give the runtime time to set up everything
"edc.catalog.cache.execution.delay.seconds", "1",
"web.http.port", valueOf(TestFunctions.PORT),
"web.http.path", TestFunctions.BASE_PATH,
"web.http.catalog.port", valueOf(TestFunctions.CATALOG_QUERY_PORT),
"web.http.catalog.path", TestFunctions.CATALOG_QUERY_BASE_PATH,
"web.http.port", valueOf(getFreePort()),
"web.http.path", "/api/v1",
"web.http.protocol.port", valueOf(getFreePort()),
"web.http.protocol.path", "/api/v1/dsp",
"edc.participant.id", "test-participant"
));
dispatcher = mock(DspHttpRemoteMessageDispatcher.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
import static org.mockito.Mockito.mock;

public class TestFunctions {
public static final String BASE_PATH = "/api";
public static final int PORT = getFreePort();
public static final String CATALOG_QUERY_BASE_PATH = "/catalog";
public static final int CATALOG_QUERY_PORT = getFreePort();
private static final String PATH = "/federatedcatalog";
private static final TypeReference<List<Map<String, Object>>> MAP_TYPE = new TypeReference<>() {
};
Expand All @@ -66,8 +66,8 @@ public class TestFunctions {

private static RequestSpecification baseRequest() {
return given()
.baseUri("http://localhost:" + PORT)
.basePath(BASE_PATH)
.baseUri("http://localhost:" + CATALOG_QUERY_PORT)
.basePath(CATALOG_QUERY_BASE_PATH)
.contentType(ContentType.JSON)
.when();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
implementation(libs.edc.core.dataPlane.selector)
runtimeOnly(libs.edc.api.observability)
runtimeOnly(libs.edc.api.management)
runtimeOnly(libs.edc.api.control.config)
runtimeOnly(libs.edc.config.filesystem)
runtimeOnly(libs.edc.dpf.transfer)
runtimeOnly(libs.edc.ext.http)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import static java.lang.String.format;

class ManagementApiClient {
class CatalogApiClient {
private static final TypeReference<List<Map<String, Object>>> LIST_TYPE_REFERENCE = new TypeReference<>() {
};
private static final MediaType JSON = MediaType.parse("application/json");
Expand All @@ -46,9 +46,9 @@ class ManagementApiClient {
private final JsonLd jsonLdService;
private final TypeTransformerRegistry typeTransformerRegistry;

ManagementApiClient(Endpoint catalogManagement, Endpoint connectorManagement,
ObjectMapper mapper, JsonLd jsonLdService,
TypeTransformerRegistry typeTransformerRegistry) {
CatalogApiClient(Endpoint catalogManagement, Endpoint connectorManagement,
ObjectMapper mapper, JsonLd jsonLdService,
TypeTransformerRegistry typeTransformerRegistry) {
this.mapper = mapper;
this.jsonLdService = jsonLdService;
this.typeTransformerRegistry = typeTransformerRegistry;
Expand All @@ -61,11 +61,11 @@ Result<String> postAsset(JsonObject entry) {
}

Result<String> postPolicy(String policyJsonLd) {
return postObjectWithId(createPostRequest(policyJsonLd, managementBaseUrl + "/v2/policydefinitions"));
return postObjectWithId(createPostRequest(policyJsonLd, managementBaseUrl + "/v3/policydefinitions"));
}

Result<String> postContractDefinition(JsonObject definition) {
return postObjectWithId(createPostRequest(definition, managementBaseUrl + "/v2/contractdefinitions"));
return postObjectWithId(createPostRequest(definition, managementBaseUrl + "/v3/contractdefinitions"));
}

List<Catalog> getContractOffers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ class FederatedCatalogTest {
private static final Endpoint CONNECTOR_MANAGEMENT = new Endpoint("/management", "8081");
private static final Endpoint CONNECTOR_PROTOCOL = new Endpoint("/api/v1/dsp", "8082");
private static final Endpoint CONNECTOR_DEFAULT = new Endpoint("/api/v1/", "8080");
private static final Endpoint CONNECTOR_CONTROL = new Endpoint("/api/v1/control", "8093");
private static final Endpoint CONNECTOR_CONTROL = new Endpoint("/api/v1/control", "8083");

private static final Endpoint CATALOG_MANAGEMENT = new Endpoint("/management", "8091");
private static final Endpoint CATALOG_PROTOCOL = new Endpoint("/api/v1/dsp", "8092");
private static final Endpoint CATALOG_DEFAULT = new Endpoint("/api/v1/", "8090");
private static final Endpoint CATALOG_CATALOG = new Endpoint("/catalog", "8093");

@RegisterExtension
static EdcRuntimeExtension connector = new EdcRuntimeExtension(":system-tests:end2end-test:connector-runtime", "connector",
Expand Down Expand Up @@ -103,10 +104,12 @@ class FederatedCatalogTest {
"web.http.protocol.path", CATALOG_PROTOCOL.path(),
"web.http.management.port", CATALOG_MANAGEMENT.port(),
"web.http.management.path", CATALOG_MANAGEMENT.path(),
"web.http.catalog.port", CATALOG_CATALOG.port(),
"web.http.catalog.path", CATALOG_CATALOG.path(),
"edc.web.rest.cors.headers", "origin,content-type,accept,authorization,x-api-key"));
private final TypeTransformerRegistry typeTransformerRegistry = new TypeTransformerRegistryImpl();
private final ObjectMapper mapper = JacksonJsonLd.createObjectMapper();
private final ManagementApiClient apiClient = new ManagementApiClient(CATALOG_MANAGEMENT, CONNECTOR_MANAGEMENT, mapper, new TitaniumJsonLd(mock(Monitor.class)), typeTransformerRegistry);
private final CatalogApiClient apiClient = new CatalogApiClient(CATALOG_CATALOG, CONNECTOR_MANAGEMENT, mapper, new TitaniumJsonLd(mock(Monitor.class)), typeTransformerRegistry);

private static Map<String, String> configOf(String... keyValuePairs) {
if (keyValuePairs.length % 2 != 0) {
Expand Down Expand Up @@ -174,13 +177,11 @@ void crawl_whenOfferAvailable_shouldContainOffer(TestInfo testInfo) {
var catalogs = apiClient.getContractOffers();

assertThat(catalogs).hasSizeGreaterThanOrEqualTo(1);
assertThat(catalogs).anySatisfy(catalog -> {
assertThat(catalog.getDatasets())
.anySatisfy(dataset -> {
assertThat(dataset.getOffers()).hasSizeGreaterThanOrEqualTo(1);
assertThat(dataset.getOffers().keySet()).anyMatch(key -> key.contains(assetIdBase64));
});
});
assertThat(catalogs).anySatisfy(catalog -> assertThat(catalog.getDatasets())
.anySatisfy(dataset -> {
assertThat(dataset.getOffers()).hasSizeGreaterThanOrEqualTo(1);
assertThat(dataset.getOffers().keySet()).anyMatch(key -> key.contains(assetIdBase64));
}));

});
}
Expand Down

0 comments on commit 494d40a

Please sign in to comment.