1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2021 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.onap.dcaegen2.services.sonhms.restclient.ConfigInterface;
34 import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 public class Configuration {
41 private static Logger log = LoggerFactory.getLogger(Configuration.class);
43 private static Configuration instance = null;
44 private String pgHost;
46 private String pgUsername;
47 private String pgPassword;
48 private List<String> dmaapServers;
49 private String configDbService;
50 private String cpsServiceUrl;
51 private String getCellDataUrl;
52 private String getNbrListUrl;
53 private String getPciUrl;
54 private String getPnfUrl;
55 private String oofService;
56 private String oofEndpoint;
59 private int pollingInterval;
60 private int pollingTimeout;
61 private int minCollision;
62 private int minConfusion;
63 private String sourceId;
64 private String callbackUrl;
65 private String pciOptimizer;
66 private String pciAnrOptimizer;
67 private int numSolutions;
68 private int bufferTime;
69 private int maximumClusters;
70 private String aafUsername;
71 private String aafPassword;
72 private Map<String, Object> streamsSubscribes;
73 private Map<String, Object> streamsPublishes;
74 private int badThreshold;
75 private int poorThreshold;
76 private int poorCountThreshold;
77 private int badCountThreshold;
78 private int oofTriggerCountTimer;
79 private int oofTriggerCountThreshold;
80 private int policyRespTimer;
81 private int policyNegativeAckThreshold;
82 private long policyFixedPciTimeInterval;
83 private String nfNamingCode;
84 private String ConfigClientType;
85 private String CpsUsername;
86 private String CpsPassword;
88 public String getCpsUsername()
92 public void setCpsUsername(String CpsUsername)
94 this.CpsUsername = CpsUsername;
96 public String getCpsPassword()
100 public void setCpsPassword(String CpsPassword)
102 this.CpsPassword = CpsPassword;
105 public String getConfigClientType()
107 return ConfigClientType;
109 public void setConfigClientType(String ConfigClientType)
111 this.ConfigClientType = ConfigClientType;
114 public int getPoorCountThreshold() {
115 return poorCountThreshold;
118 public void setPoorCountThreshold(int poorCountThreshold) {
119 this.poorCountThreshold = poorCountThreshold;
122 public int getBadCountThreshold() {
123 return badCountThreshold;
126 public void setBadCountThreshold(int badCountThreshold) {
127 this.badCountThreshold = badCountThreshold;
130 public int getOofTriggerCountTimer() {
131 return oofTriggerCountTimer;
134 public void setOofTriggerCountTimer(int oofTriggerCountTimer) {
135 this.oofTriggerCountTimer = oofTriggerCountTimer;
138 public int getOofTriggerCountThreshold() {
139 return oofTriggerCountThreshold;
142 public void setOofTriggerCountThreshold(int oofTriggerCountThreshold) {
143 this.oofTriggerCountThreshold = oofTriggerCountThreshold;
146 public int getPolicyRespTimer() {
147 return policyRespTimer;
150 public void setPolicyRespTimer(int policyRespTimer) {
151 this.policyRespTimer = policyRespTimer;
154 public int getBadThreshold() {
158 public void setBadThreshold(int badThreshold) {
159 this.badThreshold = badThreshold;
162 public int getPoorThreshold() {
163 return poorThreshold;
166 public void setPoorThreshold(int poorThreshold) {
167 this.poorThreshold = poorThreshold;
171 * Check if topic is secure.
173 public boolean isSecured() {
174 return (aafUsername != null);
178 public String getAafUsername() {
182 public void setAafUsername(String aafUsername) {
183 this.aafUsername = aafUsername;
186 public String getAafPassword() {
190 public void setAafPassword(String aafPassword) {
191 this.aafPassword = aafPassword;
194 public Map<String, Object> getStreamsSubscribes() {
195 return streamsSubscribes;
198 public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) {
199 this.streamsSubscribes = streamsSubscribes;
202 public Map<String, Object> getStreamsPublishes() {
203 return streamsPublishes;
206 public void setStreamsPublishes(Map<String, Object> streamsPublishes) {
207 this.streamsPublishes = streamsPublishes;
210 public int getMaximumClusters() {
211 return maximumClusters;
214 public void setMaximumClusters(int maximumClusters) {
215 this.maximumClusters = maximumClusters;
218 protected Configuration() {
223 * Get instance of class.
225 public static Configuration getInstance() {
226 if (instance == null) {
227 instance = new Configuration();
232 public String getCg() {
236 public void setCg(String cg) {
240 public String getCid() {
244 public void setCid(String cid) {
248 public int getPollingInterval() {
249 return pollingInterval;
252 public void setPollingInterval(int pollingInterval) {
253 this.pollingInterval = pollingInterval;
256 public int getPollingTimeout() {
257 return pollingTimeout;
260 public void setPollingTimeout(int pollingTimeout) {
261 this.pollingTimeout = pollingTimeout;
264 public int getMinCollision() {
268 public void setMinCollision(int minCollision) {
269 this.minCollision = minCollision;
272 public int getMinConfusion() {
276 public void setMinConfusion(int minConfusion) {
277 this.minConfusion = minConfusion;
280 public String getOofService() {
284 public void setOofService(String oofService) {
285 this.oofService = oofService;
288 public String getSourceId() {
292 public void setSourceId(String sourceId) {
293 this.sourceId = sourceId;
296 public String getCallbackUrl() {
300 public void setCallbackUrl(String callbackUrl) {
301 this.callbackUrl = callbackUrl;
304 public int getNumSolutions() {
308 public void setNumSolutions(int numSolutions) {
309 this.numSolutions = numSolutions;
312 public int getBufferTime() {
316 public void setBufferTime(int bufferTime) {
317 this.bufferTime = bufferTime;
320 public String getPgHost() {
324 public void setPgHost(String pgHost) {
325 this.pgHost = pgHost;
328 public int getPgPort() {
332 public void setPgPort(int pgPort) {
333 this.pgPort = pgPort;
336 public String getPgUsername() {
340 public void setPgUsername(String pgUsername) {
341 this.pgUsername = pgUsername;
344 public String getPgPassword() {
348 public void setPgPassword(String pgPassword) {
349 this.pgPassword = pgPassword;
352 public List<String> getDmaapServers() {
356 public void setDmaapServers(List<String> dmaapServers) {
357 this.dmaapServers = dmaapServers;
360 public String getConfigDbService() {
361 return configDbService;
364 public void setConfigDbService(String configDbService) {
365 this.configDbService = configDbService;
368 public String getPciOptimizer() {
372 public void setPciOptimizer(String pciOptimizer) {
373 this.pciOptimizer = pciOptimizer;
376 public String getPciAnrOptimizer() {
377 return pciAnrOptimizer;
380 public void setPciAnrOptimizer(String pciAnrOptimizer) {
381 this.pciAnrOptimizer = pciAnrOptimizer;
384 public String getOofEndpoint() {
388 public void setOofEndpoint(String oofEndpoint) {
389 this.oofEndpoint = oofEndpoint;
392 public int getPolicyNegativeAckThreshold() {
393 return policyNegativeAckThreshold;
396 public void setPolicyNegativeAckThreshold(int policyNegativeAckThreshold) {
397 this.policyNegativeAckThreshold = policyNegativeAckThreshold;
400 public long getPolicyFixedPciTimeInterval() {
401 return policyFixedPciTimeInterval;
404 public void setPolicyFixedPciTimeInterval(long policyFixedPciTimeInterval) {
405 this.policyFixedPciTimeInterval = policyFixedPciTimeInterval;
408 public String getNfNamingCode() {
412 public void setNfNamingCode(String nfNamingCode) {
413 this.nfNamingCode = nfNamingCode;
416 public static Logger getLog() {
420 public static void setLog(Logger log) {
421 Configuration.log = log;
424 public String getCpsServiceUrl() {
425 return cpsServiceUrl;
428 public void setCpsServiceUrl(String cpsServiceUrl) {
429 this.cpsServiceUrl = cpsServiceUrl;
432 public String getGetCellDataUrl() {
433 return getCellDataUrl;
436 public void setGetCellDataUrl(String getCellDataUrl) {
437 this.getCellDataUrl = getCellDataUrl;
440 public String getGetNbrListUrl() {
441 return getNbrListUrl;
444 public void setGetNbrListUrl(String getNbrListUrl) {
445 this.getNbrListUrl = getNbrListUrl;
448 public String getGetPciUrl() {
452 public void setGetPciUrl(String getPciUrl) {
453 this.getPciUrl = getPciUrl;
456 public String getGetPnfUrl() {
460 public void setGetPnfUrl(String getPnfUrl) {
461 this.getPnfUrl = getPnfUrl;
464 public static void setInstance(Configuration instance) {
465 Configuration.instance = instance;
468 public ConfigInterface getConfigurationClient()
470 ConfigInterface conf = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType());
471 log.info("ConfigurationClient obj is : " + conf);
476 public String toString() {
477 return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword="
478 + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService
479 + ", cpsServiceUrl=" + cpsServiceUrl + ", CpsUsername=" + CpsUsername + ",CpsPassword=" + CpsPassword + ",ConfigClientType=" + ConfigClientType + ", getCellDataUrl=" + getCellDataUrl + ", getNbrListUrl="
480 + getNbrListUrl + ", getPciUrl=" + getPciUrl + ", getPnfUrl=" + getPnfUrl + ", oofService=" + oofService + ", oofEndpoint=" + oofEndpoint + ", cg=" + cg + ", cid=" + cid
481 + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + ", minCollision="
482 + minCollision + ", minConfusion=" + minConfusion + ", sourceId=" + sourceId + ", callbackUrl="
483 + callbackUrl + ", pciOptimizer=" + pciOptimizer + ", pciAnrOptimizer=" + pciAnrOptimizer
484 + ", numSolutions=" + numSolutions + ", bufferTime=" + bufferTime + ", maximumClusters="
485 + maximumClusters + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword
486 + ", streamsSubscribes=" + streamsSubscribes + ", streamsPublishes=" + streamsPublishes
487 + ", badThreshold=" + badThreshold + ", poorThreshold=" + poorThreshold + ", poorCountThreshold="
488 + poorCountThreshold + ", badCountThreshold=" + badCountThreshold + ", oofTriggerCountTimer="
489 + oofTriggerCountTimer + ", oofTriggerCountThreshold=" + oofTriggerCountThreshold + ", policyRespTimer="
490 + policyRespTimer + ", policyNegativeAckThreshold=" + policyNegativeAckThreshold + ", policyFixedPciTimeInterval="+ policyFixedPciTimeInterval + ", nfNamingCode="+nfNamingCode+"]";
494 * updates application configuration.
496 public void updateConfigurationFromJsonObject(JsonObject jsonObject) {
498 log.info("Updating configuration from CBS");
500 Type mapType = new TypeToken<Map<String, Object>>() {
504 JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes");
505 streamsSubscribes = new Gson().fromJson(subscribes, mapType);
507 JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes");
508 streamsPublishes = new Gson().fromJson(publishes, mapType);
510 CpsUsername = jsonObject.get("cps.username").getAsString();
511 CpsPassword = jsonObject.get("cps.password").getAsString();
512 pgPort = jsonObject.get("postgres.port").getAsInt();
513 pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt();
514 pgPassword = jsonObject.get("postgres.password").getAsString();
515 numSolutions = jsonObject.get("sonhandler.numSolutions").getAsInt();
516 minConfusion = jsonObject.get("sonhandler.minConfusion").getAsInt();
517 maximumClusters = jsonObject.get("sonhandler.maximumClusters").getAsInt();
518 minCollision = jsonObject.get("sonhandler.minCollision").getAsInt();
519 sourceId = jsonObject.get("sonhandler.sourceId").getAsString();
520 pgUsername = jsonObject.get("postgres.username").getAsString();
521 pgHost = jsonObject.get("postgres.host").getAsString();
523 JsonArray servers = jsonObject.getAsJsonArray("sonhandler.dmaap.server");
524 Type listType = new TypeToken<List<String>>() {
526 dmaapServers = new Gson().fromJson(servers, listType);
528 cg = jsonObject.get("sonhandler.cg").getAsString();
529 bufferTime = jsonObject.get("sonhandler.bufferTime").getAsInt();
530 cid = jsonObject.get("sonhandler.cid").getAsString();
531 configDbService = jsonObject.get("sonhandler.configDb.service").getAsString();
532 String namespace = jsonObject.get("sonhandler.namespace").getAsString();
533 callbackUrl = "http://" + System.getenv("HOSTNAME") + "." + namespace + ":8080/callbackUrl";
535 pciOptimizer = jsonObject.get("sonhandler.pciOptimizer").getAsString();
536 pciAnrOptimizer = jsonObject.get("sonhandler.pciAnrOptimizer").getAsString();
538 oofService = jsonObject.get("sonhandler.oof.service").getAsString();
539 oofEndpoint = jsonObject.get("sonhandler.oof.endpoint").getAsString();
540 pollingTimeout = jsonObject.get("sonhandler.pollingTimeout").getAsInt();
542 badThreshold = jsonObject.get("sonhandler.badThreshold").getAsInt();
543 poorThreshold = jsonObject.get("sonhandler.poorThreshold").getAsInt();
545 poorCountThreshold = jsonObject.get("sonhandler.poorCountThreshold").getAsInt();
546 badCountThreshold = jsonObject.get("sonhandler.badCountThreshold").getAsInt();
547 oofTriggerCountTimer = jsonObject.get("sonhandler.oofTriggerCountTimer").getAsInt();
548 oofTriggerCountThreshold = jsonObject.get("sonhandler.oofTriggerCountThreshold").getAsInt();
549 policyRespTimer = jsonObject.get("sonhandler.policyRespTimer").getAsInt();
550 policyNegativeAckThreshold = jsonObject.get("sonhandler.policyNegativeAckThreshold").getAsInt();
551 policyFixedPciTimeInterval = jsonObject.get("sonhandler.policyFixedPciTimeInterval").getAsLong();
552 nfNamingCode = jsonObject.get("sonhandler.nfNamingCode").getAsString();
553 cpsServiceUrl = jsonObject.get("cps.service.url").getAsString();
554 getCellDataUrl = jsonObject.get("cps.get.celldata").getAsString();
555 getPnfUrl = jsonObject.get("cps.get.pnf.url").getAsString();
556 getPciUrl = jsonObject.get("cps.get.pci.url").getAsString();
557 ConfigClientType = jsonObject.get("sonhandler.clientType").getAsString();
559 log.info("configuration from CBS {}", this);