1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 Wipro Limited.
6 * ==============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 *******************************************************************************/
22 package org.onap.dcaegen2.services.sonhms;
24 import com.google.gson.Gson;
25 import com.google.gson.JsonArray;
26 import com.google.gson.JsonObject;
27 import com.google.gson.reflect.TypeToken;
29 import java.lang.reflect.Type;
30 import java.util.List;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 public class Configuration {
39 private static Logger log = LoggerFactory.getLogger(Configuration.class);
41 private static Configuration instance = null;
42 private String pgHost;
44 private String pgUsername;
45 private String pgPassword;
46 private List<String> dmaapServers;
47 private String configDbService;
48 private String oofService;
49 private String oofEndpoint;
52 private int pollingInterval;
53 private int pollingTimeout;
54 private int minCollision;
55 private int minConfusion;
56 private String sourceId;
57 private String callbackUrl;
58 private String pciOptimizer;
59 private String pciAnrOptimizer;
60 private int numSolutions;
61 private int bufferTime;
62 private int maximumClusters;
63 private String aafUsername;
64 private String aafPassword;
65 private Map<String, Object> streamsSubscribes;
66 private Map<String, Object> streamsPublishes;
67 private int badThreshold;
68 private int poorThreshold;
69 private int poorCountThreshold;
70 private int badCountThreshold;
71 private int oofTriggerCountTimer;
72 private int oofTriggerCountThreshold;
73 private int policyRespTimer;
76 public int getPoorCountThreshold() {
77 return poorCountThreshold;
80 public void setPoorCountThreshold(int poorCountThreshold) {
81 this.poorCountThreshold = poorCountThreshold;
84 public int getBadCountThreshold() {
85 return badCountThreshold;
88 public void setBadCountThreshold(int badCountThreshold) {
89 this.badCountThreshold = badCountThreshold;
92 public int getOofTriggerCountTimer() {
93 return oofTriggerCountTimer;
96 public void setOofTriggerCountTimer(int oofTriggerCountTimer) {
97 this.oofTriggerCountTimer = oofTriggerCountTimer;
100 public int getOofTriggerCountThreshold() {
101 return oofTriggerCountThreshold;
104 public void setOofTriggerCountThreshold(int oofTriggerCountThreshold) {
105 this.oofTriggerCountThreshold = oofTriggerCountThreshold;
108 public int getPolicyRespTimer() {
109 return policyRespTimer;
112 public void setPolicyRespTimer(int policyRespTimer) {
113 this.policyRespTimer = policyRespTimer;
116 public int getBadThreshold() {
120 public void setBadThreshold(int badThreshold) {
121 this.badThreshold = badThreshold;
124 public int getPoorThreshold() {
125 return poorThreshold;
128 public void setPoorThreshold(int poorThreshold) {
129 this.poorThreshold = poorThreshold;
133 * Check if topic is secure.
135 public boolean isSecured() {
136 return (aafUsername != null);
140 public String getAafUsername() {
144 public void setAafUsername(String aafUsername) {
145 this.aafUsername = aafUsername;
148 public String getAafPassword() {
152 public void setAafPassword(String aafPassword) {
153 this.aafPassword = aafPassword;
156 public Map<String, Object> getStreamsSubscribes() {
157 return streamsSubscribes;
160 public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) {
161 this.streamsSubscribes = streamsSubscribes;
164 public Map<String, Object> getStreamsPublishes() {
165 return streamsPublishes;
168 public void setStreamsPublishes(Map<String, Object> streamsPublishes) {
169 this.streamsPublishes = streamsPublishes;
172 public int getMaximumClusters() {
173 return maximumClusters;
176 public void setMaximumClusters(int maximumClusters) {
177 this.maximumClusters = maximumClusters;
180 protected Configuration() {
185 * Get instance of class.
187 public static Configuration getInstance() {
188 if (instance == null) {
189 instance = new Configuration();
194 public String getCg() {
198 public void setCg(String cg) {
202 public String getCid() {
206 public void setCid(String cid) {
210 public int getPollingInterval() {
211 return pollingInterval;
214 public void setPollingInterval(int pollingInterval) {
215 this.pollingInterval = pollingInterval;
218 public int getPollingTimeout() {
219 return pollingTimeout;
222 public void setPollingTimeout(int pollingTimeout) {
223 this.pollingTimeout = pollingTimeout;
226 public int getMinCollision() {
230 public void setMinCollision(int minCollision) {
231 this.minCollision = minCollision;
234 public int getMinConfusion() {
238 public void setMinConfusion(int minConfusion) {
239 this.minConfusion = minConfusion;
242 public String getOofService() {
246 public void setOofService(String oofService) {
247 this.oofService = oofService;
250 public String getSourceId() {
254 public void setSourceId(String sourceId) {
255 this.sourceId = sourceId;
258 public String getCallbackUrl() {
262 public void setCallbackUrl(String callbackUrl) {
263 this.callbackUrl = callbackUrl;
266 public int getNumSolutions() {
270 public void setNumSolutions(int numSolutions) {
271 this.numSolutions = numSolutions;
274 public int getBufferTime() {
278 public void setBufferTime(int bufferTime) {
279 this.bufferTime = bufferTime;
282 public String getPgHost() {
286 public void setPgHost(String pgHost) {
287 this.pgHost = pgHost;
290 public int getPgPort() {
294 public void setPgPort(int pgPort) {
295 this.pgPort = pgPort;
298 public String getPgUsername() {
302 public void setPgUsername(String pgUsername) {
303 this.pgUsername = pgUsername;
306 public String getPgPassword() {
310 public void setPgPassword(String pgPassword) {
311 this.pgPassword = pgPassword;
314 public List<String> getDmaapServers() {
318 public void setDmaapServers(List<String> dmaapServers) {
319 this.dmaapServers = dmaapServers;
322 public String getConfigDbService() {
323 return configDbService;
326 public void setConfigDbService(String configDbService) {
327 this.configDbService = configDbService;
330 public String getPciOptimizer() {
334 public void setPciOptimizer(String pciOptimizer) {
335 this.pciOptimizer = pciOptimizer;
338 public String getPciAnrOptimizer() {
339 return pciAnrOptimizer;
342 public void setPciAnrOptimizer(String pciAnrOptimizer) {
343 this.pciAnrOptimizer = pciAnrOptimizer;
346 public String getOofEndpoint() {
350 public void setOofEndpoint(String oofEndpoint) {
351 this.oofEndpoint = oofEndpoint;
355 public String toString() {
356 return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword="
357 + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService
358 + ", oofService=" + oofService + ", oofEndpoint=" + oofEndpoint + ", cg=" + cg + ", cid=" + cid
359 + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + ", minCollision="
360 + minCollision + ", minConfusion=" + minConfusion + ", sourceId=" + sourceId + ", callbackUrl="
361 + callbackUrl + ", pciOptimizer=" + pciOptimizer + ", pciAnrOptimizer=" + pciAnrOptimizer
362 + ", numSolutions=" + numSolutions + ", bufferTime=" + bufferTime + ", maximumClusters="
363 + maximumClusters + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword
364 + ", streamsSubscribes=" + streamsSubscribes + ", streamsPublishes=" + streamsPublishes
365 + ", badThreshold=" + badThreshold + ", poorThreshold=" + poorThreshold + ", poorCountThreshold="
366 + poorCountThreshold + ", badCountThreshold=" + badCountThreshold + ", oofTriggerCountTimer="
367 + oofTriggerCountTimer + ", oofTriggerCountThreshold=" + oofTriggerCountThreshold + ", policyRespTimer="
368 + policyRespTimer + "]";
372 * updates application configuration.
374 public void updateConfigurationFromJsonObject(JsonObject jsonObject) {
376 log.info("Updating configuration from CBS");
378 Type mapType = new TypeToken<Map<String, Object>>() {
381 JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes");
382 streamsSubscribes = new Gson().fromJson(subscribes, mapType);
384 JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes");
385 streamsPublishes = new Gson().fromJson(publishes, mapType);
387 pgPort = jsonObject.get("postgres.port").getAsInt();
388 pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt();
389 pgPassword = jsonObject.get("postgres.password").getAsString();
390 numSolutions = jsonObject.get("sonhandler.numSolutions").getAsInt();
391 minConfusion = jsonObject.get("sonhandler.minConfusion").getAsInt();
392 maximumClusters = jsonObject.get("sonhandler.maximumClusters").getAsInt();
393 minCollision = jsonObject.get("sonhandler.minCollision").getAsInt();
394 sourceId = jsonObject.get("sonhandler.sourceId").getAsString();
395 pgUsername = jsonObject.get("postgres.username").getAsString();
396 pgHost = jsonObject.get("postgres.host").getAsString();
398 JsonArray servers = jsonObject.getAsJsonArray("sonhandler.dmaap.server");
399 Type listType = new TypeToken<List<String>>() {
401 dmaapServers = new Gson().fromJson(servers, listType);
403 cg = jsonObject.get("sonhandler.cg").getAsString();
404 bufferTime = jsonObject.get("sonhandler.bufferTime").getAsInt();
405 cid = jsonObject.get("sonhandler.cid").getAsString();
406 configDbService = jsonObject.get("sonhandler.configDb.service").getAsString();
407 String namespace = jsonObject.get("sonhandler.namespace").getAsString();
408 callbackUrl = "http://" + System.getenv("HOSTNAME") + "." + namespace + ":8080/callbackUrl";
410 pciOptimizer = jsonObject.get("sonhandler.pciOptimizer").getAsString();
411 pciAnrOptimizer = jsonObject.get("sonhandler.pciAnrOptimizer").getAsString();
413 oofService = jsonObject.get("sonhandler.oof.service").getAsString();
414 oofEndpoint = jsonObject.get("sonhandler.oof.endpoint").getAsString();
415 pollingTimeout = jsonObject.get("sonhandler.pollingTimeout").getAsInt();
417 badThreshold = jsonObject.get("sonhandler.badThreshold").getAsInt();
418 poorThreshold = jsonObject.get("sonhandler.poorThreshold").getAsInt();
420 poorCountThreshold = jsonObject.get("sonhandler.poorCountThreshold").getAsInt();
421 badCountThreshold = jsonObject.get("sonhandler.badCountThreshold").getAsInt();
422 oofTriggerCountTimer = jsonObject.get("sonhandler.oofTriggerCountTimer").getAsInt();
423 oofTriggerCountThreshold = jsonObject.get("sonhandler.oofTriggerCountThreshold").getAsInt();
424 policyRespTimer = jsonObject.get("sonhandler.policyRespTimer").getAsInt();
427 log.info("configuration from CBS {}", this);