Modify ANR Payload aligned to A1 schema in SDNR
[dcaegen2/services/son-handler.git] / src / main / java / org / onap / dcaegen2 / services / sonhms / Configuration.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  son-handler
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  *******************************************************************************/
21
22 package org.onap.dcaegen2.services.sonhms;
23
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;
28
29 import java.lang.reflect.Type;
30 import java.util.List;
31 import java.util.Map;
32
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;
37
38
39 public class Configuration {
40
41     private static Logger log = LoggerFactory.getLogger(Configuration.class);
42
43     private static Configuration instance = null;
44     private String pgHost;
45     private int pgPort;
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;
59     private String cg;
60     private String cid;
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;
89
90     public String getCpsUsername()
91     {
92         return CpsUsername;
93     }
94     public void setCpsUsername(String CpsUsername)
95     {
96         this.CpsUsername = CpsUsername;
97     }
98     public String getCpsPassword()
99     {
100         return CpsPassword;
101     }
102     public void setCpsPassword(String CpsPassword)
103     {
104         this.CpsPassword = CpsPassword;
105     }
106
107     public String getConfigClientType()
108     {
109         return ConfigClientType;
110     }
111     public void setConfigClientType(String ConfigClientType)
112     {
113         this.ConfigClientType = ConfigClientType;
114     }
115
116     public int getPoorCountThreshold() {
117         return poorCountThreshold;
118     }
119
120     public void setPoorCountThreshold(int poorCountThreshold) {
121         this.poorCountThreshold = poorCountThreshold;
122     }
123
124     public int getBadCountThreshold() {
125         return badCountThreshold;
126     }
127
128     public void setBadCountThreshold(int badCountThreshold) {
129         this.badCountThreshold = badCountThreshold;
130     }
131
132     public int getOofTriggerCountTimer() {
133         return oofTriggerCountTimer;
134     }
135
136     public void setOofTriggerCountTimer(int oofTriggerCountTimer) {
137         this.oofTriggerCountTimer = oofTriggerCountTimer;
138     }
139
140     public int getOofTriggerCountThreshold() {
141         return oofTriggerCountThreshold;
142     }
143
144     public void setOofTriggerCountThreshold(int oofTriggerCountThreshold) {
145         this.oofTriggerCountThreshold = oofTriggerCountThreshold;
146     }
147
148     public int getPolicyRespTimer() {
149         return policyRespTimer;
150     }
151
152     public void setPolicyRespTimer(int policyRespTimer) {
153         this.policyRespTimer = policyRespTimer;
154     }
155
156     public int getBadThreshold() {
157         return badThreshold;
158     }
159
160     public void setBadThreshold(int badThreshold) {
161         this.badThreshold = badThreshold;
162     }
163
164     public int getPoorThreshold() {
165         return poorThreshold;
166     }
167
168     public void setPoorThreshold(int poorThreshold) {
169         this.poorThreshold = poorThreshold;
170     }
171
172     /**
173      * Check if topic is secure.
174      */
175     public boolean isSecured() {
176         return (aafUsername != null);
177
178     }
179
180     public String getAafUsername() {
181         return aafUsername;
182     }
183
184     public void setAafUsername(String aafUsername) {
185         this.aafUsername = aafUsername;
186     }
187
188     public String getAafPassword() {
189         return aafPassword;
190     }
191
192     public void setAafPassword(String aafPassword) {
193         this.aafPassword = aafPassword;
194     }
195
196     public Map<String, Object> getStreamsSubscribes() {
197         return streamsSubscribes;
198     }
199
200     public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) {
201         this.streamsSubscribes = streamsSubscribes;
202     }
203
204     public Map<String, Object> getStreamsPublishes() {
205         return streamsPublishes;
206     }
207
208     public void setStreamsPublishes(Map<String, Object> streamsPublishes) {
209         this.streamsPublishes = streamsPublishes;
210     }
211
212     public int getMaximumClusters() {
213         return maximumClusters;
214     }
215
216     public void setMaximumClusters(int maximumClusters) {
217         this.maximumClusters = maximumClusters;
218     }
219
220     protected Configuration() {
221
222     }
223
224     /**
225      * Get instance of class.
226      */
227     public static Configuration getInstance() {
228         if (instance == null) {
229             instance = new Configuration();
230         }
231         return instance;
232     }
233
234     public String getCg() {
235         return cg;
236     }
237
238     public void setCg(String cg) {
239         this.cg = cg;
240     }
241
242     public String getCid() {
243         return cid;
244     }
245
246     public void setCid(String cid) {
247         this.cid = cid;
248     }
249
250     public int getPollingInterval() {
251         return pollingInterval;
252     }
253
254     public void setPollingInterval(int pollingInterval) {
255         this.pollingInterval = pollingInterval;
256     }
257
258     public int getPollingTimeout() {
259         return pollingTimeout;
260     }
261
262     public void setPollingTimeout(int pollingTimeout) {
263         this.pollingTimeout = pollingTimeout;
264     }
265
266     public int getMinCollision() {
267         return minCollision;
268     }
269
270     public void setMinCollision(int minCollision) {
271         this.minCollision = minCollision;
272     }
273
274     public int getMinConfusion() {
275         return minConfusion;
276     }
277
278     public void setMinConfusion(int minConfusion) {
279         this.minConfusion = minConfusion;
280     }
281
282     public String getOofService() {
283         return oofService;
284     }
285
286     public void setOofService(String oofService) {
287         this.oofService = oofService;
288     }
289
290     public String getSourceId() {
291         return sourceId;
292     }
293
294     public void setSourceId(String sourceId) {
295         this.sourceId = sourceId;
296     }
297
298     public String getCallbackUrl() {
299         return callbackUrl;
300     }
301
302     public void setCallbackUrl(String callbackUrl) {
303         this.callbackUrl = callbackUrl;
304     }
305
306     public int getNumSolutions() {
307         return numSolutions;
308     }
309
310     public void setNumSolutions(int numSolutions) {
311         this.numSolutions = numSolutions;
312     }
313
314     public int getBufferTime() {
315         return bufferTime;
316     }
317
318     public void setBufferTime(int bufferTime) {
319         this.bufferTime = bufferTime;
320     }
321
322     public String getPgHost() {
323         return pgHost;
324     }
325
326     public void setPgHost(String pgHost) {
327         this.pgHost = pgHost;
328     }
329
330     public int getPgPort() {
331         return pgPort;
332     }
333
334     public void setPgPort(int pgPort) {
335         this.pgPort = pgPort;
336     }
337
338     public String getPgUsername() {
339         return pgUsername;
340     }
341
342     public void setPgUsername(String pgUsername) {
343         this.pgUsername = pgUsername;
344     }
345
346     public String getPgPassword() {
347         return pgPassword;
348     }
349
350     public void setPgPassword(String pgPassword) {
351         this.pgPassword = pgPassword;
352     }
353
354     public List<String> getDmaapServers() {
355         return dmaapServers;
356     }
357
358     public void setDmaapServers(List<String> dmaapServers) {
359         this.dmaapServers = dmaapServers;
360     }
361
362     public String getConfigDbService() {
363         return configDbService;
364     }
365
366     public void setConfigDbService(String configDbService) {
367         this.configDbService = configDbService;
368     }
369
370     public String getPciOptimizer() {
371         return pciOptimizer;
372     }
373
374     public void setPciOptimizer(String pciOptimizer) {
375         this.pciOptimizer = pciOptimizer;
376     }
377
378     public String getPciAnrOptimizer() {
379         return pciAnrOptimizer;
380     }
381
382     public void setPciAnrOptimizer(String pciAnrOptimizer) {
383         this.pciAnrOptimizer = pciAnrOptimizer;
384     }
385
386     public String getOofEndpoint() {
387         return oofEndpoint;
388     }
389
390     public void setOofEndpoint(String oofEndpoint) {
391         this.oofEndpoint = oofEndpoint;
392     }
393
394     public int getPolicyNegativeAckThreshold() {
395         return policyNegativeAckThreshold;
396     }
397
398     public void setPolicyNegativeAckThreshold(int policyNegativeAckThreshold) {
399         this.policyNegativeAckThreshold = policyNegativeAckThreshold;
400     }
401
402     public long getPolicyFixedPciTimeInterval() {
403         return policyFixedPciTimeInterval;
404     }
405
406     public void setPolicyFixedPciTimeInterval(long policyFixedPciTimeInterval) {
407         this.policyFixedPciTimeInterval = policyFixedPciTimeInterval;
408     }
409   
410     public String getNfNamingCode() {
411         return nfNamingCode;
412     }
413
414     public void setNfNamingCode(String nfNamingCode) {
415         this.nfNamingCode = nfNamingCode;
416     }
417
418     public static Logger getLog() {
419         return log;
420     }
421
422     public static void setLog(Logger log) {
423         Configuration.log = log;
424     }
425
426     public String getCpsServiceUrl() {
427         return cpsServiceUrl;
428     }
429
430     public void setCpsServiceUrl(String cpsServiceUrl) {
431         this.cpsServiceUrl = cpsServiceUrl;
432     }
433
434     public String getGetCellDataUrl() {
435         return getCellDataUrl;
436     }
437
438     public void setGetCellDataUrl(String getCellDataUrl) {
439         this.getCellDataUrl = getCellDataUrl;
440     }
441
442     public String getGetNbrListUrl() {
443         return getNbrListUrl;
444     }
445
446     public void setGetNbrListUrl(String getNbrListUrl) {
447         this.getNbrListUrl = getNbrListUrl;
448     }
449
450     public String getGetPciUrl() {
451         return getPciUrl;
452     }
453
454     public void setGetPciUrl(String getPciUrl) {
455         this.getPciUrl = getPciUrl;
456     }
457
458     public String getGetPnfUrl() {
459         return getPnfUrl;
460     }
461
462     public void setGetPnfUrl(String getPnfUrl) {
463         this.getPnfUrl = getPnfUrl;
464     }
465
466     public void setGetRicIdUrl(String getRicIdUrl) {
467         this.getRicIdUrl = getRicIdUrl;
468     }
469
470     public String getGetRicIdUrl() {
471         return getRicIdUrl;
472     }
473
474     public void setNearRtricUrl(String nearRtricUrl) {
475         this.nearRtricUrl = nearRtricUrl;
476     }
477
478     public String getNearRtricUrl() {
479         return nearRtricUrl;
480     }
481
482     public static void setInstance(Configuration instance) {
483         Configuration.instance = instance;
484     }
485
486     @Override
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+"]";
502     }
503
504     /**
505      * updates application configuration.
506      */
507     public void updateConfigurationFromJsonObject(JsonObject jsonObject) {
508
509         log.info("Updating configuration from CBS");
510
511         Type mapType = new TypeToken<Map<String, Object>>() {
512         }.getType();
513
514
515         JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes");
516         streamsSubscribes = new Gson().fromJson(subscribes, mapType);
517
518         JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes");
519         streamsPublishes = new Gson().fromJson(publishes, mapType);
520
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();
533
534         JsonArray servers = jsonObject.getAsJsonArray("sonhandler.dmaap.server");
535         Type listType = new TypeToken<List<String>>() {
536         }.getType();
537         dmaapServers = new Gson().fromJson(servers, listType);
538
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";
545
546         pciOptimizer = jsonObject.get("sonhandler.pciOptimizer").getAsString();
547         pciAnrOptimizer = jsonObject.get("sonhandler.pciAnrOptimizer").getAsString();
548
549         oofService = jsonObject.get("sonhandler.oof.service").getAsString();
550         oofEndpoint = jsonObject.get("sonhandler.oof.endpoint").getAsString();
551         pollingTimeout = jsonObject.get("sonhandler.pollingTimeout").getAsInt();
552
553         badThreshold = jsonObject.get("sonhandler.badThreshold").getAsInt();
554         poorThreshold = jsonObject.get("sonhandler.poorThreshold").getAsInt();
555
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();
571
572         log.info("configuration from CBS {}", this);
573
574     }
575
576     public ConfigInterface getConfigurationClient()
577     {
578          ConfigInterface conf = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType());
579          log.info("ConfigurationClient obj is : " + conf);
580          return conf;
581     }
582
583 }