80e8659908094804857595aee20c0fed2420a0a3
[ccsdk/features.git] /
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.config;
19
20 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
21 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorProblems;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
24
25 /**
26  * Configuration of devicemonitor, section [devicemonitor] SeverityConnectionlossNeOAM=minor
27  * SeverityConnectionlossOAM=major SeverityConnectionlossMediator=critical
28  */
29 public class DmConfig implements Configuration {
30
31     private static final String SECTION_MARKER_TA = "devicemonitor";
32
33     private static final String PROPERTY_KEY_PREFIX_Severity = "Severity";
34
35     private final ConfigurationFileRepresentation configuration;
36
37     public DmConfig(ConfigurationFileRepresentation configuration) {
38         this.configuration = configuration;
39         this.configuration.addSection(SECTION_MARKER_TA);
40         defaults();
41     }
42
43     public InternalSeverity getSeverity(DeviceMonitorProblems problem) {
44         String severityString = configuration.getProperty(SECTION_MARKER_TA, getPropertyName(problem));
45         InternalSeverity result = InternalSeverity.valueOfString(severityString);
46         return result != null ? result : InternalSeverity.Major;
47     }
48
49     @Override
50     public String getSectionName() {
51         return SECTION_MARKER_TA;
52     }
53
54     @Override
55     public void defaults() {
56         for (DeviceMonitorProblems problem : DeviceMonitorProblems.values()) {
57             configuration.setPropertyIfNotAvailable(SECTION_MARKER_TA, getPropertyName(problem),
58                     problem.getSeverity().name());
59         }
60     }
61
62     private String getPropertyName(DeviceMonitorProblems problem) {
63         return PROPERTY_KEY_PREFIX_Severity + problem.name();
64     }
65
66 }