c3bddc9b1021903d068d421c72fc72aa338e59fe
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.config;
23
24 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
25 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
27
28 public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuration {
29
30     private static final String SECTION_MARKER = "VESCollector";
31
32     /** set to true if VES Collector is installed and configured */
33     private static final String PROPERTY_KEY_VES_COLLECTOR_ENABLED = "VES_COLLECTOR_ENABLED";
34     private static final boolean DEFAULT_VALUE_VES_COLLECTOR_ENABLED = false;
35
36     private static final String PROPERTY_KEY_VES_COLLECTOR_IP = "VES_COLLECTOR_IP";
37     private static final String DEFAULT_VALUE_VES_COLLECTOR_IP = "127.0.0.1";
38
39     private static final String PROPERTY_KEY_VES_COLLECTOR_PORT = "VES_COLLECTOR_PORT";
40     private static final String DEFAULT_VALUE_VES_COLLECTOR_PORT = "8080";
41
42     private static final String PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED = "VES_COLLECTOR_TLS_ENABLED";
43
44     private static final String PROPERTY_KEY_VES_COLLECTOR_USERNAME = "VES_COLLECTOR_USERNAME";
45     private static final String DEFAULT_VALUE_VES_COLLECTOR_USERNAME = "sample1";
46
47     private static final String PROPERTY_KEY_VES_COLLECTOR_PASSWORD = "VES_COLLECTOR_PASSWORD";
48     private static final String DEFAULT_VALUE_VES_COLLECTOR_PASSWORD = "sample1";
49
50     private static final String PROPERTY_KEY_VES_COLLECTOR_VERSION = "VES_COLLECTOR_VERSION";
51     private static final String DEFAULT_VALUE_VES_COLLECTOR_VERSION = "v7";
52
53     private static final String PROPERTY_KEY_REPORTING_ENTITY_NAME = "REPORTING_ENTITY_NAME";
54     private static final String DEFAULT_VALUE_REPORTING_ENTITY_NAME = "ONAP SDN-R";
55
56     private static final String PROPERTY_KEY_EVENTLOG_DETAIL = "EVENTLOG_MSG_DETAIL";
57     private static final String DEFAULT_VALUE_EVENTLOG_DETAIL = "SHORT"; // "SHORT", "MEDIUM", "LONG"
58
59
60     private static ConfigurationFileRepresentation configuration;
61
62     public VESCollectorCfgImpl(ConfigurationFileRepresentation configuration) {
63         VESCollectorCfgImpl.configuration = configuration;
64         VESCollectorCfgImpl.configuration.addSection(SECTION_MARKER);
65         defaults();
66     }
67
68     @Override
69     public String getSectionName() {
70         return SECTION_MARKER;
71     }
72
73     @Override
74     public String getReportingEntityName() {
75         return configuration != null ? configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_REPORTING_ENTITY_NAME) : "ONAP SDN-R";
76     }
77
78     @Override
79     public String getEventLogMsgDetail() {
80         return configuration != null ?configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_EVENTLOG_DETAIL) : DEFAULT_VALUE_EVENTLOG_DETAIL;
81     }
82
83     @Override
84     public boolean isVESCollectorEnabled() {
85         return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_ENABLED);
86     }
87
88     public boolean getTLSEnabled() {
89         return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED);
90     }
91
92     public String getUsername() {
93         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_USERNAME);
94     }
95
96     public String getPassword() {
97         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PASSWORD);
98     }
99
100     public String getIP() {
101         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_IP);
102     }
103
104     public String getPort() {
105         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PORT);
106     }
107
108     public String getVersion() {
109         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_VERSION);
110     }
111
112     @Override
113     public synchronized void defaults() {
114         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_ENABLED, DEFAULT_VALUE_VES_COLLECTOR_ENABLED);
115         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED, Boolean.FALSE);
116         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_USERNAME,
117                 DEFAULT_VALUE_VES_COLLECTOR_USERNAME);
118         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PASSWORD,
119                 DEFAULT_VALUE_VES_COLLECTOR_PASSWORD);
120         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_IP,
121                 DEFAULT_VALUE_VES_COLLECTOR_IP);
122         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PORT,
123                 DEFAULT_VALUE_VES_COLLECTOR_PORT);
124         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_VERSION,
125                 DEFAULT_VALUE_VES_COLLECTOR_VERSION);
126         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_REPORTING_ENTITY_NAME,
127                 DEFAULT_VALUE_REPORTING_ENTITY_NAME);
128         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_EVENTLOG_DETAIL,
129                 DEFAULT_VALUE_EVENTLOG_DETAIL);
130     }
131
132 }