diff options
Diffstat (limited to 'dcae-analytics/dcae-analytics-web/src')
4 files changed, 18 insertions, 117 deletions
diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/SystemConfig.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/SystemConfig.java deleted file mode 100644 index 946c2f2..0000000 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/SystemConfig.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============LICENSE_START====================================================================== - * Copyright (C) 2019-2020 China Mobile. 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.dcae.analytics.web.config; - -import java.util.Optional; - -import org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants; -import org.onap.dcae.analytics.web.exception.EnvironmentLoaderException; - -/** - * - * get consul config and cbs config. - * - * @author Kai Lu - */ -public class SystemConfig { - - /** - * - * private constructor. - * - */ - private SystemConfig() { - } - - /** - * getConsulHost. - * - * @return consulHost consulHost - * - */ - public static String getConsulHost() throws EnvironmentLoaderException { - return Optional.ofNullable(ConfigBindingServiceConstants.CONSUL_HOST_ENV_VARIABLE_VALUE) - .orElseThrow(() -> new EnvironmentLoaderException("$CONSUL_HOST environment has not been defined")); - } - - /** - * getConsultPort. - * - * @return consulPort consulPort - * - */ - public static Integer getConsultPort() { - return ConfigBindingServiceConstants.DEFAULT_CONSUL_PORT_ENV_VARIABLE_VALUE; - } - - /** - * getConfigBindingService. - * - * @return configBindingService configBindingService - * - */ - public static String getConfigBindingService() throws EnvironmentLoaderException { - return Optional.ofNullable(ConfigBindingServiceConstants.CONFIG_BINDING_SERVICE_ENV_VARIABLE_VALUE) // - .orElseThrow(() -> new EnvironmentLoaderException( - "$CONFIG_BINDING_SERVICE environment has not been defined")); - } - - /** - * getService. - * - * @return service service - * - */ - public static String getService() throws EnvironmentLoaderException { - return Optional.ofNullable(ConfigBindingServiceConstants.SERVICE_NAME_ENV_VARIABLE_VALUE).orElseThrow( - () -> new EnvironmentLoaderException("$HOSTNAME have not been defined as system environment")); - } - -} diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessor.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessor.java index 5fa82d6..d643de2 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessor.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessor.java @@ -30,14 +30,11 @@ import java.util.stream.Collectors; import org.onap.dcae.analytics.model.AnalyticsProfile; import org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants; import org.onap.dcae.analytics.model.util.function.JsonStringToMapFunction; -import org.onap.dcae.analytics.web.config.SystemConfig; -import org.onap.dcae.analytics.web.exception.EnvironmentLoaderException; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient; 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.CbsClientConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest; -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.model.logging.RequestDiagnosticContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -177,21 +174,10 @@ public class ConfigBindingServiceEnvironmentPostProcessor implements Environment * @return environment properties. * */ - public Mono<EnvProperties> readEnvironmentVariables() { + public Mono<CbsClientConfiguration> readEnvironmentVariables() { logger.trace("Loading configuration from system environment variables"); - EnvProperties envProperties; - try { - envProperties = ImmutableEnvProperties.builder() // - .consulHost(SystemConfig.getConsulHost()) // - .consulPort(SystemConfig.getConsultPort()) // - .cbsName(SystemConfig.getConfigBindingService()) // - .appName(SystemConfig.getService()) // - .build(); - } catch (EnvironmentLoaderException e) { - return Mono.error(e); - } - logger.trace("Evaluated environment system variables {}", envProperties); - return Mono.just(envProperties); + CbsClientConfiguration cbsClientConfiguration = CbsClientConfiguration.fromEnvironment(); + return Mono.just(cbsClientConfiguration); } /** @@ -220,12 +206,12 @@ public class ConfigBindingServiceEnvironmentPostProcessor implements Environment /** * create CbsClient. * - * @param env environment properties + * @param cbsClientConfiguration cbs configuration * @return cbsclient * */ - public Mono<CbsClient> createCbsClient(EnvProperties env) { - return CbsClientFactory.createCbsClient(env); + public Mono<CbsClient> createCbsClient(CbsClientConfiguration cbsClientConfiguration) { + return CbsClientFactory.createCbsClient(cbsClientConfiguration); } /** diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/BaseAnalyticsWebTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/BaseAnalyticsWebTest.java index 641ad95..34ca253 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/BaseAnalyticsWebTest.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/BaseAnalyticsWebTest.java @@ -27,6 +27,7 @@ import java.util.HashMap; import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants.CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY; import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants.CONSUL_HOST_ENV_VARIABLE_KEY; import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants.SERVICE_NAME_ENV_VARIABLE_KEY; +import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants.ENV_CBS_PORT; /** * @author Rajiv Singla @@ -42,6 +43,7 @@ public abstract class BaseAnalyticsWebTest extends BaseAnalyticsUnitTest { testEnvironmentVariables.put(CONSUL_HOST_ENV_VARIABLE_KEY, testConsulHostValue); testEnvironmentVariables.put(CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY, testConfigBindingService); testEnvironmentVariables.put(SERVICE_NAME_ENV_VARIABLE_KEY, testServiceName); + testEnvironmentVariables.put(ENV_CBS_PORT, "10000"); setEnvironmentVariables(testEnvironmentVariables); } diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorTest.java index ac03f7e..caac2b3 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorTest.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorTest.java @@ -25,13 +25,14 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.dcae.analytics.model.AnalyticsProfile; import org.onap.dcae.analytics.web.BaseAnalyticsWebTest; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient; -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.springframework.boot.SpringApplication; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; @@ -41,10 +42,14 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; public class ConfigBindingServiceEnvironmentPostProcessorTest extends BaseAnalyticsWebTest { + @BeforeAll + static void beforeAll() throws Exception { + BaseAnalyticsWebTest.initializeConfigBindingServiceEnvironmentVariables(); + } + @Test void postProcessEnvironment() { CbsClient cbsClient = Mockito.mock(CbsClient.class); @@ -56,13 +61,6 @@ public class ConfigBindingServiceEnvironmentPostProcessorTest extends BaseAnalyt String configServicePropertiesKey = "config-binding-service"; MutablePropertySources sources = configurableEnvironment.getPropertySources(); - EnvProperties envProperties; - envProperties = ImmutableEnvProperties.builder() // - .consulHost("consul-server.onap") // - .consulPort(8500) // - .cbsName("config-binding-service") // - .appName("dcae-tca-analytics") // - .build(); String strConfig = "{\"spring.data.mongodb.uri\": \"mongodb://tcagen2-mongohost/analytics-tca\", \"streams_subscribes\": {\"tca_handle_in\": {\"type\": \"message_router\", \"dmaap_info\": {\"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_MEASUREMENT3_OUTPUT\"}}}, \"tca.enable_ecomp_logging\": true, \"tca.enable_abatement\": true, \"tca.aai.password\": \"DCAE\", \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\", \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000, \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\", \"streams_publishes\": {\"tca_handle_out\": {\"type\": \"message_router\", \"dmaap_info\": {\"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.TCAGEN3-OUTPUT\"}}}, \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\", \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\", \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000, \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000, \"tca.aai.username\": \"DCAE\", \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000, \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\", \"streams_subscribes.tca_handle_in.timeout\": -1, \"tca.aai.enable_enrichment\": true, \"tca.policy\": \"{\\\"domain\\\":\\\"measurementsForVfScaling\\\",\\\"metricsPerEventName\\\":[{\\\"eventName\\\":\\\"vFirewallBroadcastPackets\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.3\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"LESS_OR_EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":700,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"vLoadBalancer\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"Measurement_vGMUX\\\",\\\"controlLoopSchemaType\\\":\\\"VNF\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ABATED\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"GREATER\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]}]}\", \"tca.processing_batch_size\": 10000, \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0, \"streams_subscribes.tca_handle_in.message_limit\": 50000, \"service_calls\": [], \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"}"; String parseConfig = "{\"config\": {\"spring.data.mongodb.uri\": \"mongodb://tcagen2-mongohost/analytics-tca\", \"streams_subscribes\": {\"tca_handle_in\": {\"type\": \"message_router\", \"dmaap_info\": {\"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_MEASUREMENT3_OUTPUT\"}}}, \"tca.enable_ecomp_logging\": true, \"tca.enable_abatement\": true, \"tca.aai.password\": \"DCAE\", \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\", \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000, \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\", \"streams_publishes\": {\"tca_handle_out\": {\"type\": \"message_router\", \"dmaap_info\": {\"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.TCAGEN3-OUTPUT\"}}}, \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\", \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\", \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000, \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000, \"tca.aai.username\": \"DCAE\", \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000, \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\", \"streams_subscribes.tca_handle_in.timeout\": -1, \"tca.aai.enable_enrichment\": true, \"tca.policy\": \"{\\\"domain\\\":\\\"measurementsForVfScaling\\\",\\\"metricsPerEventName\\\":[{\\\"eventName\\\":\\\"vFirewallBroadcastPackets\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.3\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"LESS_OR_EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":700,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"vLoadBalancer\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"Measurement_vGMUX\\\",\\\"controlLoopSchemaType\\\":\\\"VNF\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ABATED\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"GREATER\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]}]}\", \"tca.processing_batch_size\": 10000, \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0, \"streams_subscribes.tca_handle_in.message_limit\": 50000, \"service_calls\": [], \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"}}"; @@ -71,8 +69,7 @@ public class ConfigBindingServiceEnvironmentPostProcessorTest extends BaseAnalyt JsonObject parseJson = parser.parse(parseConfig).getAsJsonObject(); Mockito.when(configurableEnvironment.getActiveProfiles()).thenReturn(activeProfiles); - Mockito.when(testObject.readEnvironmentVariables()).thenReturn(Mono.just(envProperties)); - Mockito.when(testObject.createCbsClient(envProperties)).thenReturn(Mono.just(cbsClient)); + Mockito.when(testObject.periodicConfigurationUpdates(cbsClient)).thenReturn(Flux.just(json)); Mockito.doNothing().when(testObject).addJsonPropertySource(sources, new MapPropertySource(configServicePropertiesKey, filterKeyMap)); testObject.postProcessEnvironment(configurableEnvironment, springApplication); |