From ae956fcb64d6d36ccc2e892984fd7d2c194e3b87 Mon Sep 17 00:00:00 2001 From: kurczews Date: Mon, 3 Jun 2019 11:31:43 +0200 Subject: Adjust PRH with SDK Change-Id: If1f230047bf635d5288482b275d05c484a4ecaec Issue-ID: DCAEGEN2-1521 Signed-off-by: kurczews --- .../prh/configuration/CbsConfiguration.java | 12 +++++------ .../prh/configuration/ConsulConfigFileReader.java | 25 +++++++++++----------- 2 files changed, 19 insertions(+), 18 deletions(-) (limited to 'prh-app-server') diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsConfiguration.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsConfiguration.java index 3f018b53..e262da55 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsConfiguration.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsConfiguration.java @@ -24,7 +24,7 @@ import com.google.gson.JsonObject; import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClientFactory; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.DmaapClientFactory; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber; @@ -58,23 +58,23 @@ public class CbsConfiguration implements Config { } public void runTask() { - Flux.defer(this::resolveEnvProperties) + Flux.defer(this::resolveCbsClientConfiguration) .subscribeOn(Schedulers.parallel()) .subscribe(this::parsingConfigSuccess, this::parsingConfigError); } - private Mono resolveEnvProperties() { + private Mono resolveCbsClientConfiguration() { try { - return Mono.just(EnvProperties.fromEnvironment()); + return Mono.just(CbsClientConfiguration.fromEnvironment()); } catch(Exception e){ parsingConfigError(e); return consulConfigFileReader.evaluate(); } } - private void parsingConfigSuccess(EnvProperties envProperties) { + private void parsingConfigSuccess(CbsClientConfiguration cbsClientConfiguration) { LOGGER.debug("Fetching PRH configuration from Consul"); - CbsClientFactory.createCbsClient(envProperties) + CbsClientFactory.createCbsClient(cbsClientConfiguration) .flatMap(cbsClient -> cbsClient.get(CbsRequests.getAll(RequestDiagnosticContext.create()))) .subscribe(this::parseCBSConfig, this::cbsConfigError); } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigFileReader.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigFileReader.java index f11d9ff6..401db881 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigFileReader.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigFileReader.java @@ -28,8 +28,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.Optional; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableCbsClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableCbsClientConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -42,21 +43,21 @@ public class ConsulConfigFileReader { private static final Logger LOGGER = LoggerFactory.getLogger(ConsulConfigFileReader.class); private static final int DEFAULT_CONSUL_PORT = 8500; - private ImmutableEnvProperties jsonEnvProperties; + private ImmutableCbsClientConfiguration jsonCbsClientConfiguration; @Value("classpath:consul_config.json") private Resource consulConfig; - public Mono evaluate() { + public Mono evaluate() { initFileStreamReader(); - EnvProperties envProperties = ImmutableEnvProperties.builder() - .consulHost(jsonEnvProperties.consulHost()) - .consulPort(Optional.ofNullable(jsonEnvProperties.consulPort()).orElse(DEFAULT_CONSUL_PORT)) - .cbsName(jsonEnvProperties.cbsName()) - .appName(jsonEnvProperties.appName()) + CbsClientConfiguration cbsClientConfiguration = ImmutableCbsClientConfiguration.builder() + .consulHost(jsonCbsClientConfiguration.consulHost()) + .consulPort(Optional.ofNullable(jsonCbsClientConfiguration.consulPort()).orElse(DEFAULT_CONSUL_PORT)) + .cbsName(jsonCbsClientConfiguration.cbsName()) + .appName(jsonCbsClientConfiguration.appName()) .build(); - LOGGER.info("Evaluated variables: {}", envProperties); - return Mono.just(envProperties); + LOGGER.info("Evaluated variables: {}", cbsClientConfiguration); + return Mono.just(cbsClientConfiguration); } private void initFileStreamReader() { @@ -65,7 +66,7 @@ public class ConsulConfigFileReader { try (InputStream inputStream = consulConfig.getInputStream()) { JsonElement rootElement = getJsonElement(inputStream); if (rootElement.isJsonObject()) { - jsonEnvProperties = gson.fromJson(rootElement, ImmutableEnvProperties.class); + jsonCbsClientConfiguration = gson.fromJson(rootElement, ImmutableCbsClientConfiguration.class); } } catch (IOException e) { LOGGER.warn("Failed to load/parse file", e); -- cgit 1.2.3-korg