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.Environment;
21 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile.ConfigurationException;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.BaseSubConfig;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.ISubConfigHandler;
26 public class PmConfig extends BaseSubConfig {
28 private static final String SECTION_MARKER_PM = "pm";
29 private static final String PROPERTY_KEY_ENABLED = "pmEnabled";
30 private static final String PROPERTY_KEY_CLUSTER = "pmCluster";
32 private static final boolean DEFAULT_VALUE_ENABLED = true;
33 private static final String DEFAULT_VALUE_CLUSTER = "";
34 private static PmConfig pmConfig;
36 private boolean enabled;
38 public static final String ESDATATYPENAME = "database";
40 private static final String EMPTY = "empty";
42 private String cluster;
46 public static String getESDATATYPENAME() {
47 return ESDATATYPENAME;
50 public String getCluster() {
54 public void setCluster(String cluster) {
55 this.cluster = cluster;
58 public String getHost() {
62 public void setHost(String host) {
66 public String getNode() {
70 public void setNode(String node) {
74 public boolean isPerformanceManagerEnabled() {
78 public PmConfig(IniConfigurationFile config, ISubConfigHandler configHandler) throws ConfigurationException {
79 this(config, configHandler, true);
82 public PmConfig(IniConfigurationFile config, ISubConfigHandler configHandler, boolean save)
83 throws ConfigurationException {
85 super(config, configHandler, SECTION_MARKER_PM);
86 String clustername = Environment.getVar("$HOSTNAME");
88 this.enabled = this.getBoolean(PROPERTY_KEY_ENABLED, DEFAULT_VALUE_ENABLED);
89 String c = this.getString(PROPERTY_KEY_CLUSTER, clustername);
90 if (c != null && c.startsWith("$")) {
91 c = Environment.getVar(c);
94 this.node = String.format("%s%s", this.cluster, "n1");
95 this.host = "localhost";
98 config.setProperty(SECTION_MARKER_PM + "." + PROPERTY_KEY_ENABLED, this.enabled);
99 config.setProperty(SECTION_MARKER_PM + "." + PROPERTY_KEY_CLUSTER, this.cluster);
107 this.cluster = EMPTY;
110 this.enabled = DEFAULT_VALUE_ENABLED;
116 public int hashCode() {
117 final int prime = 31;
119 result = prime * result + (cluster == null ? 0 : cluster.hashCode());
120 result = prime * result + (enabled ? 1231 : 1237);
121 result = prime * result + (host == null ? 0 : host.hashCode());
122 result = prime * result + (node == null ? 0 : node.hashCode());
127 public boolean equals(Object obj) {
134 if (getClass() != obj.getClass()) {
137 PmConfig other = (PmConfig) obj;
138 if (cluster == null) {
139 if (other.cluster != null) {
142 } else if (!cluster.equals(other.cluster)) {
145 if (enabled != other.enabled) {
149 if (other.host != null) {
152 } else if (!host.equals(other.host)) {
156 if (other.node != null) {
159 } else if (!node.equals(other.node)) {
165 public static PmConfig getDefaultConfiguration() {
166 PmConfig c = new PmConfig();
167 c.enabled = DEFAULT_VALUE_ENABLED;
168 c.cluster = DEFAULT_VALUE_CLUSTER;
173 public String toString() {
174 return "PmConfig [enabled=" + enabled + ", cluster=" + cluster + ", host=" + host + ", node=" + node + "]";
177 public static boolean isInstantiated() {
178 return pmConfig != null;
181 public static PmConfig getPm(IniConfigurationFile config, ISubConfigHandler configHandler) {
182 if (pmConfig == null) {
184 pmConfig = new PmConfig(config, configHandler);
185 } catch (ConfigurationException e) {
186 pmConfig = PmConfig.getDefaultConfiguration();
192 public static PmConfig reload() {
193 if (pmConfig == null) {
198 tmpConfig = new PmConfig(pmConfig.getConfig(), pmConfig.getConfigHandler(), false);
199 } catch (ConfigurationException e) {
200 tmpConfig = PmConfig.getDefaultConfiguration();
202 pmConfig = tmpConfig;
206 public static void clear() {