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 java.util.EnumMap;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile.ConfigurationException;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.BaseSubConfig;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.ISubConfigHandler;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorProblems;
31 * Configuration of devicemonitor, section [devicemonitor]
32 * SeverityConnectionlossNeOAM=minor
33 * SeverityConnectionlossOAM=major
34 * SeverityConnectionlossMediator=critical
36 public class DmConfig extends BaseSubConfig{
38 private static final String SECTION_MARKER_TA = "devicemonitor";
39 private static final String PROPERTY_KEY_PREFIX_Severity = "Severity";
41 private static DmConfig dmConfig = null;
43 private Map<DeviceMonitorProblems, InternalSeverity> severty = new EnumMap<>(DeviceMonitorProblems.class);
52 public DmConfig(IniConfigurationFile config, ISubConfigHandler configHandler) throws ConfigurationException {
53 this(config, configHandler, true);
56 public DmConfig(IniConfigurationFile config, ISubConfigHandler configHandler, boolean save)
57 throws ConfigurationException {
59 super(config, configHandler, SECTION_MARKER_TA);
61 for (DeviceMonitorProblems problem : DeviceMonitorProblems.values()) {
62 severty.put(problem, readProperty(problem));
66 for (DeviceMonitorProblems problem : DeviceMonitorProblems.values()) {
67 configSetPropertyp(config, problem, severty.get(problem));
73 public InternalSeverity getSeverity(DeviceMonitorProblems problem) {
74 return severty.get(problem);
77 public static DmConfig getDefaultConfiguration() {
78 DmConfig c = new DmConfig();
79 for (DeviceMonitorProblems problem : DeviceMonitorProblems.values()) {
80 c.severty.put(problem, InternalSeverity.Major);
84 public static boolean isInstantiated() {
85 return dmConfig != null;
88 public static DmConfig getDmConfig(IniConfigurationFile config, ISubConfigHandler configHandler) {
89 if (dmConfig == null) {
91 dmConfig = new DmConfig(config, configHandler);
92 } catch (ConfigurationException e) {
93 dmConfig = DmConfig.getDefaultConfiguration();
99 public static DmConfig reload() {
100 if (dmConfig == null) {
105 tmpConfig = new DmConfig(dmConfig.getConfig(), dmConfig.getConfigHandler(), false);
106 } catch (ConfigurationException e) {
107 tmpConfig = DmConfig.getDefaultConfiguration();
109 dmConfig = tmpConfig;
113 public static void clear() {
118 * Private Helper functions
120 private static String getPropertyName(DeviceMonitorProblems problem) {
121 return PROPERTY_KEY_PREFIX_Severity+problem.name();
124 private static void configSetPropertyp(IniConfigurationFile config, DeviceMonitorProblems problem, InternalSeverity value) {
125 config.setProperty(SECTION_MARKER_TA + "."+getPropertyName(problem), value.getValueAsString());
128 private InternalSeverity readProperty(DeviceMonitorProblems problem) {
129 return InternalSeverity.valueOfString(getString(getPropertyName(problem), InternalSeverity.Major.getValueAsString()));