From 624618c0d343c707d1a40588c3e226f8db2a2203 Mon Sep 17 00:00:00 2001 From: micdzied Date: Fri, 22 Mar 2019 12:32:53 +0100 Subject: use CBS SDK in PRH -remove unused classes -fix junit tests -use cbs Change-Id: Ibc5841b713ad00522dd78a52b7cb7efa871cb8b4 Issue-ID: DCAEGEN2-1360 Signed-off-by: micdzied --- .../org/onap/dcaegen2/services/prh/MainApp.java | 6 + .../prh/configuration/AaiHttpClientConfig.java | 6 +- .../services/prh/configuration/AppConfig.java | 1 - .../prh/configuration/CloudConfigParser.java | 123 --------------------- .../prh/configuration/CloudConfiguration.java | 119 -------------------- .../prh/configuration/ConsulConfigFileReader.java | 78 +++++++++++++ .../prh/configuration/ConsulConfiguration.java | 121 ++++++++++++++++++++ .../configuration/ConsulConfigurationParser.java | 123 +++++++++++++++++++++ .../prh/configuration/EnvironmentProcessor.java | 85 -------------- .../services/prh/tasks/ScheduledTasksRunner.java | 10 +- .../src/main/resources/consul_config.json | 5 + .../src/main/resources/prh_endpoints.json | 65 ----------- .../prh/configuration/CloudConfigParserTest.java | 87 --------------- .../ConsulConfigurationParserTest.java | 87 +++++++++++++++ .../test/resources/flattened_configuration.json | 78 ++++++------- 15 files changed, 468 insertions(+), 526 deletions(-) delete mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParser.java delete mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigFileReader.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfiguration.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParser.java delete mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/EnvironmentProcessor.java create mode 100644 prh-app-server/src/main/resources/consul_config.json delete mode 100644 prh-app-server/src/main/resources/prh_endpoints.json delete mode 100644 prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParserTest.java create mode 100644 prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParserTest.java diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java index 5ea07e0a..6ce5d64a 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java @@ -25,6 +25,7 @@ import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.REQUEST_ import java.util.Map; import java.util.UUID; +import org.onap.dcaegen2.services.prh.configuration.ConsulConfigFileReader; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationClient; import org.slf4j.MDC; import org.springframework.boot.SpringApplication; @@ -65,4 +66,9 @@ public class MainApp { CloudConfigurationClient getCloudConfigurationClient(){ return new CloudConfigurationClient(); } + + @Bean + ConsulConfigFileReader getConfigFileLoader(){ + return new ConsulConfigFileReader(); + } } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java index c90fd9e3..6df9c4ac 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java @@ -42,7 +42,7 @@ import java.util.function.BiFunction; @Configuration public class AaiHttpClientConfig { @Autowired - private CloudConfiguration cloudConfig; + private ConsulConfiguration consulConfiguration; @Bean public AaiHttpClient getPatchClientFactory() { @@ -68,8 +68,8 @@ public class AaiHttpClientConfig { final BiFunction> factoryMethod) { return x -> factoryMethod.apply( - cloudConfig.getAaiClientConfiguration(), - new AaiHttpClientFactory(cloudConfig.getAaiClientConfiguration()).build() + consulConfiguration.getAaiClientConfiguration(), + new AaiHttpClientFactory(consulConfiguration.getAaiClientConfiguration()).build() ).getAaiResponse(x); } } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java index 21495740..8ac1d9c0 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java @@ -36,7 +36,6 @@ import org.springframework.context.annotation.Configuration; /** * @author Przemysław Wąsala on 4/9/18 */ - @Configuration @EnableConfigurationProperties public class AppConfig extends PrhAppConfig { diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParser.java deleted file mode 100644 index ec01ff50..00000000 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParser.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.prh.configuration; - -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.aai.client.config.ImmutableAaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration; - -/** - * @author Przemysław Wąsala on 8/21/18 - */ -class CloudConfigParser { - - private static final String SECURITY_TRUST_STORE_PATH = "security.trustStorePath"; - private static final String SECURITY_TRUST_STORE_PASS_PATH = "security.trustStorePasswordPath"; - private static final String SECURITY_KEY_STORE_PATH = "security.keyStorePath"; - private static final String SECURITY_KEY_STORE_PASS_PATH = "security.keyStorePasswordPath"; - private final JsonObject jsonObject; - - CloudConfigParser(JsonObject jsonObject) { - this.jsonObject = jsonObject; - } - - DmaapPublisherConfiguration getDmaapPublisherConfig() { - return new ImmutableDmaapPublisherConfiguration.Builder() - .dmaapTopicName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapTopicName").getAsString()) - .dmaapUserPassword(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserPassword").getAsString()) - .dmaapPortNumber(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapPortNumber").getAsInt()) - .dmaapProtocol(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapProtocol").getAsString()) - .dmaapContentType(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapContentType").getAsString()) - .dmaapHostName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapHostName").getAsString()) - .dmaapUserName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserName").getAsString()) - .dmaapUserPassword(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserPassword").getAsString()) - .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString()) - .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString()) - .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString()) - .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString()) - .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean()) - .build(); - } - - DmaapPublisherConfiguration getDmaapUpdatePublisherConfig() { - return new ImmutableDmaapPublisherConfiguration.Builder() - .dmaapTopicName(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapTopicName").getAsString()) - .dmaapUserPassword(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapUserPassword").getAsString()) - .dmaapPortNumber(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapPortNumber").getAsInt()) - .dmaapProtocol(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapProtocol").getAsString()) - .dmaapContentType(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapContentType").getAsString()) - .dmaapHostName(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapHostName").getAsString()) - .dmaapUserName(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapUserName").getAsString()) - .dmaapUserPassword(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapUserPassword").getAsString()) - .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString()) - .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString()) - .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString()) - .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString()) - .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean()) - .build(); - } - - AaiClientConfiguration getAaiClientConfig() { - return new ImmutableAaiClientConfiguration.Builder() - .pnfUrl(jsonObject.get("aai.aaiClientConfiguration.pnfUrl").getAsString()) - .aaiHost(jsonObject.get("aai.aaiClientConfiguration.aaiHost").getAsString()) - .aaiPort(jsonObject.get("aai.aaiClientConfiguration.aaiHostPortNumber").getAsInt()) - .aaiUserName(jsonObject.get("aai.aaiClientConfiguration.aaiUserName").getAsString()) - .aaiPnfPath(jsonObject.get("aai.aaiClientConfiguration.aaiPnfPath").getAsString()) - .aaiServiceInstancePath(jsonObject.get("aai.aaiClientConfiguration.aaiServiceInstancePath").getAsString()) - .aaiIgnoreSslCertificateErrors( - jsonObject.get("aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors").getAsBoolean()) - .aaiUserPassword(jsonObject.get("aai.aaiClientConfiguration.aaiUserPassword").getAsString()) - .aaiProtocol(jsonObject.get("aai.aaiClientConfiguration.aaiProtocol").getAsString()) - .aaiBasePath(jsonObject.get("aai.aaiClientConfiguration.aaiBasePath").getAsString()) - .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString()) - .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString()) - .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString()) - .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString()) - .enableAaiCertAuth(jsonObject.get("security.enableAaiCertAuth").getAsBoolean()) - .build(); - } - - DmaapConsumerConfiguration getDmaapConsumerConfig() { - return new ImmutableDmaapConsumerConfiguration.Builder() - .timeoutMs(jsonObject.get("dmaap.dmaapConsumerConfiguration.timeoutMs").getAsInt()) - .dmaapHostName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapHostName").getAsString()) - .dmaapUserName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapUserName").getAsString()) - .dmaapUserPassword(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapUserPassword").getAsString()) - .dmaapTopicName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapTopicName").getAsString()) - .dmaapPortNumber(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapPortNumber").getAsInt()) - .dmaapContentType(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapContentType").getAsString()) - .messageLimit(jsonObject.get("dmaap.dmaapConsumerConfiguration.messageLimit").getAsInt()) - .dmaapProtocol(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapProtocol").getAsString()) - .consumerId(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerId").getAsString()) - .consumerGroup(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerGroup").getAsString()) - .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString()) - .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString()) - .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString()) - .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString()) - .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean()) - .build(); - } -} \ No newline at end of file diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java deleted file mode 100644 index 10ece50b..00000000 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.prh.configuration; - -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.aai.client.config.ImmutableAaiClientConfiguration; - -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationClient; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.*; -import org.springframework.scheduling.annotation.EnableScheduling; -import reactor.core.publisher.Flux; -import reactor.core.scheduler.Schedulers; - -import java.util.Optional; -import java.util.Properties; - -/** - * @author Przemysław Wąsala on 8/9/18 - */ -@Configuration -@ComponentScan("org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers") -@EnableConfigurationProperties -@EnableScheduling -@Primary -public class CloudConfiguration extends AppConfig { - - private static final Logger LOGGER = LoggerFactory.getLogger(CloudConfiguration.class); - private CloudConfigurationClient prhConfigurationProvider; - - private AaiClientConfiguration aaiClientCloudConfiguration; - private DmaapPublisherConfiguration dmaapPublisherCloudConfiguration; - private DmaapPublisherConfiguration dmaapUpdatePublisherCloudConfiguration; - private DmaapConsumerConfiguration dmaapConsumerCloudConfiguration; - - @Value("#{systemEnvironment}") - private Properties systemEnvironment; - - @Autowired - public void setThreadPoolTaskScheduler(CloudConfigurationClient prhConfigurationProvider) { - this.prhConfigurationProvider = prhConfigurationProvider; - } - - public void runTask() { - Flux.defer(() -> EnvironmentProcessor.evaluate(systemEnvironment)) - .subscribeOn(Schedulers.parallel()) - .subscribe(this::parsingConfigSuccess, this::parsingConfigError); - } - - private void parsingConfigError(Throwable throwable) { - LOGGER.warn("Failed to process system environments", throwable); - } - - private void cloudConfigError(Throwable throwable) { - LOGGER.warn("Failed to gather configuration from ConfigBindingService/Consul", throwable); - } - - private void parsingConfigSuccess(EnvProperties envProperties) { - LOGGER.debug("Fetching PRH configuration from ConfigBindingService/Consul"); - prhConfigurationProvider.callForServiceConfigurationReactive(envProperties) - .subscribe(this::parseCloudConfig, this::cloudConfigError); - } - - private void parseCloudConfig(JsonObject jsonObject) { - LOGGER.info("Received application configuration: {}", jsonObject); - CloudConfigParser cloudConfigParser = new CloudConfigParser(jsonObject); - dmaapPublisherCloudConfiguration = cloudConfigParser.getDmaapPublisherConfig(); - dmaapUpdatePublisherCloudConfiguration = cloudConfigParser.getDmaapUpdatePublisherConfig(); - aaiClientCloudConfiguration = ImmutableAaiClientConfiguration.copyOf(cloudConfigParser.getAaiClientConfig()) - .withAaiHeaders(aaiClientConfiguration.aaiHeaders()); - dmaapConsumerCloudConfiguration = cloudConfigParser.getDmaapConsumerConfig(); - } - - @Override - public DmaapPublisherConfiguration getDmaapPublisherConfiguration() { - return Optional.ofNullable(dmaapPublisherCloudConfiguration).orElse(super.getDmaapPublisherConfiguration()); - } - - @Override - public DmaapPublisherConfiguration getDmaapUpdatePublisherConfiguration() { - return Optional.ofNullable(dmaapUpdatePublisherCloudConfiguration).orElse(super.getDmaapPublisherConfiguration()); - } - - @Override - public AaiClientConfiguration getAaiClientConfiguration() { - return Optional.ofNullable(aaiClientCloudConfiguration).orElse(super.getAaiClientConfiguration()); - } - - @Override - public DmaapConsumerConfiguration getDmaapConsumerConfiguration() { - return Optional.ofNullable(dmaapConsumerCloudConfiguration).orElse(super.getDmaapConsumerConfiguration()); - } -} 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 new file mode 100644 index 00000000..f11d9ff6 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigFileReader.java @@ -0,0 +1,78 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.configuration; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import java.io.IOException; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import reactor.core.publisher.Mono; + +@Configuration +public class ConsulConfigFileReader { + + private static final Logger LOGGER = LoggerFactory.getLogger(ConsulConfigFileReader.class); + private static final int DEFAULT_CONSUL_PORT = 8500; + private ImmutableEnvProperties jsonEnvProperties; + + @Value("classpath:consul_config.json") + private Resource consulConfig; + + 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()) + .build(); + LOGGER.info("Evaluated variables: {}", envProperties); + return Mono.just(envProperties); + } + + private void initFileStreamReader() { + LOGGER.debug("Loading configuration from configuration file"); + Gson gson = new Gson(); + try (InputStream inputStream = consulConfig.getInputStream()) { + JsonElement rootElement = getJsonElement(inputStream); + if (rootElement.isJsonObject()) { + jsonEnvProperties = gson.fromJson(rootElement, ImmutableEnvProperties.class); + } + } catch (IOException e) { + LOGGER.warn("Failed to load/parse file", e); + } + } + + private JsonElement getJsonElement(InputStream inputStream) { + return new JsonParser().parse(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + } +} diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfiguration.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfiguration.java new file mode 100644 index 00000000..3d58f01e --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfiguration.java @@ -0,0 +1,121 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.configuration; + +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.aai.client.config.ImmutableAaiClientConfiguration; +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.providers.CloudConfigurationClient; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.scheduling.annotation.EnableScheduling; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; + +import java.util.Optional; + +@Configuration +@ComponentScan("org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers") +@EnableConfigurationProperties +@EnableScheduling +@Primary +public class ConsulConfiguration extends PrhAppConfig { + private static final Logger LOGGER = LoggerFactory.getLogger(ConsulConfiguration.class); + private AaiClientConfiguration aaiClientCBSConfiguration; + private DmaapPublisherConfiguration dmaapPublisherCBSConfiguration; + private DmaapConsumerConfiguration dmaapConsumerCBSConfiguration; + private DmaapPublisherConfiguration dmaapUpdatePublisherCBSConfiguration; + + @Autowired + private ConsulConfigFileReader consulConfigFileReader; + + public void runTask() { + Flux.defer(this::resolveEnvProperties) + .subscribeOn(Schedulers.parallel()) + .subscribe(this::parsingConfigSuccess, this::parsingConfigError); + } + + private Mono resolveEnvProperties() { + try { + return Mono.just(EnvProperties.fromEnvironment()); + } catch(Exception e){ + parsingConfigError(e); + return consulConfigFileReader.evaluate(); + } + } + + private void parsingConfigSuccess(EnvProperties envProperties) { + LOGGER.debug("Fetching PRH configuration from Consul"); + CbsClientFactory.createCbsClient(envProperties) + .flatMap(cbsClient -> cbsClient.get(CbsRequests.getAll(RequestDiagnosticContext.create()))) + .subscribe(this::parseCBSConfig, this::cbsConfigError); + } + + private void parseCBSConfig(JsonObject jsonObject) { + LOGGER.info("Received application configuration: {}", jsonObject); + ConsulConfigurationParser consulConfigurationParser = new ConsulConfigurationParser(jsonObject); + dmaapPublisherCBSConfiguration = consulConfigurationParser.getDmaapPublisherConfig(); + dmaapUpdatePublisherCBSConfiguration = consulConfigurationParser.getDmaapUpdatePublisherConfig(); + aaiClientCBSConfiguration = ImmutableAaiClientConfiguration.copyOf(consulConfigurationParser.getAaiClientConfig()) + .withAaiHeaders(aaiClientConfiguration.aaiHeaders()); + dmaapConsumerCBSConfiguration = consulConfigurationParser.getDmaapConsumerConfig(); + } + + private void parsingConfigError(Throwable throwable) { + LOGGER.warn("Failed to process system environments", throwable); + } + + private void cbsConfigError(Throwable throwable) { + LOGGER.warn("Failed to gather configuration from ConfigBindingService/Consul", throwable); + } + + @Override + public DmaapPublisherConfiguration getDmaapPublisherConfiguration() { + return Optional.ofNullable(dmaapPublisherCBSConfiguration).orElse(super.getDmaapPublisherConfiguration()); + } + + @Override + public DmaapPublisherConfiguration getDmaapUpdatePublisherConfiguration() { + return Optional.ofNullable(dmaapUpdatePublisherCBSConfiguration).orElse(super.getDmaapPublisherConfiguration()); + } + + @Override + public AaiClientConfiguration getAaiClientConfiguration() { + return Optional.ofNullable(aaiClientCBSConfiguration).orElse(super.getAaiClientConfiguration()); + } + + @Override + public DmaapConsumerConfiguration getDmaapConsumerConfiguration() { + return Optional.ofNullable(dmaapConsumerCBSConfiguration).orElse(super.getDmaapConsumerConfiguration()); + } +} diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParser.java new file mode 100644 index 00000000..b05c0324 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParser.java @@ -0,0 +1,123 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.configuration; + +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.aai.client.config.ImmutableAaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration; + +/** + * @author Przemysław Wąsala on 8/21/18 + */ +class ConsulConfigurationParser { + private static final String SECURITY_TRUST_STORE_PATH = "security.trustStorePath"; + private static final String SECURITY_TRUST_STORE_PASS_PATH = "security.trustStorePasswordPath"; + private static final String SECURITY_KEY_STORE_PATH = "security.keyStorePath"; + private static final String SECURITY_KEY_STORE_PASS_PATH = "security.keyStorePasswordPath"; + private static final String CONFIG = "config"; + private final JsonObject jsonObject; + + ConsulConfigurationParser(JsonObject jsonObject) { + this.jsonObject = jsonObject.getAsJsonObject(CONFIG); + } + + DmaapPublisherConfiguration getDmaapPublisherConfig() { + return new ImmutableDmaapPublisherConfiguration.Builder() + .dmaapTopicName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapTopicName").getAsString()) + .dmaapUserPassword(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserPassword").getAsString()) + .dmaapPortNumber(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapPortNumber").getAsInt()) + .dmaapProtocol(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapProtocol").getAsString()) + .dmaapContentType(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapContentType").getAsString()) + .dmaapHostName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapHostName").getAsString()) + .dmaapUserName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserName").getAsString()) + .dmaapUserPassword(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserPassword").getAsString()) + .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString()) + .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString()) + .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString()) + .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString()) + .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean()) + .build(); + } + + DmaapPublisherConfiguration getDmaapUpdatePublisherConfig() { + return new ImmutableDmaapPublisherConfiguration.Builder() + .dmaapTopicName(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapTopicName").getAsString()) + .dmaapUserPassword(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapUserPassword").getAsString()) + .dmaapPortNumber(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapPortNumber").getAsInt()) + .dmaapProtocol(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapProtocol").getAsString()) + .dmaapContentType(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapContentType").getAsString()) + .dmaapHostName(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapHostName").getAsString()) + .dmaapUserName(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapUserName").getAsString()) + .dmaapUserPassword(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapUserPassword").getAsString()) + .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString()) + .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString()) + .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString()) + .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString()) + .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean()) + .build(); + } + + AaiClientConfiguration getAaiClientConfig() { + return new ImmutableAaiClientConfiguration.Builder() + .pnfUrl(jsonObject.get("aai.aaiClientConfiguration.pnfUrl").getAsString()) + .aaiHost(jsonObject.get("aai.aaiClientConfiguration.aaiHost").getAsString()) + .aaiPort(jsonObject.get("aai.aaiClientConfiguration.aaiHostPortNumber").getAsInt()) + .aaiUserName(jsonObject.get("aai.aaiClientConfiguration.aaiUserName").getAsString()) + .aaiPnfPath(jsonObject.get("aai.aaiClientConfiguration.aaiPnfPath").getAsString()) + .aaiServiceInstancePath(jsonObject.get("aai.aaiClientConfiguration.aaiServiceInstancePath").getAsString()) + .aaiIgnoreSslCertificateErrors( + jsonObject.get("aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors").getAsBoolean()) + .aaiUserPassword(jsonObject.get("aai.aaiClientConfiguration.aaiUserPassword").getAsString()) + .aaiProtocol(jsonObject.get("aai.aaiClientConfiguration.aaiProtocol").getAsString()) + .aaiBasePath(jsonObject.get("aai.aaiClientConfiguration.aaiBasePath").getAsString()) + .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString()) + .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString()) + .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString()) + .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString()) + .enableAaiCertAuth(jsonObject.get("security.enableAaiCertAuth").getAsBoolean()) + .build(); + } + + DmaapConsumerConfiguration getDmaapConsumerConfig() { + return new ImmutableDmaapConsumerConfiguration.Builder() + .timeoutMs(jsonObject.get("dmaap.dmaapConsumerConfiguration.timeoutMs").getAsInt()) + .dmaapHostName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapHostName").getAsString()) + .dmaapUserName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapUserName").getAsString()) + .dmaapUserPassword(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapUserPassword").getAsString()) + .dmaapTopicName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapTopicName").getAsString()) + .dmaapPortNumber(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapPortNumber").getAsInt()) + .dmaapContentType(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapContentType").getAsString()) + .messageLimit(jsonObject.get("dmaap.dmaapConsumerConfiguration.messageLimit").getAsInt()) + .dmaapProtocol(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapProtocol").getAsString()) + .consumerId(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerId").getAsString()) + .consumerGroup(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerGroup").getAsString()) + .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString()) + .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString()) + .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString()) + .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString()) + .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean()) + .build(); + } +} \ No newline at end of file diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/EnvironmentProcessor.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/EnvironmentProcessor.java deleted file mode 100644 index 3d765bde..00000000 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/EnvironmentProcessor.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.prh.configuration; - -import org.onap.dcaegen2.services.prh.exceptions.EnvironmentLoaderException; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; -import reactor.core.publisher.Mono; - -import java.util.Optional; -import java.util.Properties; - -/** - * @author Przemysław Wąsala on 8/10/18 - */ -final class EnvironmentProcessor { - - private static final Logger LOGGER = LoggerFactory.getLogger(EnvironmentProcessor.class); - private static final int DEFAULT_CONSUL_PORT = 8500; - - private EnvironmentProcessor() { - } - - static Mono evaluate(Properties systemEnvironment) { - LOGGER.debug("Loading configuration from system environment variables"); - EnvProperties envProperties; - try { - envProperties = ImmutableEnvProperties.builder().consulHost(getConsulHost(systemEnvironment)) - .consulPort(getConsultPort(systemEnvironment)).cbsName(getConfigBindingService(systemEnvironment)) - .appName(getService(systemEnvironment)).build(); - } catch (EnvironmentLoaderException e) { - return Mono.error(e); - } - LOGGER.info("Evaluated system environment variables: {}", envProperties); - return Mono.just(envProperties); - } - - private static String getConsulHost(Properties systemEnvironments) throws EnvironmentLoaderException { - return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_HOST")) - .orElseThrow(() -> new EnvironmentLoaderException("$CONSUL_HOST environment has not been defined")); - } - - private static Integer getConsultPort(Properties systemEnvironments) { - return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_PORT")).map(Integer::valueOf) - .orElseGet(EnvironmentProcessor::getDefaultPortOfConsul); - } - - private static String getConfigBindingService(Properties systemEnvironments) throws EnvironmentLoaderException { - return Optional.ofNullable(systemEnvironments.getProperty("CONFIG_BINDING_SERVICE")) - .orElseThrow( - () -> new EnvironmentLoaderException("$CONFIG_BINDING_SERVICE environment has not been defined")); - } - - private static String getService(Properties systemEnvironments) throws EnvironmentLoaderException { - return Optional.ofNullable(Optional.ofNullable(systemEnvironments.getProperty("HOSTNAME")) - .orElse(systemEnvironments.getProperty("SERVICE_NAME"))) - .orElseThrow(() -> new EnvironmentLoaderException( - "Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment")); - } - - private static Integer getDefaultPortOfConsul() { - LOGGER.warn("$CONSUL_PORT environment has not been defined, using default port: {}", DEFAULT_CONSUL_PORT); - return DEFAULT_CONSUL_PORT; - } -} diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksRunner.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksRunner.java index 956ffead..e20e25d8 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksRunner.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksRunner.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.concurrent.ScheduledFuture; import javax.annotation.PostConstruct; -import org.onap.dcaegen2.services.prh.configuration.CloudConfiguration; +import org.onap.dcaegen2.services.prh.configuration.ConsulConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.Marker; @@ -57,15 +57,15 @@ public class ScheduledTasksRunner { private final TaskScheduler taskScheduler; private final ScheduledTasks scheduledTask; - private final CloudConfiguration cloudConfiguration; + private final ConsulConfiguration consulConfiguration; @Autowired public ScheduledTasksRunner(TaskScheduler taskScheduler, ScheduledTasks scheduledTask, - CloudConfiguration cloudConfiguration) { + ConsulConfiguration consulConfiguration) { this.taskScheduler = taskScheduler; this.scheduledTask = scheduledTask; - this.cloudConfiguration = cloudConfiguration; + this.consulConfiguration = consulConfiguration; } /** @@ -94,7 +94,7 @@ public class ScheduledTasksRunner { LOGGER.info(ENTRY, "Start scheduling PRH workflow"); if (scheduledPrhTaskFutureList.isEmpty()) { scheduledPrhTaskFutureList.add(taskScheduler - .scheduleAtFixedRate(cloudConfiguration::runTask, Instant.now(), + .scheduleAtFixedRate(consulConfiguration::runTask, Instant.now(), Duration.ofMinutes(SCHEDULING_REQUEST_FOR_CONFIGURATION_DELAY))); scheduledPrhTaskFutureList.add(taskScheduler .scheduleWithFixedDelay(scheduledTask::scheduleMainPrhEventTask, diff --git a/prh-app-server/src/main/resources/consul_config.json b/prh-app-server/src/main/resources/consul_config.json new file mode 100644 index 00000000..7cefd641 --- /dev/null +++ b/prh-app-server/src/main/resources/consul_config.json @@ -0,0 +1,5 @@ +{ + "consulHost": "10.42.111.9", + "cbsName": "cbs", + "appName": "dcae-prh" +} \ No newline at end of file diff --git a/prh-app-server/src/main/resources/prh_endpoints.json b/prh-app-server/src/main/resources/prh_endpoints.json deleted file mode 100644 index a24dfd92..00000000 --- a/prh-app-server/src/main/resources/prh_endpoints.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "configs": { - "dmaap": { - "dmaapConsumerConfiguration": { - "dmaapHostName": "localhost", - "dmaapPortNumber": 8904, - "dmaapTopicName": "events/unauthenticated.VES_PNFREG_OUTPUT", - "dmaapProtocol": "http", - "dmaapUserName": "admin", - "dmaapUserPassword": "admin", - "dmaapContentType": "application/json", - "consumerId": "c12", - "consumerGroup": "OpenDcae-c12", - "timeoutMs": -1, - "messageLimit": 1 - }, - "dmaapProducerConfiguration": { - "dmaapHostName": "localhost", - "dmaapPortNumber": 8904, - "dmaapTopicName": "events/unauthenticated.PNF_READY", - "dmaapProtocol": "http", - "dmaapUserName": "admin", - "dmaapUserPassword": "admin", - "dmaapContentType": "application/json" - }, - "dmaapUpdateProducerConfiguration": { - "dmaapHostName": "localhost", - "dmaapPortNumber": 8904, - "dmaapTopicName": "events/unauthenticated.PNF_UPDATE", - "dmaapProtocol": "http", - "dmaapUserName": "admin", - "dmaapUserPassword": "admin", - "dmaapContentType": "application/json" - } - }, - "aai": { - "aaiClientConfiguration": { - "aaiHost": "localhost", - "aaiPort": 8443, - "aaiProtocol": "https", - "aaiUserName": "AAI", - "aaiUserPassword": "AAI", - "aaiIgnoreSslCertificateErrors": true, - "aaiBasePath": "/aai/v12", - "aaiPnfPath": "/network/pnfs/pnf", - "aaiServiceInstancePath": "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}", - "aaiHeaders": { - "X-FromAppId": "prh", - "X-TransactionId": "9999", - "Accept": "application/json", - "Real-Time": "true", - "Authorization": "Basic QUFJOkFBSQ==" - } - } - }, - "security": { - "trustStorePath" : "change it", - "trustStorePasswordPath" : "change it", - "keyStorePath" : "change it", - "keyStorePasswordPath" : "change it", - "enableAaiCertAuth" : "false", - "enableDmaapCertAuth" : "false" - } - } -} \ No newline at end of file diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParserTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParserTest.java deleted file mode 100644 index 8f421034..00000000 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParserTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.prh.configuration; - -import static java.lang.ClassLoader.getSystemResource; -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import java.nio.file.Files; -import java.nio.file.Paths; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.prh.TestAppConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.ImmutableAaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration; - - -class CloudConfigParserTest { - - private final String correctJson = - new String(Files.readAllBytes(Paths.get(getSystemResource("flattened_configuration.json").toURI()))); - private final ImmutableAaiClientConfiguration correctAaiClientConfig = - TestAppConfiguration.createDefaultAaiClientConfiguration(); - private final ImmutableDmaapConsumerConfiguration correctDmaapConsumerConfig = - TestAppConfiguration.createDefaultDmaapConsumerConfiguration(); - private final ImmutableDmaapPublisherConfiguration correctDmaapPublisherConfig = - TestAppConfiguration.createDefaultDmaapPublisherConfiguration(); - private final CloudConfigParser cloudConfigParser = new CloudConfigParser( - new Gson().fromJson(correctJson, JsonObject.class)); - - CloudConfigParserTest() throws Exception { - } - - @Test - void shouldCreateAaiConfigurationCorrectly() { - // when - AaiClientConfiguration aaiClientConfig = cloudConfigParser.getAaiClientConfig(); - - // then - assertThat(aaiClientConfig).isNotNull(); - assertThat(aaiClientConfig).isEqualToComparingFieldByField(correctAaiClientConfig); - } - - - @Test - void shouldCreateDmaapConsumerConfigurationCorrectly() { - // when - DmaapConsumerConfiguration dmaapConsumerConfig = cloudConfigParser.getDmaapConsumerConfig(); - - // then - assertThat(dmaapConsumerConfig).isNotNull(); - assertThat(dmaapConsumerConfig).isEqualToComparingFieldByField(correctDmaapConsumerConfig); - } - - - @Test - void shouldCreateDmaapPublisherConfigurationCorrectly() { - // when - DmaapPublisherConfiguration dmaapPublisherConfig = cloudConfigParser.getDmaapPublisherConfig(); - - // then - assertThat(dmaapPublisherConfig).isNotNull(); - assertThat(dmaapPublisherConfig).isEqualToComparingFieldByField(correctDmaapPublisherConfig); - } -} \ No newline at end of file diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParserTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParserTest.java new file mode 100644 index 00000000..3c746940 --- /dev/null +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParserTest.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.configuration; + +import static java.lang.ClassLoader.getSystemResource; +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.TestAppConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.ImmutableAaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration; + + +class ConsulConfigurationParserTest { + + private final String correctJson = + new String(Files.readAllBytes(Paths.get(getSystemResource("flattened_configuration.json").toURI()))); + private final ImmutableAaiClientConfiguration correctAaiClientConfig = + TestAppConfiguration.createDefaultAaiClientConfiguration(); + private final ImmutableDmaapConsumerConfiguration correctDmaapConsumerConfig = + TestAppConfiguration.createDefaultDmaapConsumerConfiguration(); + private final ImmutableDmaapPublisherConfiguration correctDmaapPublisherConfig = + TestAppConfiguration.createDefaultDmaapPublisherConfiguration(); + private final ConsulConfigurationParser consulConfigurationParser = new ConsulConfigurationParser( + new Gson().fromJson(correctJson, JsonObject.class)); + + ConsulConfigurationParserTest() throws Exception { + } + + @Test + void shouldCreateAaiConfigurationCorrectly() { + // when + AaiClientConfiguration aaiClientConfig = consulConfigurationParser.getAaiClientConfig(); + + // then + assertThat(aaiClientConfig).isNotNull(); + assertThat(aaiClientConfig).isEqualToComparingFieldByField(correctAaiClientConfig); + } + + + @Test + void shouldCreateDmaapConsumerConfigurationCorrectly() { + // when + DmaapConsumerConfiguration dmaapConsumerConfig = consulConfigurationParser.getDmaapConsumerConfig(); + + // then + assertThat(dmaapConsumerConfig).isNotNull(); + assertThat(dmaapConsumerConfig).isEqualToComparingFieldByField(correctDmaapConsumerConfig); + } + + + @Test + void shouldCreateDmaapPublisherConfigurationCorrectly() { + // when + DmaapPublisherConfiguration dmaapPublisherConfig = consulConfigurationParser.getDmaapPublisherConfig(); + + // then + assertThat(dmaapPublisherConfig).isNotNull(); + assertThat(dmaapPublisherConfig).isEqualToComparingFieldByField(correctDmaapPublisherConfig); + } +} \ No newline at end of file diff --git a/prh-app-server/src/test/resources/flattened_configuration.json b/prh-app-server/src/test/resources/flattened_configuration.json index 3c1cc9ac..48b45a80 100644 --- a/prh-app-server/src/test/resources/flattened_configuration.json +++ b/prh-app-server/src/test/resources/flattened_configuration.json @@ -1,40 +1,42 @@ { - "aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors": true, - "dmaap.dmaapProducerConfiguration.dmaapTopicName": "/events/unauthenticated.PNF_READY", - "dmaap.dmaapUpdateProducerConfiguration.dmaapTopicName": "/events/unauthenticated.PNF_UPDATE", - "dmaap.dmaapConsumerConfiguration.timeoutMs": -1, - "dmaap.dmaapConsumerConfiguration.dmaapHostName": "message-router.onap.svc.cluster.local", - "aai.aaiClientConfiguration.pnfUrl": "https://aai.onap.svc.cluster.local:8443/aai/v12/network/pnfs/pnf", - "aai.aaiClientConfiguration.aaiPnfPath": "/network/pnfs/pnf", - "aai.aaiClientConfiguration.aaiServiceInstancePath": "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}", - "aai.aaiClientConfiguration.aaiUserPassword": "AAI", - "dmaap.dmaapConsumerConfiguration.dmaapUserName": "admin", - "aai.aaiClientConfiguration.aaiBasePath": "/aai/v12", - "dmaap.dmaapProducerConfiguration.dmaapPortNumber": 3904, - "aai.aaiClientConfiguration.aaiHost": "aai.onap.svc.cluster.local", - "dmaap.dmaapConsumerConfiguration.dmaapUserPassword": "admin", - "dmaap.dmaapProducerConfiguration.dmaapProtocol": "http", - "dmaap.dmaapProducerConfiguration.dmaapContentType": "application/json", - "dmaap.dmaapUpdateProducerConfiguration.dmaapProtocol": "http", - "dmaap.dmaapUpdateProducerConfiguration.dmaapContentType": "application/json", - "dmaap.dmaapConsumerConfiguration.dmaapTopicName": "/events/unauthenticated.SEC_OTHER_OUTPUT", - "dmaap.dmaapConsumerConfiguration.dmaapPortNumber": 3904, - "dmaap.dmaapConsumerConfiguration.dmaapContentType": "application/json", - "dmaap.dmaapConsumerConfiguration.messageLimit": -1, - "dmaap.dmaapConsumerConfiguration.dmaapProtocol": "http", - "aai.aaiClientConfiguration.aaiUserName": "AAI", - "dmaap.dmaapConsumerConfiguration.consumerId": "c12", - "dmaap.dmaapProducerConfiguration.dmaapHostName": "message-router.onap.svc.cluster.local", - "dmaap.dmaapUpdateProducerConfiguration.dmaapHostName": "message-router.onap.svc.cluster.local", - "aai.aaiClientConfiguration.aaiHostPortNumber": 8443, - "dmaap.dmaapConsumerConfiguration.consumerGroup": "OpenDCAE-c12", - "aai.aaiClientConfiguration.aaiProtocol": "https", - "dmaap.dmaapProducerConfiguration.dmaapUserName": "admin", - "dmaap.dmaapProducerConfiguration.dmaapUserPassword": "admin", - "security.trustStorePath": "/opt/app/prh/local/org.onap.prh.trust.jks", - "security.trustStorePasswordPath": "change_it", - "security.keyStorePath": "/opt/app/prh/local/org.onap.prh.p12", - "security.keyStorePasswordPath": "change_it", - "security.enableAaiCertAuth": false, - "security.enableDmaapCertAuth": false + "config": { + "aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors": true, + "dmaap.dmaapProducerConfiguration.dmaapTopicName": "/events/unauthenticated.PNF_READY", + "dmaap.dmaapUpdateProducerConfiguration.dmaapTopicName": "/events/unauthenticated.PNF_UPDATE", + "dmaap.dmaapConsumerConfiguration.timeoutMs": -1, + "dmaap.dmaapConsumerConfiguration.dmaapHostName": "message-router.onap.svc.cluster.local", + "aai.aaiClientConfiguration.pnfUrl": "https://aai.onap.svc.cluster.local:8443/aai/v12/network/pnfs/pnf", + "aai.aaiClientConfiguration.aaiPnfPath": "/network/pnfs/pnf", + "aai.aaiClientConfiguration.aaiServiceInstancePath": "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}", + "aai.aaiClientConfiguration.aaiUserPassword": "AAI", + "dmaap.dmaapConsumerConfiguration.dmaapUserName": "admin", + "aai.aaiClientConfiguration.aaiBasePath": "/aai/v12", + "dmaap.dmaapProducerConfiguration.dmaapPortNumber": 3904, + "aai.aaiClientConfiguration.aaiHost": "aai.onap.svc.cluster.local", + "dmaap.dmaapConsumerConfiguration.dmaapUserPassword": "admin", + "dmaap.dmaapProducerConfiguration.dmaapProtocol": "http", + "dmaap.dmaapProducerConfiguration.dmaapContentType": "application/json", + "dmaap.dmaapUpdateProducerConfiguration.dmaapProtocol": "http", + "dmaap.dmaapUpdateProducerConfiguration.dmaapContentType": "application/json", + "dmaap.dmaapConsumerConfiguration.dmaapTopicName": "/events/unauthenticated.SEC_OTHER_OUTPUT", + "dmaap.dmaapConsumerConfiguration.dmaapPortNumber": 3904, + "dmaap.dmaapConsumerConfiguration.dmaapContentType": "application/json", + "dmaap.dmaapConsumerConfiguration.messageLimit": -1, + "dmaap.dmaapConsumerConfiguration.dmaapProtocol": "http", + "aai.aaiClientConfiguration.aaiUserName": "AAI", + "dmaap.dmaapConsumerConfiguration.consumerId": "c12", + "dmaap.dmaapProducerConfiguration.dmaapHostName": "message-router.onap.svc.cluster.local", + "dmaap.dmaapUpdateProducerConfiguration.dmaapHostName": "message-router.onap.svc.cluster.local", + "aai.aaiClientConfiguration.aaiHostPortNumber": 8443, + "dmaap.dmaapConsumerConfiguration.consumerGroup": "OpenDCAE-c12", + "aai.aaiClientConfiguration.aaiProtocol": "https", + "dmaap.dmaapProducerConfiguration.dmaapUserName": "admin", + "dmaap.dmaapProducerConfiguration.dmaapUserPassword": "admin", + "security.trustStorePath": "/opt/app/prh/local/org.onap.prh.trust.jks", + "security.trustStorePasswordPath": "change_it", + "security.keyStorePath": "/opt/app/prh/local/org.onap.prh.p12", + "security.keyStorePasswordPath": "change_it", + "security.enableAaiCertAuth": false, + "security.enableDmaapCertAuth": false + } } \ No newline at end of file -- cgit 1.2.3-korg