Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(chore):884 - added retry for submodelclient. #1157

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tx-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ SPDX-License-Identifier: Apache-2.0
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${awaitility.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class AssetBase {
private String van;
private SemanticDataModel semanticDataModel;
private String classification;
@Singular
private List<DetailAspectModel> detailAspectModels;
private List<Notification> sentQualityAlerts;
private List<Notification> receivedQualityAlerts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ public static OffsetDateTime getOffsetDateTime(String date) {
}

public static void enrichAssetBase(List<DetailAspectModel> detailAspectModels, AssetBase assetBase) {
List<DetailAspectModel> 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<String, List<Descriptions>> descriptionsMap, AssetBase assetBase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,7 +45,23 @@ 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)
.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;
}
}
);

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down
Loading