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;
74 private int policyNegativeAckThreshold;
75 private long policyFixedPciTimeInterval;
77 public int getPoorCountThreshold() {
78 return poorCountThreshold;
81 public void setPoorCountThreshold(int poorCountThreshold) {
82 this.poorCountThreshold = poorCountThreshold;
85 public int getBadCountThreshold() {
86 return badCountThreshold;
89 public void setBadCountThreshold(int badCountThreshold) {
90 this.badCountThreshold = badCountThreshold;
93 public int getOofTriggerCountTimer() {
94 return oofTriggerCountTimer;
97 public void setOofTriggerCountTimer(int oofTriggerCountTimer) {
98 this.oofTriggerCountTimer = oofTriggerCountTimer;
101 public int getOofTriggerCountThreshold() {
102 return oofTriggerCountThreshold;
105 public void setOofTriggerCountThreshold(int oofTriggerCountThreshold) {
106 this.oofTriggerCountThreshold = oofTriggerCountThreshold;
109 public int getPolicyRespTimer() {
110 return policyRespTimer;
113 public void setPolicyRespTimer(int policyRespTimer) {
114 this.policyRespTimer = policyRespTimer;
117 public int getBadThreshold() {
121 public void setBadThreshold(int badThreshold) {
122 this.badThreshold = badThreshold;
125 public int getPoorThreshold() {
126 return poorThreshold;
129 public void setPoorThreshold(int poorThreshold) {
130 this.poorThreshold = poorThreshold;
134 * Check if topic is secure.
136 public boolean isSecured() {
137 return (aafUsername != null);
141 public String getAafUsername() {
145 public void setAafUsername(String aafUsername) {
146 this.aafUsername = aafUsername;
149 public String getAafPassword() {
153 public void setAafPassword(String aafPassword) {
154 this.aafPassword = aafPassword;
157 public Map<String, Object> getStreamsSubscribes() {
158 return streamsSubscribes;
161 public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) {
162 this.streamsSubscribes = streamsSubscribes;
165 public Map<String, Object> getStreamsPublishes() {
166 return streamsPublishes;
169 public void setStreamsPublishes(Map<String, Object> streamsPublishes) {
170 this.streamsPublishes = streamsPublishes;
173 public int getMaximumClusters() {
174 return maximumClusters;
177 public void setMaximumClusters(int maximumClusters) {
178 this.maximumClusters = maximumClusters;
181 protected Configuration() {
186 * Get instance of class.
188 public static Configuration getInstance() {
189 if (instance == null) {
190 instance = new Configuration();
195 public String getCg() {
199 public void setCg(String cg) {
203 public String getCid() {
207 public void setCid(String cid) {
211 public int getPollingInterval() {
212 return pollingInterval;
215 public void setPollingInterval(int pollingInterval) {
216 this.pollingInterval = pollingInterval;
219 public int getPollingTimeout() {
220 return pollingTimeout;
223 public void setPollingTimeout(int pollingTimeout) {
224 this.pollingTimeout = pollingTimeout;
227 public int getMinCollision() {
231 public void setMinCollision(int minCollision) {
232 this.minCollision = minCollision;
235 public int getMinConfusion() {
239 public void setMinConfusion(int minConfusion) {
240 this.minConfusion = minConfusion;
243 public String getOofService() {
247 public void setOofService(String oofService) {
248 this.oofService = oofService;
251 public String getSourceId() {
255 public void setSourceId(String sourceId) {
256 this.sourceId = sourceId;
259 public String getCallbackUrl() {
263 public void setCallbackUrl(String callbackUrl) {
264 this.callbackUrl = callbackUrl;
267 public int getNumSolutions() {
271 public void setNumSolutions(int numSolutions) {
272 this.numSolutions = numSolutions;
275 public int getBufferTime() {
279 public void setBufferTime(int bufferTime) {
280 this.bufferTime = bufferTime;
283 public String getPgHost() {
287 public void setPgHost(String pgHost) {
288 this.pgHost = pgHost;
291 public int getPgPort() {
295 public void setPgPort(int pgPort) {
296 this.pgPort = pgPort;
299 public String getPgUsername() {
303 public void setPgUsername(String pgUsername) {
304 this.pgUsername = pgUsername;
307 public String getPgPassword() {
311 public void setPgPassword(String pgPassword) {
312 this.pgPassword = pgPassword;
315 public List<String> getDmaapServers() {
319 public void setDmaapServers(List<String> dmaapServers) {
320 this.dmaapServers = dmaapServers;
323 public String getConfigDbService() {
324 return configDbService;
327 public void setConfigDbService(String configDbService) {
328 this.configDbService = configDbService;
331 public String getPciOptimizer() {
335 public void setPciOptimizer(String pciOptimizer) {
336 this.pciOptimizer = pciOptimizer;
339 public String getPciAnrOptimizer() {
340 return pciAnrOptimizer;
343 public void setPciAnrOptimizer(String pciAnrOptimizer) {
344 this.pciAnrOptimizer = pciAnrOptimizer;
347 public String getOofEndpoint() {
351 public void setOofEndpoint(String oofEndpoint) {
352 this.oofEndpoint = oofEndpoint;
355 public int getPolicyNegativeAckThreshold() {
356 return policyNegativeAckThreshold;
359 public void setPolicyNegativeAckThreshold(int policyNegativeAckThreshold) {
360 this.policyNegativeAckThreshold = policyNegativeAckThreshold;
363 public long getPolicyFixedPciTimeInterval() {
364 return policyFixedPciTimeInterval;
367 public void setPolicyFixedPciTimeInterval(long policyFixedPciTimeInterval) {
368 this.policyFixedPciTimeInterval = policyFixedPciTimeInterval;
372 public String toString() {
373 return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword="
374 + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService
375 + ", oofService=" + oofService + ", oofEndpoint=" + oofEndpoint + ", cg=" + cg + ", cid=" + cid
376 + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + ", minCollision="
377 + minCollision + ", minConfusion=" + minConfusion + ", sourceId=" + sourceId + ", callbackUrl="
378 + callbackUrl + ", pciOptimizer=" + pciOptimizer + ", pciAnrOptimizer=" + pciAnrOptimizer
379 + ", numSolutions=" + numSolutions + ", bufferTime=" + bufferTime + ", maximumClusters="
380 + maximumClusters + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword
381 + ", streamsSubscribes=" + streamsSubscribes + ", streamsPublishes=" + streamsPublishes
382 + ", badThreshold=" + badThreshold + ", poorThreshold=" + poorThreshold + ", poorCountThreshold="
383 + poorCountThreshold + ", badCountThreshold=" + badCountThreshold + ", oofTriggerCountTimer="
384 + oofTriggerCountTimer + ", oofTriggerCountThreshold=" + oofTriggerCountThreshold + ", policyRespTimer="
385 + policyRespTimer + ", policyNegativeAckThreshold=" + policyNegativeAckThreshold + ", policyFixedPciTimeInterval="+ policyFixedPciTimeInterval + "]";
389 * updates application configuration.
391 public void updateConfigurationFromJsonObject(JsonObject jsonObject) {
393 log.info("Updating configuration from CBS");
395 Type mapType = new TypeToken<Map<String, Object>>() {
398 JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes");
399 streamsSubscribes = new Gson().fromJson(subscribes, mapType);
401 JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes");
402 streamsPublishes = new Gson().fromJson(publishes, mapType);
404 pgPort = jsonObject.get("postgres.port").getAsInt();
405 pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt();
406 pgPassword = jsonObject.get("postgres.password").getAsString();
407 numSolutions = jsonObject.get("sonhandler.numSolutions").getAsInt();
408 minConfusion = jsonObject.get("sonhandler.minConfusion").getAsInt();
409 maximumClusters = jsonObject.get("sonhandler.maximumClusters").getAsInt();
410 minCollision = jsonObject.get("sonhandler.minCollision").getAsInt();
411 sourceId = jsonObject.get("sonhandler.sourceId").getAsString();
412 pgUsername = jsonObject.get("postgres.username").getAsString();
413 pgHost = jsonObject.get("postgres.host").getAsString();
415 JsonArray servers = jsonObject.getAsJsonArray("sonhandler.dmaap.server");
416 Type listType = new TypeToken<List<String>>() {
418 dmaapServers = new Gson().fromJson(servers, listType);
420 cg = jsonObject.get("sonhandler.cg").getAsString();
421 bufferTime = jsonObject.get("sonhandler.bufferTime").getAsInt();
422 cid = jsonObject.get("sonhandler.cid").getAsString();
423 configDbService = jsonObject.get("sonhandler.configDb.service").getAsString();
424 String namespace = jsonObject.get("sonhandler.namespace").getAsString();
425 callbackUrl = "http://" + System.getenv("HOSTNAME") + "." + namespace + ":8080/callbackUrl";
427 pciOptimizer = jsonObject.get("sonhandler.pciOptimizer").getAsString();
428 pciAnrOptimizer = jsonObject.get("sonhandler.pciAnrOptimizer").getAsString();
430 oofService = jsonObject.get("sonhandler.oof.service").getAsString();
431 oofEndpoint = jsonObject.get("sonhandler.oof.endpoint").getAsString();
432 pollingTimeout = jsonObject.get("sonhandler.pollingTimeout").getAsInt();
434 badThreshold = jsonObject.get("sonhandler.badThreshold").getAsInt();
435 poorThreshold = jsonObject.get("sonhandler.poorThreshold").getAsInt();
437 poorCountThreshold = jsonObject.get("sonhandler.poorCountThreshold").getAsInt();
438 badCountThreshold = jsonObject.get("sonhandler.badCountThreshold").getAsInt();
439 oofTriggerCountTimer = jsonObject.get("sonhandler.oofTriggerCountTimer").getAsInt();
440 oofTriggerCountThreshold = jsonObject.get("sonhandler.oofTriggerCountThreshold").getAsInt();
441 policyRespTimer = jsonObject.get("sonhandler.policyRespTimer").getAsInt();
442 policyNegativeAckThreshold = jsonObject.get("sonhandler.policyNegativeAckThreshold").getAsInt();
443 policyFixedPciTimeInterval = jsonObject.get("sonhandler.policyFixedPciTimeInterval").getAsLong();
445 log.info("configuration from CBS {}", this);