From 81b3ea340a67442b39840a9382c19068a9d2e8e1 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 3 Jul 2024 16:58:46 +0200 Subject: [PATCH 1/3] feature(chore):884 - added retry for submodelclient. --- tx-backend/pom.xml | 1 - .../repository/SubmodelClient.java | 25 ++++++++++++++++++- .../repository/SubmodelServerClientImpl.java | 1 - 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tx-backend/pom.xml b/tx-backend/pom.xml index 691f04af34..3486860960 100644 --- a/tx-backend/pom.xml +++ b/tx-backend/pom.xml @@ -255,7 +255,6 @@ SPDX-License-Identifier: Apache-2.0 org.awaitility awaitility ${awaitility.version} - test com.tngtech.archunit diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelClient.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelClient.java index 42b2a771e3..68ad179d70 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelClient.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelClient.java @@ -19,11 +19,17 @@ package org.eclipse.tractusx.traceability.submodel.infrastructure.repository; import lombok.extern.slf4j.Slf4j; +import notification.response.NotificationResponse; +import org.awaitility.Durations; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; +import static org.awaitility.Awaitility.await; + +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import static org.eclipse.tractusx.traceability.common.config.RestTemplateConfiguration.SUBMODEL_REST_TEMPLATE; @@ -39,7 +45,24 @@ public SubmodelClient(@Qualifier(SUBMODEL_REST_TEMPLATE) RestTemplate submodelRe } public void createSubmodel(String submodelId, String payload) { - submodelRestTemplate.exchange("/" + submodelId, HttpMethod.POST, new HttpEntity<>(payload), Void.class); + + await() + .atMost(Durations.FIVE_MINUTES) + .pollInterval(1, TimeUnit.SECONDS) + .ignoreExceptions() + .until(() -> { + try { + submodelRestTemplate.exchange("/" + submodelId, HttpMethod.POST, new HttpEntity<>(payload), Void.class); + log.info("Submodel created successfully with id: {}", submodelId); + return true; + } catch (Exception e) { + log.warn("Retrying to create submodel with id: {}. Exception: {}", submodelId, e.getMessage()); + log.debug("Exception details:", e); + return false; + } + } + ); + } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelServerClientImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelServerClientImpl.java index ffe4a60981..371f686395 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelServerClientImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelServerClientImpl.java @@ -33,7 +33,6 @@ public class SubmodelServerClientImpl implements SubmodelServerRepository { @Override public void saveSubmodel(String submodelId, String submodel) { - log.info(submodelId, "submodelId"); submodelClient.createSubmodel(submodelId, submodel); } From c9c672f5389d82560099ea71b310d3084b5fcbaa Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 3 Jul 2024 20:40:51 +0200 Subject: [PATCH 2/3] feature(chore):884 - added retry for submodelclient. --- .../traceability/assets/domain/base/model/AssetBase.java | 1 - .../irs/model/response/mapping/submodel/MapperHelper.java | 6 +++++- .../submodel/infrastructure/repository/SubmodelClient.java | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/base/model/AssetBase.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/base/model/AssetBase.java index a82e6a9dec..db908070f6 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/base/model/AssetBase.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/base/model/AssetBase.java @@ -53,7 +53,6 @@ public class AssetBase { private String van; private SemanticDataModel semanticDataModel; private String classification; - @Singular private List detailAspectModels; private List sentQualityAlerts; private List receivedQualityAlerts; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/MapperHelper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/MapperHelper.java index 5f0af079a3..65e1e8046a 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/MapperHelper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/MapperHelper.java @@ -77,10 +77,14 @@ public static OffsetDateTime getOffsetDateTime(String date) { } public static void enrichAssetBase(List detailAspectModels, AssetBase assetBase) { + List detailAspectModelsToAdd = new ArrayList<>(); detailAspectModels.stream() .filter(detailAspectModel -> detailAspectModel.getGlobalAssetId().equals(assetBase.getId())) .findFirst() - .ifPresent(detailAspectModel -> emptyIfNull(new ArrayList<>(assetBase.getDetailAspectModels())).add(detailAspectModel)); + .ifPresent(detailAspectModelsToAdd::add); + + detailAspectModelsToAdd.addAll(emptyIfNull(assetBase.getDetailAspectModels())); + assetBase.setDetailAspectModels(detailAspectModelsToAdd); } public static void enrichUpwardAndDownwardDescriptions(Map> descriptionsMap, AssetBase assetBase) { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelClient.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelClient.java index 68ad179d70..23c618a03b 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelClient.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/submodel/infrastructure/repository/SubmodelClient.java @@ -49,7 +49,6 @@ public void createSubmodel(String submodelId, String payload) { await() .atMost(Durations.FIVE_MINUTES) .pollInterval(1, TimeUnit.SECONDS) - .ignoreExceptions() .until(() -> { try { submodelRestTemplate.exchange("/" + submodelId, HttpMethod.POST, new HttpEntity<>(payload), Void.class); From 703a8be7a6bc184fe700359323ca6c98c90a4d18 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 3 Jul 2024 20:47:13 +0200 Subject: [PATCH 3/3] feature(chore):884 - added retry for submodelclient. --- .../integration/importdata/ImportControllerIT.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/importdata/ImportControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/importdata/ImportControllerIT.java index c5e207a48a..9df0dacc36 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/importdata/ImportControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/importdata/ImportControllerIT.java @@ -417,10 +417,14 @@ void givenValidFile_whenPublishData_thenStatusShouldChangeToInPublishedToCX() th // then eventually(() -> { - AssetBase asset = assetAsBuiltRepository.getAssetById("urn:uuid:254604ab-2153-45fb-8cad-54ef09f4080f"); - assertThat(asset.getPolicyId()).isEqualTo("default-policy"); - assertThat(asset.getImportState()).isEqualTo(ImportState.PUBLISHED_TO_CORE_SERVICES); - dtrApiSupport.verifyDtrCreateShellCalledTimes(1); + try { + AssetBase asset = assetAsBuiltRepository.getAssetById("urn:uuid:254604ab-2153-45fb-8cad-54ef09f4080f"); + assertThat(asset.getPolicyId()).isEqualTo("default-policy"); + assertThat(asset.getImportState()).isEqualTo(ImportState.PUBLISHED_TO_CORE_SERVICES); + dtrApiSupport.verifyDtrCreateShellCalledTimes(1); + } catch (AssertionFailedError exception) { + return false; + } return true; });