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