1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl;
20 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile;
21 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile.ConfigurationException;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.BaseSubConfig;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.ISubConfigHandler;
25 public class DcaeConfig extends BaseSubConfig {
26 private static final String SECTION_MARKER_DCAE = "dcae";
28 private static final String PROPERTY_KEY_EVENTRECEIVERURL = "dcaeUrl";
29 //private static final String PROPERTY_KEY_TESTCOLLECTOR = "dcaeTestCollector";
30 private static final String PROPERTY_KEY_USERCREDENTIALS = "dcaeUserCredentials";
31 private static final String PROPERTY_KEY_TIMERPERIOD = "dcaeHeartbeatPeriodSeconds";
33 private static final String DEFAULT_VALUE_EVENTRECEIVERURL = "off";
34 @SuppressWarnings("unused")
35 private static final String DEFAULT_VALUE_TESTCOLLECTOR = "no";
36 private static final String DEFAULT_VALUE_USERCREDENTIALS = "admin:admin";
37 private static final int DEFAULT_VALUE_TIMERPERIOD = 120;
39 private static DcaeConfig dcaeConfig = null; // Singleton of configuration data
41 private String eventReceiverUrl;
42 private String userCredentials;
43 private Integer timerPeriodSeconds;
45 private DcaeConfig() {
47 this.eventReceiverUrl = DEFAULT_VALUE_EVENTRECEIVERURL;
48 this.userCredentials = DEFAULT_VALUE_USERCREDENTIALS;
49 this.timerPeriodSeconds = DEFAULT_VALUE_TIMERPERIOD;
52 private DcaeConfig(IniConfigurationFile config, ISubConfigHandler configHandler) throws ConfigurationException {
53 this(config, configHandler, true);
56 private DcaeConfig(IniConfigurationFile config, ISubConfigHandler configHandler, boolean save)
57 throws ConfigurationException {
59 super(config, configHandler, SECTION_MARKER_DCAE);
61 this.eventReceiverUrl = this.getString(PROPERTY_KEY_EVENTRECEIVERURL, DEFAULT_VALUE_EVENTRECEIVERURL);
62 this.userCredentials = this.getString(PROPERTY_KEY_USERCREDENTIALS, DEFAULT_VALUE_USERCREDENTIALS);
63 this.timerPeriodSeconds = this.getInt(PROPERTY_KEY_TIMERPERIOD, DEFAULT_VALUE_TIMERPERIOD);
65 config.setProperty(SECTION_MARKER_DCAE + "." + PROPERTY_KEY_EVENTRECEIVERURL, this.eventReceiverUrl);
66 config.setProperty(SECTION_MARKER_DCAE + "." + PROPERTY_KEY_USERCREDENTIALS, this.userCredentials);
67 config.setProperty(SECTION_MARKER_DCAE + "." + PROPERTY_KEY_TIMERPERIOD, this.timerPeriodSeconds);
77 public void setEventReceiverUrl(String eventReveicerUrl) {
78 this.eventReceiverUrl = eventReveicerUrl;
81 public void setUserCredentials(String userCredentials) {
82 this.userCredentials = userCredentials;
87 public void setTimerPeriodSeconds(Integer timerPeriodSeconds) {
88 this.timerPeriodSeconds = timerPeriodSeconds;
95 public String getEventReveicerUrl() {
96 return eventReceiverUrl;
99 public String getUserCredentials() {
100 return userCredentials;
104 public Integer getTimerPeriodSeconds() {
105 return timerPeriodSeconds;
109 public String toString() {
110 return "DcaeConfig [eventReceiverUrl=" + eventReceiverUrl + ", userCredentials=" + userCredentials
111 + ", timerPeriodSeconds=" + timerPeriodSeconds + "]";
115 public int hashCode() {
116 final int prime = 31;
118 result = prime * result + (eventReceiverUrl == null ? 0 : eventReceiverUrl.hashCode());
119 result = prime * result + (timerPeriodSeconds == null ? 0 : timerPeriodSeconds.hashCode());
120 result = prime * result + (userCredentials == null ? 0 : userCredentials.hashCode());
125 public boolean equals(Object obj) {
132 if (getClass() != obj.getClass()) {
135 DcaeConfig other = (DcaeConfig) obj;
136 if (eventReceiverUrl == null) {
137 if (other.eventReceiverUrl != null) {
140 } else if (!eventReceiverUrl.equals(other.eventReceiverUrl)) {
143 if (timerPeriodSeconds == null) {
144 if (other.timerPeriodSeconds != null) {
147 } else if (!timerPeriodSeconds.equals(other.timerPeriodSeconds)) {
150 if (userCredentials == null) {
151 if (other.userCredentials != null) {
154 } else if (!userCredentials.equals(other.userCredentials)) {
160 /*-------------------------------------
164 public static DcaeConfig getDefaultConfiguration() {
165 return new DcaeConfig();
168 public static DcaeConfig getDcae(IniConfigurationFile config, ISubConfigHandler configHandler) {
169 if (dcaeConfig == null) {
171 dcaeConfig = new DcaeConfig(config, configHandler);
172 } catch (ConfigurationException e) {
173 dcaeConfig = DcaeConfig.getDefaultConfiguration();
179 public static boolean isInstantiated() {
180 return dcaeConfig != null;
183 public static DcaeConfig reload() {
184 if (dcaeConfig == null) {
187 DcaeConfig tmpConfig;
189 tmpConfig = new DcaeConfig(dcaeConfig.getConfig(), dcaeConfig.getConfigHandler(), false);
190 } catch (ConfigurationException e) {
191 tmpConfig = DcaeConfig.getDefaultConfiguration();
193 dcaeConfig = tmpConfig;
197 public static void clear() {