Skip to content

Commit

Permalink
disable by default, add simple node directory
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Jul 8, 2024
1 parent 3a8971f commit 8641e42
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,12 @@ spec:
value: {{ .Values.controlplane.endpoints.protocol.port | quote }}
- name: "WEB_HTTP_PROTOCOL_PATH"
value: {{ .Values.controlplane.endpoints.protocol.path | quote }}
- name: "EDC_CONTROL_ENDPOINT"
value: {{ include "txdc.controlplane.url.control" .}}
- name: "WEB_HTTP_CATALOG_PORT"
value: {{ .Values.controlplane.endpoints.catalog.port | quote }}
- name: "WEB_HTTP_CATALOG_PATH"
value: {{ .Values.controlplane.endpoints.catalog.path | quote }}
- name: "EDC_CONTROL_ENDPOINT"
value: {{ include "txdc.controlplane.url.control" .}}

#########
## DSP ##
#########
Expand Down Expand Up @@ -340,6 +339,9 @@ spec:
value: {{ .Values.controlplane.catalog.crawler.num }}
{{- end }}

- name: "EDC_CATALOG_CACHE_EXECUTION_ENABLED"
value: {{ .Values.controlplane.catalog.enabled | quote }}

######################################
## Additional environment variables ##
######################################
Expand Down
2 changes: 2 additions & 0 deletions charts/tractusx-connector/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ controlplane:

# -- configuration for the built-in federated catalog crawler
catalog:
# -- Flag to globally enable/disable the FC feature
enabled: false
crawler:
# -- Number of desired crawlers. Final number might be different, based on number of crawl targets
num:
Expand Down
1 change: 1 addition & 0 deletions edc-controlplane/edc-controlplane-base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ dependencies {
runtimeOnly(libs.edc.controlplane.callback.dispatcher.http)

// Federated Catalog Crawler + Query API
runtimeOnly(project(":edc-extensions:federated-catalog"))
runtimeOnly(libs.edc.fc.core)
runtimeOnly(libs.edc.fc.api)

Expand Down
30 changes: 30 additions & 0 deletions edc-extensions/federated-catalog/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
`maven-publish`
`java-library`
}

dependencies {
implementation(libs.edc.spi.core)
implementation(libs.edc.fc.spi.crawler)

testImplementation(libs.edc.junit)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.eclipse.tractusx.edc.federatedcatalog;

import org.eclipse.edc.crawler.spi.TargetNode;
import org.eclipse.edc.crawler.spi.TargetNodeDirectory;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.types.TypeManager;

import java.io.File;
import java.util.Collections;
import java.util.List;

import static java.util.Optional.ofNullable;
import static org.eclipse.tractusx.edc.federatedcatalog.FederatedCatalogExtension.NAME;


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

public static final String NAME = "Tractus-X Federated Catalog Extension";

@Setting(value = "File path to a JSON file containing TargetNode entries for the Federated Catalog Crawler")
public static final String NODE_LIST_FILE = "tx.edc.catalog.node.list.file";

@Inject
private TypeManager typeManager;


@Override
public String name() {
return NAME;
}

@Provider
public TargetNodeDirectory createFileBasedNodeDirectory(ServiceExtensionContext context) {
return ofNullable(context.getConfig().getString(NODE_LIST_FILE, null))
.map(File::new)
.map(f -> (TargetNodeDirectory) new FileBasedTargetNodeDirectory(f, context.getMonitor(), typeManager.getMapper()))
.orElseGet(() -> {
context.getMonitor().warning("No TargetNode file configured ('%s'). Federated Catalog Crawler will be inactive.".formatted(NODE_LIST_FILE));
return new NoopNodeDirectory();
});

}

private static class NoopNodeDirectory implements TargetNodeDirectory {
@Override
public List<TargetNode> getAll() {
return Collections.emptyList();
}

@Override
public void insert(TargetNode targetNode) {

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.eclipse.tractusx.edc.federatedcatalog;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.edc.crawler.spi.TargetNode;
import org.eclipse.edc.crawler.spi.TargetNodeDirectory;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
* File-based implementation of the {@link TargetNodeDirectory} that returns a static {@code List<TargetNode>} that are
* serialized as JSON and stored in a file.
*/
class FileBasedTargetNodeDirectory implements TargetNodeDirectory {

private static final TypeReference<List<TargetNode>> LIST_TYPE = new TypeReference<>() {
};
private final File nodeFile;
private final Monitor monitor;
private final ObjectMapper objectMapper;
private List<TargetNode> nodes;

FileBasedTargetNodeDirectory(File nodeFile, Monitor monitor, ObjectMapper objectMapper) {

this.nodeFile = nodeFile;
this.monitor = monitor;
this.objectMapper = objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
}

@Override
public List<TargetNode> getAll() {

if (nodes == null) {
try {
nodes = objectMapper.readValue(nodeFile, LIST_TYPE);
} catch (IOException e) {
throw new EdcException(e);
}
}
return nodes;

}

@Override
public void insert(TargetNode targetNode) {
monitor.warning("Inserting nodes into the file-based TargetNodeDirectory is not supported.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#################################################################################
# Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
# Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# 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.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
#################################################################################

org.eclipse.tractusx.edc.federatedcatalog.FederatedCatalogExtension
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.eclipse.tractusx.edc.federatedcatalog;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.edc.crawler.spi.TargetNode;
import org.eclipse.edc.junit.testfixtures.TestUtils;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

class FileBasedTargetNodeDirectoryTest {

@Test
void getAll_hasEntries() {
var nodeDir = new FileBasedTargetNodeDirectory(TestUtils.getFileFromResourceName("nodes.json"), mock(), new ObjectMapper());
assertThat(nodeDir.getAll()).hasSize(2);
}

@Test
void getAll_fileNotExist() {
var nodeDir = new FileBasedTargetNodeDirectory(new File("not-exist.json"), mock(), new ObjectMapper());
assertThatThrownBy(nodeDir::getAll)
.isInstanceOf(EdcException.class)
.hasRootCauseInstanceOf(FileNotFoundException.class);
}

@Test
void insert() {
var monitor = mock(Monitor.class);
var nodeDir = new FileBasedTargetNodeDirectory(new File("not-exist.json"), monitor, new ObjectMapper());

assertThatNoException().isThrownBy(() -> nodeDir.insert(new TargetNode("foo", "bar", "https://foobar.com", List.of())));
verify(monitor).warning("Inserting nodes into the file-based TargetNodeDirectory is not supported.");
}
}
14 changes: 14 additions & 0 deletions edc-extensions/federated-catalog/src/test/resources/nodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "test-1",
"url": "http://nodes.com/test-1",
"id": "1",
"supportedProtocols": "test-protocol"
},
{
"name": "test-2",
"url": "http://nodes.com/test-2",
"id": "2",
"supportedProtocols": "another-test-protocol"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ iatp:
id: "test-client-id"
secret_alias: "test-alias"
controlplane:
debug:
enabled: true
port: 1044
suspendOnStart: false
service:
type: NodePort
endpoints:
Expand All @@ -54,7 +58,7 @@ controlplane:
dataplane:
debug:
enabled: true
port: 1044
port: 1045
suspendOnStart: false
endpoints:
proxy:
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
format.version = "1.1"

[versions]
edc = "0.7.2-20240705-SNAPSHOT"
edc = "0.7.2-SNAPSHOT"
assertj = "3.26.0"
awaitility = "4.2.1"
aws = "2.26.14"
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ include(":edc-extensions:migrations:data-plane-migration")
include(":edc-extensions:tokenrefresh-handler")
include(":edc-extensions:bdrs-client")
include(":edc-extensions:provision-additional-headers")
include(":edc-extensions:federated-catalog")
include(":edc-extensions:edr:edr-api-v2")
include(":edc-extensions:edr:edr-callback")
include(":edc-extensions:cx-policy")
Expand Down

0 comments on commit 8641e42

Please sign in to comment.