diff options
Diffstat (limited to 'prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsPropertySourceLocator.java')
-rw-r--r-- | prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsPropertySourceLocator.java | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsPropertySourceLocator.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsPropertySourceLocator.java index 2b5ac2e5..b4875eed 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsPropertySourceLocator.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsPropertySourceLocator.java @@ -3,6 +3,7 @@ * PNF-REGISTRATION-HANDLER * ================================================================================ * Copyright (C) 2019-2021 NOKIA Intellectual Property. All rights reserved. + * Copyright (C) 2023 Deutsche Telekom Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +29,7 @@ import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnos import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.bootstrap.config.PropertySourceLocator; +import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; @@ -35,6 +37,7 @@ import reactor.util.retry.Retry; import java.util.Map; +@Profile("!autoCommitDisabled") public class CbsPropertySourceLocator implements PropertySourceLocator { private static final Logger LOGGER = LoggerFactory.getLogger(CbsPropertySourceLocator.class); @@ -43,37 +46,40 @@ public class CbsPropertySourceLocator implements PropertySourceLocator { private final CbsClientConfigurationResolver cbsClientConfigurationResolver; private final CbsClientFactoryFacade cbsClientFactoryFacade; private final CbsConfiguration cbsConfiguration; - + public CbsPropertySourceLocator(CbsProperties cbsProperties, - CbsJsonToPropertyMapConverter cbsJsonToPropertyMapConverter, - CbsClientConfigurationResolver cbsClientConfigurationResolver, - CbsClientFactoryFacade cbsClientFactoryFacade, - CbsConfiguration cbsConfiguration) { - this.cbsProperties = cbsProperties; - this.cbsJsonToPropertyMapConverter = cbsJsonToPropertyMapConverter; - this.cbsClientConfigurationResolver = cbsClientConfigurationResolver; - this.cbsClientFactoryFacade = cbsClientFactoryFacade; - this.cbsConfiguration = cbsConfiguration; + CbsJsonToPropertyMapConverter cbsJsonToPropertyMapConverter, + CbsClientConfigurationResolver cbsClientConfigurationResolver, + CbsClientFactoryFacade cbsClientFactoryFacade, CbsConfiguration cbsConfiguration) { + + this.cbsProperties = cbsProperties; + this.cbsJsonToPropertyMapConverter = cbsJsonToPropertyMapConverter; + this.cbsClientConfigurationResolver = cbsClientConfigurationResolver; + this.cbsClientFactoryFacade = cbsClientFactoryFacade; + this.cbsConfiguration = cbsConfiguration; } @Override public PropertySource<?> locate(Environment environment) { + CbsClientConfiguration cbsClientConfiguration = cbsClientConfigurationResolver.resolveCbsClientConfiguration(); Map<String, Object> properties = cbsClientFactoryFacade.createCbsClient(cbsClientConfiguration) .flatMap(cbsClient -> cbsClient.get(CbsRequests.getAll(RequestDiagnosticContext.create()))) .doOnError(e -> LOGGER.warn("Failed loading configuration - retrying...", e)) - .retryWhen(Retry. - backoff(cbsProperties.getFetchRetries().getMaxAttempts(), cbsProperties.getFetchRetries().getFirstBackoff()). - maxBackoff(cbsProperties.getFetchRetries().getMaxBackoff())) - .doOnNext(this::updateCbsConfig) - .map(cbsJsonToPropertyMapConverter::convertToMap) - .block(); + .retryWhen(Retry + .backoff(cbsProperties.getFetchRetries().getMaxAttempts(), + cbsProperties.getFetchRetries().getFirstBackoff()) + .maxBackoff(cbsProperties.getFetchRetries().getMaxBackoff())) + .doOnNext(this::updateCbsConfig).map(cbsJsonToPropertyMapConverter::convertToMap).block(); + return new MapPropertySource("cbs", properties); } private void updateCbsConfig(JsonObject jsonObject) { try { + LOGGER.info("Updating CBS configuration"); cbsConfiguration.parseCBSConfig(jsonObject); + } catch (Exception e) { LOGGER.error("Failed parsing configuration", e); throw e; |