1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2022 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 getRicIdUrl;
56 private String nearRtricUrl;
57 private String oofService;
58 private String oofEndpoint;
61 private int pollingInterval;
62 private int pollingTimeout;
63 private int minCollision;
64 private int minConfusion;
65 private String sourceId;
66 private String callbackUrl;
67 private String pciOptimizer;
68 private String pciAnrOptimizer;
69 private int numSolutions;
70 private int bufferTime;
71 private int maximumClusters;
72 private String aafUsername;
73 private String aafPassword;
74 private Map<String, Object> streamsSubscribes;
75 private Map<String, Object> streamsPublishes;
76 private int badThreshold;
77 private int poorThreshold;
78 private int poorCountThreshold;
79 private int badCountThreshold;
80 private int oofTriggerCountTimer;
81 private int oofTriggerCountThreshold;
82 private int policyRespTimer;
83 private int policyNegativeAckThreshold;
84 private long policyFixedPciTimeInterval;
85 private String nfNamingCode;
86 private String ConfigClientType;
87 private String CpsUsername;
88 private String CpsPassword;
90 public String getCpsUsername()
94 public void setCpsUsername(String CpsUsername)
96 this.CpsUsername = CpsUsername;
98 public String getCpsPassword()
102 public void setCpsPassword(String CpsPassword)
104 this.CpsPassword = CpsPassword;
107 public String getConfigClientType()
109 return ConfigClientType;
111 public void setConfigClientType(String ConfigClientType)
113 this.ConfigClientType = ConfigClientType;
116 public int getPoorCountThreshold() {
117 return poorCountThreshold;
120 public void setPoorCountThreshold(int poorCountThreshold) {
121 this.poorCountThreshold = poorCountThreshold;
124 public int getBadCountThreshold() {
125 return badCountThreshold;
128 public void setBadCountThreshold(int badCountThreshold) {
129 this.badCountThreshold = badCountThreshold;
132 public int getOofTriggerCountTimer() {
133 return oofTriggerCountTimer;
136 public void setOofTriggerCountTimer(int oofTriggerCountTimer) {
137 this.oofTriggerCountTimer = oofTriggerCountTimer;
140 public int getOofTriggerCountThreshold() {
141 return oofTriggerCountThreshold;
144 public void setOofTriggerCountThreshold(int oofTriggerCountThreshold) {
145 this.oofTriggerCountThreshold = oofTriggerCountThreshold;
148 public int getPolicyRespTimer() {
149 return policyRespTimer;
152 public void setPolicyRespTimer(int policyRespTimer) {
153 this.policyRespTimer = policyRespTimer;
156 public int getBadThreshold() {
160 public void setBadThreshold(int badThreshold) {
161 this.badThreshold = badThreshold;
164 public int getPoorThreshold() {
165 return poorThreshold;
168 public void setPoorThreshold(int poorThreshold) {
169 this.poorThreshold = poorThreshold;
173 * Check if topic is secure.
175 public boolean isSecured() {
176 return (aafUsername != null);
180 public String getAafUsername() {
184 public void setAafUsername(String aafUsername) {
185 this.aafUsername = aafUsername;
188 public String getAafPassword() {
192 public void setAafPassword(String aafPassword) {
193 this.aafPassword = aafPassword;
196 public Map<String, Object> getStreamsSubscribes() {
197 return streamsSubscribes;
200 public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) {
201 this.streamsSubscribes = streamsSubscribes;
204 public Map<String, Object> getStreamsPublishes() {
205 return streamsPublishes;
208 public void setStreamsPublishes(Map<String, Object> streamsPublishes) {
209 this.streamsPublishes = streamsPublishes;
212 public int getMaximumClusters() {
213 return maximumClusters;
216 public void setMaximumClusters(int maximumClusters) {
217 this.maximumClusters = maximumClusters;
220 protected Configuration() {
225 * Get instance of class.
227 public static Configuration getInstance() {
228 if (instance == null) {
229 instance = new Configuration();
234 public String getCg() {
238 public void setCg(String cg) {
242 public String getCid() {
246 public void setCid(String cid) {
250 public int getPollingInterval() {
251 return pollingInterval;
254 public void setPollingInterval(int pollingInterval) {
255 this.pollingInterval = pollingInterval;
258 public int getPollingTimeout() {
259 return pollingTimeout;
262 public void setPollingTimeout(int pollingTimeout) {
263 this.pollingTimeout = pollingTimeout;
266 public int getMinCollision() {
270 public void setMinCollision(int minCollision) {
271 this.minCollision = minCollision;
274 public int getMinConfusion() {
278 public void setMinConfusion(int minConfusion) {
279 this.minConfusion = minConfusion;
282 public String getOofService() {
286 public void setOofService(String oofService) {
287 this.oofService = oofService;
290 public String getSourceId() {
294 public void setSourceId(String sourceId) {
295 this.sourceId = sourceId;
298 public String getCallbackUrl() {
302 public void setCallbackUrl(String callbackUrl) {
303 this.callbackUrl = callbackUrl;
306 public int getNumSolutions() {
310 public void setNumSolutions(int numSolutions) {
311 this.numSolutions = numSolutions;
314 public int getBufferTime() {
318 public void setBufferTime(int bufferTime) {
319 this.bufferTime = bufferTime;
322 public String getPgHost() {
326 public void setPgHost(String pgHost) {
327 this.pgHost = pgHost;
330 public int getPgPort() {
334 public void setPgPort(int pgPort) {
335 this.pgPort = pgPort;
338 public String getPgUsername() {
342 public void setPgUsername(String pgUsername) {
343 this.pgUsername = pgUsername;
346 public String getPgPassword() {
350 public void setPgPassword(String pgPassword) {
351 this.pgPassword = pgPassword;
354 public List<String> getDmaapServers() {
358 public void setDmaapServers(List<String> dmaapServers) {
359 this.dmaapServers = dmaapServers;
362 public String getConfigDbService() {
363 return configDbService;
366 public void setConfigDbService(String configDbService) {
367 this.configDbService = configDbService;
370 public String getPciOptimizer() {
374 public void setPciOptimizer(String pciOptimizer) {
375 this.pciOptimizer = pciOptimizer;
378 public String getPciAnrOptimizer() {
379 return pciAnrOptimizer;
382 public void setPciAnrOptimizer(String pciAnrOptimizer) {
383 this.pciAnrOptimizer = pciAnrOptimizer;
386 public String getOofEndpoint() {
390 public void setOofEndpoint(String oofEndpoint) {
391 this.oofEndpoint = oofEndpoint;
394 public int getPolicyNegativeAckThreshold() {
395 return policyNegativeAckThreshold;
398 public void setPolicyNegativeAckThreshold(int policyNegativeAckThreshold) {
399 this.policyNegativeAckThreshold = policyNegativeAckThreshold;
402 public long getPolicyFixedPciTimeInterval() {
403 return policyFixedPciTimeInterval;
406 public void setPolicyFixedPciTimeInterval(long policyFixedPciTimeInterval) {
407 this.policyFixedPciTimeInterval = policyFixedPciTimeInterval;
410 public String getNfNamingCode() {
414 public void setNfNamingCode(String nfNamingCode) {
415 this.nfNamingCode = nfNamingCode;
418 public static Logger getLog() {
422 public static void setLog(Logger log) {
423 Configuration.log = log;
426 public String getCpsServiceUrl() {
427 return cpsServiceUrl;
430 public void setCpsServiceUrl(String cpsServiceUrl) {
431 this.cpsServiceUrl = cpsServiceUrl;
434 public String getGetCellDataUrl() {
435 return getCellDataUrl;
438 public void setGetCellDataUrl(String getCellDataUrl) {
439 this.getCellDataUrl = getCellDataUrl;
442 public String getGetNbrListUrl() {
443 return getNbrListUrl;
446 public void setGetNbrListUrl(String getNbrListUrl) {
447 this.getNbrListUrl = getNbrListUrl;
450 public String getGetPciUrl() {
454 public void setGetPciUrl(String getPciUrl) {
455 this.getPciUrl = getPciUrl;
458 public String getGetPnfUrl() {
462 public void setGetPnfUrl(String getPnfUrl) {
463 this.getPnfUrl = getPnfUrl;
466 public void setGetRicIdUrl(String getRicIdUrl) {
467 this.getRicIdUrl = getRicIdUrl;
470 public String getGetRicIdUrl() {
474 public void setNearRtricUrl(String nearRtricUrl) {
475 this.nearRtricUrl = nearRtricUrl;
478 public String getNearRtricUrl() {
482 public static void setInstance(Configuration instance) {
483 Configuration.instance = instance;
487 public String toString() {
488 return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword="
489 + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService
490 + ", cpsServiceUrl=" + cpsServiceUrl + ", CpsUsername=" + CpsUsername + ",CpsPassword=" + CpsPassword + ",ConfigClientType=" + ConfigClientType + ", getCellDataUrl=" + getCellDataUrl + ", getNbrListUrl="
491 + getNbrListUrl + ", getPciUrl=" + getPciUrl + ", getPnfUrl=" + getPnfUrl + ", getRicIdUrl=" + getRicIdUrl + ", nearRtricUrl=" + nearRtricUrl + ",oofService=" + oofService + ", oofEndpoint=" + oofEndpoint + ", cg=" + cg + ", cid=" + cid
492 + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + ", minCollision="
493 + minCollision + ", minConfusion=" + minConfusion + ", sourceId=" + sourceId + ", callbackUrl="
494 + callbackUrl + ", pciOptimizer=" + pciOptimizer + ", pciAnrOptimizer=" + pciAnrOptimizer
495 + ", numSolutions=" + numSolutions + ", bufferTime=" + bufferTime + ", maximumClusters="
496 + maximumClusters + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword
497 + ", streamsSubscribes=" + streamsSubscribes + ", streamsPublishes=" + streamsPublishes
498 + ", badThreshold=" + badThreshold + ", poorThreshold=" + poorThreshold + ", poorCountThreshold="
499 + poorCountThreshold + ", badCountThreshold=" + badCountThreshold + ", oofTriggerCountTimer="
500 + oofTriggerCountTimer + ", oofTriggerCountThreshold=" + oofTriggerCountThreshold + ", policyRespTimer="
501 + policyRespTimer + ", policyNegativeAckThreshold=" + policyNegativeAckThreshold + ", policyFixedPciTimeInterval="+ policyFixedPciTimeInterval + ", nfNamingCode="+nfNamingCode+"]";
505 * updates application configuration.
507 public void updateConfigurationFromJsonObject(JsonObject jsonObject) {
509 log.info("Updating configuration from CBS");
511 Type mapType = new TypeToken<Map<String, Object>>() {
515 JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes");
516 streamsSubscribes = new Gson().fromJson(subscribes, mapType);
518 JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes");
519 streamsPublishes = new Gson().fromJson(publishes, mapType);
521 CpsUsername = jsonObject.get("cps.username").getAsString();
522 CpsPassword = jsonObject.get("cps.password").getAsString();
523 pgPort = jsonObject.get("postgres.port").getAsInt();
524 pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt();
525 pgPassword = jsonObject.get("postgres.password").getAsString();
526 numSolutions = jsonObject.get("sonhandler.numSolutions").getAsInt();
527 minConfusion = jsonObject.get("sonhandler.minConfusion").getAsInt();
528 maximumClusters = jsonObject.get("sonhandler.maximumClusters").getAsInt();
529 minCollision = jsonObject.get("sonhandler.minCollision").getAsInt();
530 sourceId = jsonObject.get("sonhandler.sourceId").getAsString();
531 pgUsername = jsonObject.get("postgres.username").getAsString();
532 pgHost = jsonObject.get("postgres.host").getAsString();
534 JsonArray servers = jsonObject.getAsJsonArray("sonhandler.dmaap.server");
535 Type listType = new TypeToken<List<String>>() {
537 dmaapServers = new Gson().fromJson(servers, listType);
539 cg = jsonObject.get("sonhandler.cg").getAsString();
540 bufferTime = jsonObject.get("sonhandler.bufferTime").getAsInt();
541 cid = jsonObject.get("sonhandler.cid").getAsString();
542 configDbService = jsonObject.get("sonhandler.configDb.service").getAsString();
543 String namespace = jsonObject.get("sonhandler.namespace").getAsString();
544 callbackUrl = "http://" + System.getenv("HOSTNAME") + "." + namespace + ":8080/callbackUrl";
546 pciOptimizer = jsonObject.get("sonhandler.pciOptimizer").getAsString();
547 pciAnrOptimizer = jsonObject.get("sonhandler.pciAnrOptimizer").getAsString();
549 oofService = jsonObject.get("sonhandler.oof.service").getAsString();
550 oofEndpoint = jsonObject.get("sonhandler.oof.endpoint").getAsString();
551 pollingTimeout = jsonObject.get("sonhandler.pollingTimeout").getAsInt();
553 badThreshold = jsonObject.get("sonhandler.badThreshold").getAsInt();
554 poorThreshold = jsonObject.get("sonhandler.poorThreshold").getAsInt();
556 poorCountThreshold = jsonObject.get("sonhandler.poorCountThreshold").getAsInt();
557 badCountThreshold = jsonObject.get("sonhandler.badCountThreshold").getAsInt();
558 oofTriggerCountTimer = jsonObject.get("sonhandler.oofTriggerCountTimer").getAsInt();
559 oofTriggerCountThreshold = jsonObject.get("sonhandler.oofTriggerCountThreshold").getAsInt();
560 policyRespTimer = jsonObject.get("sonhandler.policyRespTimer").getAsInt();
561 policyNegativeAckThreshold = jsonObject.get("sonhandler.policyNegativeAckThreshold").getAsInt();
562 policyFixedPciTimeInterval = jsonObject.get("sonhandler.policyFixedPciTimeInterval").getAsLong();
563 nfNamingCode = jsonObject.get("sonhandler.nfNamingCode").getAsString();
564 cpsServiceUrl = jsonObject.get("cps.service.url").getAsString();
565 getCellDataUrl = jsonObject.get("cps.get.celldata").getAsString();
566 getPnfUrl = jsonObject.get("cps.get.pnf.url").getAsString();
567 getPciUrl = jsonObject.get("cps.get.pci.url").getAsString();
568 getNbrListUrl = jsonObject.get("cps.get.nbr.list.url").getAsString();
569 nearRtricUrl = jsonObject.get("sonhandler.nearRtricUrl").getAsString();
570 ConfigClientType = jsonObject.get("sonhandler.clientType").getAsString();
572 log.info("configuration from CBS {}", this);
576 public ConfigInterface getConfigurationClient()
578 ConfigInterface conf = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType());
579 log.info("ConfigurationClient obj is : " + conf);