From d712e3e80b90cf5928a11c78d9d7139fa871c821 Mon Sep 17 00:00:00 2001 From: "Avishek Pathania (Cofinity-X)" Date: Tue, 24 Sep 2024 16:59:52 +0200 Subject: [PATCH] chore: [TRX-96] Adapt-Discovery-flow (bpnl) (#12) (cherry picked from commit 5ae81f4a3946f760ff2cc085154dc1eb04585418) --- CHANGELOG.md | 4 ++++ charts/item-relationship-service/CHANGELOG.md | 4 ++++ .../configmap-spring-app-config.yaml | 1 + charts/item-relationship-service/values.yaml | 1 + .../configuration/RegistryConfiguration.java | 6 +++-- .../registryclient/DefaultConfiguration.java | 5 +++-- .../discovery/ConnectorEndpointsService.java | 3 ++- .../DefaultConfigurationTest.java | 2 +- ...igitalTwinRegistryServiceWiremockTest.java | 2 +- .../ConnectorEndpointsServiceTest.java | 2 +- .../DiscoveryFinderClientImplTest.java | 2 +- .../discovery/templates/configmap.yaml | 22 +++++++++---------- 12 files changed, 34 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43edbf9d08..596a50569b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ _**For better traceability add the corresponding GitHub issue number in each cha ## [Unreleased] +### Changed + +- Added the discovery type configurable, with a default value of bpnl in (ConnectorEndpointsService) (#12) + ## [5.4.1] - 2024-08-19 ### Fixed diff --git a/charts/item-relationship-service/CHANGELOG.md b/charts/item-relationship-service/CHANGELOG.md index 5ce205eff0..50c8696113 100644 --- a/charts/item-relationship-service/CHANGELOG.md +++ b/charts/item-relationship-service/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Added the discovery type configurable (discovery.type) default value as bpnl. (#12). + ## [7.4.1] - 2024-08-19 ### Changed diff --git a/charts/item-relationship-service/templates/configmap-spring-app-config.yaml b/charts/item-relationship-service/templates/configmap-spring-app-config.yaml index aefab9cf42..7149cdc677 100644 --- a/charts/item-relationship-service/templates/configmap-spring-app-config.yaml +++ b/charts/item-relationship-service/templates/configmap-spring-app-config.yaml @@ -80,6 +80,7 @@ data: discovery: oAuthClientId: {{ .Values.discovery.oAuthClientId | default "discovery" }} # ID of the OAuth2 client registration to use, see config spring.security.oauth2.client discoveryFinderUrl: {{ tpl (.Values.discovery.discoveryFinderUrl | default "") . | quote }} # The endpoint to discover EDC endpoints to a particular BPN. + type: {{ .Values.discovery.type | default "bpnl" }} # Type to discover EDC of type "bpnl". semanticshub: url: {{ tpl (.Values.semanticshub.url | default "") . | quote }} diff --git a/charts/item-relationship-service/values.yaml b/charts/item-relationship-service/values.yaml index fa818ec8f6..2a5116b1fb 100644 --- a/charts/item-relationship-service/values.yaml +++ b/charts/item-relationship-service/values.yaml @@ -132,6 +132,7 @@ digitalTwinRegistry: discovery: oAuthClientId: discovery # ID of the OAuth2 client registration to use, see config spring.security.oauth2.client discoveryFinderUrl: # "https:// + type: "bpnl" # discovery type to find bpnl type in EDC discovery semanticshub: url: # https:// diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java index ec10c41d4a..b8cdd0bb49 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java @@ -97,10 +97,12 @@ public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService( @Bean public ConnectorEndpointsService connectorEndpointsService( @Qualifier(RestTemplateConfig.DTR_REST_TEMPLATE) final RestTemplate dtrRestTemplate, - @Value("${digitalTwinRegistry.discovery.discoveryFinderUrl:}") final String finderUrl) { - return new ConnectorEndpointsService(discoveryFinderClient(dtrRestTemplate, finderUrl)); + @Value("${digitalTwinRegistry.discovery.discoveryFinderUrl:}") final String finderUrl, + @Value("${digitalTwinRegistry.discovery.type:}") final String discoveryType) { + return new ConnectorEndpointsService(discoveryFinderClient(dtrRestTemplate, finderUrl), discoveryType); } + @Bean public DiscoveryFinderClient discoveryFinderClient( @Qualifier(RestTemplateConfig.DTR_REST_TEMPLATE) final RestTemplate dtrRestTemplate, diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java index 230c66d7ee..c87b8a7956 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java @@ -110,8 +110,9 @@ public DiscoveryFinderClient discoveryFinderClient( @Bean @ConditionalOnProperty(prefix = CONFIG_PREFIX, name = CONFIG_FIELD_TYPE, havingValue = CONFIG_VALUE_DECENTRAL) - public ConnectorEndpointsService connectorEndpointsService(final DiscoveryFinderClient discoveryFinderClient) { - return new ConnectorEndpointsService(discoveryFinderClient); + public ConnectorEndpointsService connectorEndpointsService(final DiscoveryFinderClient discoveryFinderClient, + @Value("${digitalTwinRegistryClient.discovery.type:}") final String discoveryType) { + return new ConnectorEndpointsService(discoveryFinderClient, discoveryType); } @Bean diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/discovery/ConnectorEndpointsService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/discovery/ConnectorEndpointsService.java index a5333b659d..43bb738fbe 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/discovery/ConnectorEndpointsService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/discovery/ConnectorEndpointsService.java @@ -43,6 +43,7 @@ public class ConnectorEndpointsService { private final DiscoveryFinderClient discoveryFinderClient; private static final String CONNECTOR_ENDPOINT_SERVICE_CACHE_NAME = "connector_endpoint_service_cache"; + private final String discoveryType; /** * Get EDCs for BPN. @@ -60,7 +61,7 @@ public List fetchConnectorEndpoints(final String bpn) { log.info("Requesting connector endpoints for BPN {}", bpn); - final var onlyBpn = new DiscoveryFinderRequest(List.of("bpn")); + final var onlyBpn = new DiscoveryFinderRequest(List.of(discoveryType)); final var discoveryEndpoints = discoveryFinderClient.findDiscoveryEndpoints(onlyBpn).endpoints(); final var endpoints = discoveryEndpoints.stream() .flatMap( diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/DefaultConfigurationTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/DefaultConfigurationTest.java index 22bbf0c673..33872ec491 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/DefaultConfigurationTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/DefaultConfigurationTest.java @@ -64,7 +64,7 @@ void centralDigitalTwinRegistryService() { void decentralDigitalTwinRegistryService() { final EdcSubmodelFacade facadeMock = mock(EdcSubmodelFacade.class); final var service = testee.decentralDigitalTwinRegistryService( - testee.connectorEndpointsService(testee.discoveryFinderClient(new RestTemplate(), "finder")), + testee.connectorEndpointsService(testee.discoveryFinderClient(new RestTemplate(), "finder"), "bpnl"), testee.endpointDataForConnectorsService(facadeMock), testee.decentralDigitalTwinRegistryClient(new RestTemplate(), descriptorTemplate, shellLookupTemplate), edcConfiguration); diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java index f34da42154..522686ed10 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java @@ -93,7 +93,7 @@ void setUp(WireMockRuntimeInfo wireMockRuntimeInfo) { final RestTemplate restTemplate = restTemplateProxy(PROXY_SERVER_HOST, wireMockRuntimeInfo.getHttpPort()); final var discoveryFinderClient = new DiscoveryFinderClientImpl(DISCOVERY_FINDER_URL, restTemplate); - final var connectorEndpointsService = new ConnectorEndpointsService(discoveryFinderClient); + final var connectorEndpointsService = new ConnectorEndpointsService(discoveryFinderClient, "bpnl"); final var endpointDataForConnectorsService = new EndpointDataForConnectorsService( edcEndpointReferenceRetrieverMock); final var decentralDigitalTwinRegistryClient = new DecentralDigitalTwinRegistryClient(restTemplate, diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/discovery/ConnectorEndpointsServiceTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/discovery/ConnectorEndpointsServiceTest.java index 5511c078c2..d7b5dc693a 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/discovery/ConnectorEndpointsServiceTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/discovery/ConnectorEndpointsServiceTest.java @@ -36,7 +36,7 @@ class ConnectorEndpointsServiceTest { private final DiscoveryFinderClient essDiscoveryFinderClient = Mockito.mock(DiscoveryFinderClient.class); - private final ConnectorEndpointsService service = new ConnectorEndpointsService(essDiscoveryFinderClient); + private final ConnectorEndpointsService service = new ConnectorEndpointsService(essDiscoveryFinderClient, "bpnl" ); @Test void shouldFindConnectorEndpoints() { diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/discovery/DiscoveryFinderClientImplTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/discovery/DiscoveryFinderClientImplTest.java index 9a14c6df34..0786df7d75 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/discovery/DiscoveryFinderClientImplTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/discovery/DiscoveryFinderClientImplTest.java @@ -61,7 +61,7 @@ void findDiscoveryEndpoints_shouldReturnResponseFromRestRequest() { final DiscoveryResponse mockResponse = new DiscoveryResponse( List.of(new DiscoveryEndpoint("test-endpoint", "desc", "test-endpoint-addr", "docs", "resId"))); - final var request = new DiscoveryFinderRequest(List.of("bpn")); + final var request = new DiscoveryFinderRequest(List.of("bpnl")); when(restTemplate.postForObject(DISCOVERY_FINDER_URL, request, DiscoveryResponse.class)).thenReturn( mockResponse); diff --git a/local/deployment/full-irs/subcharts/discovery/templates/configmap.yaml b/local/deployment/full-irs/subcharts/discovery/templates/configmap.yaml index 18c1492ee9..023dac9bc1 100644 --- a/local/deployment/full-irs/subcharts/discovery/templates/configmap.yaml +++ b/local/deployment/full-irs/subcharts/discovery/templates/configmap.yaml @@ -101,16 +101,16 @@ data: bpn_discovery_service_response.json: |- { "bpns": [ - {"type": "bpn","key": ".*","value": "BPNL00000000BJTL","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003AVTH","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003AXS3","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003AYRE","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003AZQP","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003B0Q0","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003B2OM","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003B3NX","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003B5MJ","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003B5MJ","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, - {"type": "bpn","key": ".*","value": "BPNL00000003CSGV","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"} + {"type": "bpnl","key": ".*","value": "BPNL00000000BJTL","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003AVTH","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003AXS3","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003AYRE","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003AZQP","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003B0Q0","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003B2OM","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003B3NX","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003B5MJ","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003B5MJ","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}, + {"type": "bpnl","key": ".*","value": "BPNL00000003CSGV","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"} ] }