diff options
author | 2020-02-13 22:48:36 +0000 | |
---|---|---|
committer | 2020-02-13 22:48:36 +0000 | |
commit | 8e924858d792abf90c689d65ec89daa67ed72298 (patch) | |
tree | a3d4e26644249598ab35a3337a5471830900502f /src/main | |
parent | 15ad507dc77e61628c554bee2f6bbb67ae605d93 (diff) | |
parent | cee68e2e64d35019b7b66570062bd6e8e7981dc5 (diff) |
Merge "Update microservice to run as standalone MS"
Diffstat (limited to 'src/main')
6 files changed, 544 insertions, 112 deletions
diff --git a/src/main/docker/config/dmaap/MsgRtrApi.properties b/src/main/docker/config/dmaap/MsgRtrApi.properties new file mode 100755 index 0000000..61f3f03 --- /dev/null +++ b/src/main/docker/config/dmaap/MsgRtrApi.properties @@ -0,0 +1,171 @@ +# LICENSE_START======================================================= +# org.onap.dmaap +# ================================================================================ +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2020 Wipro Limited. +# ================================================================================ +# 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========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# +############################################################################### +############################################################################### +## +## Cambria API Server config +## +## - Default values are shown as commented settings. +## + +############################################################################### +## +## HTTP service +## +## - 3904 is standard as of 7/29/14. +# +## Zookeeper Connection +## +## Both Cambria and Kafka make use of Zookeeper. +## +#config.zk.servers=172.18.1.1 +config.zk.servers=zookeeper:2181 +#config.zk.root=/fe3c/cambria/config + + +############################################################################### +## +## Kafka Connection +## +## Items below are passed through to Kafka's producer and consumer +## configurations (after removing "kafka.") +## if you want to change request.required.acks it can take this one value +#kafka.metadata.broker.list=localhost:9092,localhost:9093 +kafka.metadata.broker.list=kafka:9092 +##kafka.request.required.acks=-1 +#kafka.client.zookeeper=${config.zk.servers} +consumer.timeout.ms=100 +zookeeper.connection.timeout.ms=6000 +zookeeper.session.timeout.ms=20000 +zookeeper.sync.time.ms=2000 +auto.commit.interval.ms=1000 +fetch.message.max.bytes =1000000 +auto.commit.enable=false + +#(backoff*retries > zksessiontimeout) +kafka.rebalance.backoff.ms=10000 +kafka.rebalance.max.retries=6 + + +############################################################################### +## +## Secured Config +## +## Some data stored in the config system is sensitive -- API keys and secrets, +## for example. to protect it, we use an encryption layer for this section +## of the config. +## +## The key is a base64 encode AES key. This must be created/configured for +## each installation. +#cambria.secureConfig.key= +## +## The initialization vector is a 16 byte value specific to the secured store. +## This must be created/configured for each installation. +#cambria.secureConfig.iv= + +## Southfield Sandbox +cambria.secureConfig.key=b/7ouTn9FfEw2PQwL0ov/Q== +cambria.secureConfig.iv=wR9xP5k5vbz/xD0LmtqQLw== +authentication.adminSecret=fe3cCompound +#cambria.secureConfig.key[pc569h]=YT3XPyxEmKCTLI2NK+Sjbw== +#cambria.secureConfig.iv[pc569h]=rMm2jhR3yVnU+u2V9Ugu3Q== + + +############################################################################### +## +## Consumer Caching +## +## Kafka expects live connections from the consumer to the broker, which +## obviously doesn't work over connectionless HTTP requests. The Cambria +## server proxies HTTP requests into Kafka consumer sessions that are kept +## around for later re-use. Not doing so is costly for setup per request, +## which would substantially impact a high volume consumer's performance. +## +## This complicates Cambria server failover, because we often need server +## A to close its connection before server B brings up the replacement. +## + +## The consumer cache is normally enabled. +#cambria.consumer.cache.enabled=true + +## Cached consumers are cleaned up after a period of disuse. The server inspects +## consumers every sweepFreqSeconds and will clean up any connections that are +## dormant for touchFreqMs. +#cambria.consumer.cache.sweepFreqSeconds=15 +cambria.consumer.cache.touchFreqMs=120000 +##stickforallconsumerrequests=false +## The cache is managed through ZK. The default value for the ZK connection +## string is the same as config.zk.servers. +#cambria.consumer.cache.zkConnect=${config.zk.servers} + +## +## Shared cache information is associated with this node's name. The default +## name is the hostname plus the HTTP service port this host runs on. (The +## hostname is determined via InetAddress.getLocalHost ().getCanonicalHostName(), +## which is not always adequate.) You can set this value explicitly here. +## +#cambria.api.node.identifier=<use-something-unique-to-this-instance> + +#cambria.rateLimit.maxEmptyPollsPerMinute=30 +#cambria.rateLimitActual.delay.ms=10 + +############################################################################### +## +## Metrics Reporting +## +## This server can report its metrics periodically on a topic. +## +#metrics.send.cambria.enabled=true +#metrics.send.cambria.topic=cambria.apinode.metrics #msgrtr.apinode.metrics.dmaap +#metrics.send.cambria.sendEverySeconds=60 + +cambria.consumer.cache.zkBasePath=/fe3c/cambria/consumerCache +consumer.timeout=17 +default.partitions=3 +default.replicas=3 +############################################################################## +#100mb +maxcontentlength=10000 + + +############################################################################## +#AAF Properties +msgRtr.namespace.aaf=org.onap.dmaap.mr.topic +msgRtr.topicfactory.aaf=org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic: +enforced.topic.name.AAF=org.onap +forceAAF=false +transidUEBtopicreqd=false +defaultNSforUEB=org.onap.dmaap.mr +############################################################################## +#Mirror Maker Agent +msgRtr.mirrormakeradmin.aaf=com.onap.dmaap.mr.dev.mirrormaker|*|admin +msgRtr.mirrormakeruser.aaf=com.onap.dmaap.mr.dev.mirrormaker|*|user +msgRtr.mirrormakeruser.aaf.create=com.onap.dmaap.mr.dev.topicFactory|:com.onap.dmaap.mr.dev.topic: +msgRtr.mirrormaker.timeout=15000 +msgRtr.mirrormaker.topic=com.onap.dmaap.mr.prod.mm.agent +msgRtr.mirrormaker.consumergroup=mmagentserver +msgRtr.mirrormaker.consumerid=1 + +kafka.max.poll.interval.ms=300000 +kafka.heartbeat.interval.ms=60000 +kafka.session.timeout.ms=240000 +kafka.max.poll.records=1000 + diff --git a/src/main/docker/config/sonhms/config_all.json b/src/main/docker/config/sonhms/config_all.json new file mode 100644 index 0000000..cbb2384 --- /dev/null +++ b/src/main/docker/config/sonhms/config_all.json @@ -0,0 +1,131 @@ +{ + "config": { + "sonhandler.badCountThreshold": 3, + "streams_subscribes": { + "performance_management_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/unauthenticated.VES_MEASUREMENT_OUTPUT", + "client_role": "son-subscriber", + "location": "onap", + "client_id": "sdnr-son-1" + }, + "aaf_username": null + }, + "fault_management_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/unauthenticated.SEC_FAULT_OUTPUT", + "client_role": "son-subscriber", + "location": "onap", + "client_id": "sdnr-son-1" + }, + "aaf_username": null + }, + "nbr_list_change_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/PCI-NOTIF-TOPIC-NGHBR-LIST-CHANGE-INFO", + "client_role": "son-subscriber", + "location": "onap", + "client_id": "sdnr-son-1" + }, + "aaf_username": null + }, + "dcae_cl_response_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_RSP", + "client_role": "son-subscriber", + "location": "onap", + "client_id": "sdnr-son-1" + }, + "aaf_username": null + } + }, + "postgres.port": "5432", + "sonhandler.pciOptimizer": "pci", + "sonhandler.maximumClusters": 5, + "sonhandler.numSolutions": 5, + "sonhandler.poorCountThreshold": 3, + "sonhandler.minCollision": 5, + "streams_publishes": { + "CL_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/unauthenticated.DCAE_CL_OUTPUT", + "client_role": "son-subscriber", + "location": "onap", + "client_id": "sdnr-son-1" + }, + "aaf_username": null + } + }, + "sonhandler.namespace": "onap", + "sonhandler.oof.endpoint": "/api/oof/v1/pci", + "postgres.password": "postgres", + "sonhandler.minConfusion": 5, + "sonhandler.sourceId": "SONHMS", + "postgres.username": "sonhms_admin", + "postgres.host": "postgres", + "sonhandler.policyRespTimer": 10, + "sonhandler.dmaap.server": [ + "dmaap" + ], + "sonhandler.poorThreshold": 70, + "sonhandler.oofTriggerCountTimer": 30, + "cbsPollingInterval": 60, + "sonhandler.cg": "sonhms-cg", + "sonhandler.pollingInterval": 20, + "sonhandler.badThreshold": 50, + "sonhandler.bufferTime": 60, + "sonhandler.cid": "sonhms-cid", + "sonhandler.configDb.service": "http://sdnc.onap:8181", + "sonhandler.oofTriggerCountThreshold": 5, + "sonhandler.oof.service": "http://oof-osdf.onap:8699", + "sonhandler.pciAnrOptimizer": "pci_anr", + "sonhandler.pollingTimeout": 60, + "service_calls": { + "sdnr-getpnfname": [], + "sdnr-getpci": [], + "sdnr-getnbrlist": [], + "sdnr-getcelllist": [], + "oof-req": [], + "policy-req": [] + } + }, + "policies": { + "event": { + "action": "gathered", + "timestamp": "2019-09-18T14:57:55.320Z", + "update_id": "dbb88da8-8df1-489d-b51d-8d5cbbfbcd99", + "policies_count": 1 + }, + "items": [ + { + "policyName": "com.Config_PCIMS_CONFIG_POLICY.1.xml", + "name": "com.Config_PCIMS_CONFIG_POLICY", + "config": { + "PCI_SDNR_TARGET_NAME": "SDNR", + "PCI_OPTMIZATION_ALGO_CATEGORY_IN_OOF": "OOF-PCI-OPTIMIZATION", + "PCI_NEIGHBOR_CHANGE_CLUSTER_TIMEOUT_IN_SECS": 60, + "PCI_MODCONFIGANR_POLICY_NAME": "ControlLoop-vSONH-7d4baf04-8875-4d1f-946d-06b874048b61", + "PCI_MODCONFIG_POLICY_NAME": "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459" + }, + "type_version": "1.0.0", + "version": "1.0.0", + "policyVersion": "1", + "type": "onap.policies.monitoring.docker.sonhandler.app", + "metadata": { + "policy-id": "com.Config_PCIMS_CONFIG_POLICY", + "policy-version": "1" + } + } + ] + } +}
\ No newline at end of file diff --git a/src/main/docker/docker-compose.yaml b/src/main/docker/docker-compose.yaml new file mode 100644 index 0000000..49d516e --- /dev/null +++ b/src/main/docker/docker-compose.yaml @@ -0,0 +1,91 @@ +# ============LICENSE_START======================================================= +# son-handler +# ================================================================================ +# Copyright (C) 2020 Wipro Limited. +# ============================================================================== +# 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========================================================= + +version: '2.4' +networks: + sonhms-default: + driver: bridge + driver_opts: + com.docker.network.driver.mtu: 1400 +services: + zookeeper: + image: wurstmeister/zookeeper + ports: + - "2181:2181" + networks: + - sonhms-default + kafka: + image: wurstmeister/kafka + ports: + - "9092:9092" + environment: + KAFKA_ADVERTISED_HOST_NAME: "kafka" + KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true' + KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181" + KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka:9092" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + depends_on: + - zookeeper + networks: + - sonhms-default + dmaap: + image: nexus3.onap.org:10001/onap/dmaap/dmaap-mr:1.1.8 + ports: + - "3904:3904" + - "3905:3905" + volumes: + - ./config/dmaap/MsgRtrApi.properties:/appl/dmaapMR1/bundleconfig/etc/appprops/MsgRtrApi.properties + depends_on: + - zookeeper + - kafka + networks: + - sonhms-default + postgres: + image: 'postgres:12-alpine' + container_name: sonhms-postgres + hostname: postgres + environment: + - POSTGRES_USER=sonhms_admin + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=sonhms + ports: + - 5432 + healthcheck: + test: ["CMD", "nc", "-z", "localhost", "5432"] + interval: 30s + timeout: 10s + retries: 5 + networks: + - sonhms-default + sonhms: + image: "nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.son-handler:latest" + container_name: sonhms + hostname: sonhms + environment: + - STANDALONE=true + - CONFIG_FILE=/etc/config_all.json + ports: + - "8080:8080" + volumes: + - ./config/sonhms/config_all.json:/etc/config_all.json + depends_on: + - postgres + networks: + - sonhms-default + diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java index 9919bed..3e65c8c 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java @@ -2,26 +2,34 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019 Wipro Limited. + * Copyright (C) 2019-2020 Wipro Limited. * ============================================================================== * 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.sonhms; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.lang.reflect.Type; import java.time.Duration; +import java.util.Map; import javax.sql.DataSource; @@ -33,6 +41,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; + @SpringBootApplication public class Application { @@ -42,6 +51,40 @@ public class Application { * Main method where the pci context is initially set. */ public static void main(String[] args) { + getConfig(); + log.info("Starting spring boot application"); + SpringApplication.run(Application.class); + + } + + private static void getConfig() { + + Boolean standalone = Boolean.parseBoolean(System.getenv("STANDALONE")); + + if (standalone) { + log.info("Running in standalone mode"); + + String configFile = System.getenv("CONFIG_FILE"); + String configAllJson = readFromFile(configFile); + + JsonObject configAll = new Gson().fromJson(configAllJson, JsonObject.class); + + JsonObject config = configAll.getAsJsonObject("config"); + + Configuration.getInstance().updateConfigurationFromJsonObject(config); + + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + Type mapType = new TypeToken<Map<String, Object>>() { + }.getType(); + if (configAll.getAsJsonObject("policies") != null) { + JsonObject policyJson = configAll.getAsJsonObject("policies").getAsJsonArray("items").get(0) + .getAsJsonObject().getAsJsonObject("config"); + Map<String, Object> policy = new Gson().fromJson(policyJson, mapType); + configPolicy.setConfig(policy); + log.info("Config policy {}", configPolicy); + } + return; + } ConfigFetchFromCbs configFetchFromCbs = new ConfigFetchFromCbs(Duration.ofSeconds(60)); Thread configFetchThread = new Thread(configFetchFromCbs); @@ -52,9 +95,6 @@ public class Application { log.debug("InterruptedException : {}", e); } log.info("after 10s sleep"); - log.info("Starting spring boot application"); - SpringApplication.run(Application.class); - } /** @@ -70,4 +110,19 @@ public class Application { .password(configuration.getPgPassword()).build(); } -} + private static String readFromFile(String file) { + String content = ""; + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { + content = bufferedReader.readLine(); + String temp; + while ((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + } catch (Exception e) { + content = null; + } + return content; + } + +}
\ No newline at end of file diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java index faa1b4e..d3d9d39 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java @@ -2,30 +2,42 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019 Wipro Limited. + * Copyright (C) 2019-2020 Wipro Limited. * ============================================================================== * 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.sonhms; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +import java.lang.reflect.Type; import java.util.List; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + public class Configuration { + private static Logger log = LoggerFactory.getLogger(Configuration.class); + private static Configuration instance = null; private String pgHost; private int pgPort; @@ -59,8 +71,8 @@ public class Configuration { private int oofTriggerCountTimer; private int oofTriggerCountThreshold; private int policyRespTimer; - - + + public int getPoorCountThreshold() { return poorCountThreshold; } @@ -122,7 +134,7 @@ public class Configuration { */ public boolean isSecured() { return (aafUsername != null); - + } public String getAafUsername() { @@ -355,7 +367,67 @@ public class Configuration { + oofTriggerCountTimer + ", oofTriggerCountThreshold=" + oofTriggerCountThreshold + ", policyRespTimer=" + policyRespTimer + "]"; } - - -} + /** + * updates application configuration. + */ + public void updateConfigurationFromJsonObject(JsonObject jsonObject) { + + log.info("Updating configuration from CBS"); + + Type mapType = new TypeToken<Map<String, Object>>() { + }.getType(); + + JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); + streamsSubscribes = new Gson().fromJson(subscribes, mapType); + + JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes"); + streamsPublishes = new Gson().fromJson(publishes, mapType); + + pgPort = jsonObject.get("postgres.port").getAsInt(); + pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt(); + pgPassword = jsonObject.get("postgres.password").getAsString(); + numSolutions = jsonObject.get("sonhandler.numSolutions").getAsInt(); + minConfusion = jsonObject.get("sonhandler.minConfusion").getAsInt(); + maximumClusters = jsonObject.get("sonhandler.maximumClusters").getAsInt(); + minCollision = jsonObject.get("sonhandler.minCollision").getAsInt(); + sourceId = jsonObject.get("sonhandler.sourceId").getAsString(); + pgUsername = jsonObject.get("postgres.username").getAsString(); + pgHost = jsonObject.get("postgres.host").getAsString(); + + JsonArray servers = jsonObject.getAsJsonArray("sonhandler.dmaap.server"); + Type listType = new TypeToken<List<String>>() { + }.getType(); + dmaapServers = new Gson().fromJson(servers, listType); + + cg = jsonObject.get("sonhandler.cg").getAsString(); + bufferTime = jsonObject.get("sonhandler.bufferTime").getAsInt(); + cid = jsonObject.get("sonhandler.cid").getAsString(); + configDbService = jsonObject.get("sonhandler.configDb.service").getAsString(); + String namespace = jsonObject.get("sonhandler.namespace").getAsString(); + callbackUrl = "http://" + System.getenv("HOSTNAME") + "." + namespace + ":8080/callbackUrl"; + + pciOptimizer = jsonObject.get("sonhandler.pciOptimizer").getAsString(); + pciAnrOptimizer = jsonObject.get("sonhandler.pciAnrOptimizer").getAsString(); + + oofService = jsonObject.get("sonhandler.oof.service").getAsString(); + oofEndpoint = jsonObject.get("sonhandler.oof.endpoint").getAsString(); + pollingTimeout = jsonObject.get("sonhandler.pollingTimeout").getAsInt(); + + badThreshold = jsonObject.get("sonhandler.badThreshold").getAsInt(); + poorThreshold = jsonObject.get("sonhandler.poorThreshold").getAsInt(); + + poorCountThreshold = jsonObject.get("sonhandler.poorCountThreshold").getAsInt(); + badCountThreshold = jsonObject.get("sonhandler.badCountThreshold").getAsInt(); + oofTriggerCountTimer = jsonObject.get("sonhandler.oofTriggerCountTimer").getAsInt(); + oofTriggerCountThreshold = jsonObject.get("sonhandler.oofTriggerCountThreshold").getAsInt(); + policyRespTimer = jsonObject.get("sonhandler.policyRespTimer").getAsInt(); + + + log.info("configuration from CBS {}", this); + + } + + + +}
\ No newline at end of file diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java b/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java index afa26d8..448ac27 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java @@ -2,33 +2,31 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019 Wipro Limited. + * Copyright (C) 2019-2020 Wipro Limited. * ============================================================================== * 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.sonhms.controller; import com.google.gson.Gson; -import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.time.Duration; -import java.util.List; import java.util.Map; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClientFactory; @@ -89,7 +87,7 @@ public class ConfigFetchFromCbs implements Runnable { } } - updateConfigurationFromJsonObject(config); + Configuration.getInstance().updateConfigurationFromJsonObject(config); Type mapType = new TypeToken<Map<String, Object>>() { }.getType(); @@ -103,93 +101,7 @@ public class ConfigFetchFromCbs implements Runnable { }, throwable -> log.warn("Ooops", throwable)); } - private void updateConfigurationFromJsonObject(JsonObject jsonObject) { - - log.info("Updating configuration from CBS"); - Configuration configuration = Configuration.getInstance(); - - Type mapType = new TypeToken<Map<String, Object>>() { - }.getType(); - - JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); - Map<String, Object> streamsSubscribes = new Gson().fromJson(subscribes, mapType); - - JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes"); - Map<String, Object> streamsPublishes = new Gson().fromJson(publishes, mapType); - - int pgPort = jsonObject.get("postgres.port").getAsInt(); - int pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt(); - String pgPassword = jsonObject.get("postgres.password").getAsString(); - int numSolutions = jsonObject.get("sonhandler.numSolutions").getAsInt(); - int minConfusion = jsonObject.get("sonhandler.minConfusion").getAsInt(); - int maximumClusters = jsonObject.get("sonhandler.maximumClusters").getAsInt(); - int minCollision = jsonObject.get("sonhandler.minCollision").getAsInt(); - String sourceId = jsonObject.get("sonhandler.sourceId").getAsString(); - String pgUsername = jsonObject.get("postgres.username").getAsString(); - String pgHost = jsonObject.get("postgres.host").getAsString(); - - JsonArray servers = jsonObject.getAsJsonArray("sonhandler.dmaap.server"); - Type listType = new TypeToken<List<String>>() { - }.getType(); - List<String> dmaapServers = new Gson().fromJson(servers, listType); - - String cg = jsonObject.get("sonhandler.cg").getAsString(); - int bufferTime = jsonObject.get("sonhandler.bufferTime").getAsInt(); - String cid = jsonObject.get("sonhandler.cid").getAsString(); - String configDbService = jsonObject.get("sonhandler.configDb.service").getAsString(); - String namespace = jsonObject.get("sonhandler.namespace").getAsString(); - String callbackUrl = "http://" + System.getenv("HOSTNAME") + "." + namespace + ":8080/callbackUrl"; - - String pciOptimizer = jsonObject.get("sonhandler.pciOptimizer").getAsString(); - String pciAnrOptimizer = jsonObject.get("sonhandler.pciAnrOptimizer").getAsString(); - - String oofService = jsonObject.get("sonhandler.oof.service").getAsString(); - String oofEndpoint = jsonObject.get("sonhandler.oof.endpoint").getAsString(); - int pollingTimeout = jsonObject.get("sonhandler.pollingTimeout").getAsInt(); - - int badThreshold = jsonObject.get("sonhandler.badThreshold").getAsInt(); - int poorThreshold = jsonObject.get("sonhandler.poorThreshold").getAsInt(); - - int poorCountThreshold = jsonObject.get("sonhandler.poorCountThreshold").getAsInt(); - int badCountThreshold = jsonObject.get("sonhandler.badCountThreshold").getAsInt(); - int oofTriggerCountTimer = jsonObject.get("sonhandler.oofTriggerCountTimer").getAsInt(); - int oofTriggerCountThreshold = jsonObject.get("sonhandler.oofTriggerCountThreshold").getAsInt(); - int policyRespTimer = jsonObject.get("sonhandler.policyRespTimer").getAsInt(); - - configuration.setStreamsSubscribes(streamsSubscribes); - configuration.setStreamsPublishes(streamsPublishes); - configuration.setPgPassword(pgPassword); - configuration.setPgPort(pgPort); - configuration.setPollingInterval(pollingInterval); - configuration.setNumSolutions(numSolutions); - configuration.setMinCollision(minCollision); - configuration.setMinConfusion(minConfusion); - configuration.setMaximumClusters(maximumClusters); - configuration.setPgHost(pgHost); - configuration.setPgUsername(pgUsername); - configuration.setSourceId(sourceId); - configuration.setDmaapServers(dmaapServers); - configuration.setCg(cg); - configuration.setCid(cid); - configuration.setBufferTime(bufferTime); - configuration.setConfigDbService(configDbService); - configuration.setCallbackUrl(callbackUrl); - configuration.setPciOptimizer(pciOptimizer); - configuration.setPciAnrOptimizer(pciAnrOptimizer); - configuration.setOofService(oofService); - configuration.setOofEndpoint(oofEndpoint); - configuration.setPollingTimeout(pollingTimeout); - configuration.setBadThreshold(badThreshold); - configuration.setPoorThreshold(poorThreshold); - configuration.setPoorCountThreshold(poorCountThreshold); - configuration.setBadCountThreshold(badCountThreshold); - configuration.setOofTriggerCountTimer(oofTriggerCountTimer); - configuration.setOofTriggerCountThreshold(oofTriggerCountThreshold); - configuration.setPolicyRespTimer(policyRespTimer); - - log.info("configuration from CBS {}", configuration); - } @Override public void run() { @@ -208,4 +120,4 @@ public class ConfigFetchFromCbs implements Runnable { } } -} +}
\ No newline at end of file |