1924a6759abe6c5457fa74af6a822baaa11bcdef
[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     private static final String PROPERTY_KEY_VES_COLLECTOR_IP = "VES_COLLECTOR_IP";
33     private static final String DEFAULT_VALUE_VES_COLLECTOR_IP = "127.0.0.1";
34
35     private static final String PROPERTY_KEY_VES_COLLECTOR_PORT = "VES_COLLECTOR_PORT";
36     private static final String DEFAULT_VALUE_VES_COLLECTOR_PORT = "8080";
37
38     private static final String PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED = "VES_COLLECTOR_TLS_ENABLED";
39
40     private static final String PROPERTY_KEY_VES_COLLECTOR_USERNAME = "VES_COLLECTOR_USERNAME";
41     private static final String DEFAULT_VALUE_VES_COLLECTOR_USERNAME = "sample1";
42
43     private static final String PROPERTY_KEY_VES_COLLECTOR_PASSWORD = "VES_COLLECTOR_PASSWORD";
44     private static final String DEFAULT_VALUE_VES_COLLECTOR_PASSWORD = "sample1";
45
46     private static final String PROPERTY_KEY_VES_COLLECTOR_VERSION = "VES_COLLECTOR_VERSION";
47     private static final String DEFAULT_VALUE_VES_COLLECTOR_VERSION = "v7";
48
49     private static final String PROPERTY_KEY_REPORTING_ENTITY_NAME = "REPORTING_ENTITY_NAME";
50     private static final String DEFAULT_VALUE_REPORTING_ENTITY_NAME = "ONAP SDN-R";
51
52     private static final String PROPERTY_KEY_EVENTLOG_DETAIL = "EVENTLOG_MSG_DETAIL";
53     private static final String DEFAULT_VALUE_EVENTLOG_DETAIL = "SHORT"; // "SHORT", "MEDIUM", "LONG"
54
55
56     private static ConfigurationFileRepresentation configuration;
57
58     public VESCollectorCfgImpl(ConfigurationFileRepresentation configuration) {
59         VESCollectorCfgImpl.configuration = configuration;
60         VESCollectorCfgImpl.configuration.addSection(SECTION_MARKER);
61         defaults();
62     }
63
64     @Override
65     public String getSectionName() {
66         return SECTION_MARKER;
67     }
68
69     @Override
70     public String getReportingEntityName() {
71         return configuration != null ? configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_REPORTING_ENTITY_NAME) : "ONAP SDN-R";
72     }
73
74     @Override
75     public String getEventLogMsgDetail() {
76         return configuration != null ?configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_EVENTLOG_DETAIL) : DEFAULT_VALUE_EVENTLOG_DETAIL;
77     }
78
79     public boolean getTLSEnabled() {
80         return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED);
81     }
82
83     public String getUsername() {
84         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_USERNAME);
85     }
86
87     public String getPassword() {
88         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PASSWORD);
89     }
90
91     public String getIP() {
92         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_IP);
93     }
94
95     public String getPort() {
96         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PORT);
97     }
98
99     public String getVersion() {
100         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_VERSION);
101     }
102
103     @Override
104     public synchronized void defaults() {
105         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED, Boolean.FALSE);
106         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_USERNAME,
107                 DEFAULT_VALUE_VES_COLLECTOR_USERNAME);
108         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PASSWORD,
109                 DEFAULT_VALUE_VES_COLLECTOR_PASSWORD);
110         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_IP,
111                 DEFAULT_VALUE_VES_COLLECTOR_IP);
112         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PORT,
113                 DEFAULT_VALUE_VES_COLLECTOR_PORT);
114         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_VERSION,
115                 DEFAULT_VALUE_VES_COLLECTOR_VERSION);
116         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_REPORTING_ENTITY_NAME,
117                 DEFAULT_VALUE_REPORTING_ENTITY_NAME);
118         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_EVENTLOG_DETAIL,
119                 DEFAULT_VALUE_EVENTLOG_DETAIL);
120     }
121
122 }