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 EsConfig extends BaseSubConfig {
28 public static final String SECTION_MARKER_ES = "es";
29 public static final String ESDATATYPENAME = "database";
30 private static final String EMPTY = "empty";
31 private static final String PROPERTY_KEY_CLUSTER = "esCluster";
32 private static final String DEFAULT_VALUE_CLUSTER = "";
33 private static EsConfig esConfig;
35 private String cluster;
45 this.cluster = DEFAULT_VALUE_CLUSTER;
48 public EsConfig cloneWithIndex(String _index) {
49 EsConfig c = new EsConfig();
53 c.cluster = this.cluster;
57 public static String getESDATATYPENAME() {
58 return ESDATATYPENAME;
61 public String getCluster() {
65 public void setCluster(String cluster) {
66 this.cluster = cluster;
69 public String getHost() {
73 public void setHost(String host) {
77 public String getNode() {
81 public void setNode(String node) {
85 public String getIndex() {
89 public void setIndex(String index) {
94 public String toString() {
95 return "EsConfig [cluster=" + cluster + ", host=" + host + ", node=" + node + ", index=" + index + "]";
98 public EsConfig(IniConfigurationFile config, ISubConfigHandler configHandler) throws ConfigurationException {
99 this(config, configHandler, true);
102 public EsConfig(IniConfigurationFile config, ISubConfigHandler configHandler, boolean save)
103 throws ConfigurationException {
105 super(config, configHandler, SECTION_MARKER_ES);
106 String clustername = Environment.getVar("$HOSTNAME");
108 String c = this.getString(PROPERTY_KEY_CLUSTER, clustername);
109 if (c != null && c.startsWith("$")) {
110 c = Environment.getVar(c);
113 this.node = String.format("%s%s", this.cluster, "n1");
114 this.host = "localhost";
117 config.setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_CLUSTER, this.cluster);
123 public int hashCode() {
124 final int prime = 31;
126 result = prime * result + (cluster == null ? 0 : cluster.hashCode());
127 result = prime * result + (host == null ? 0 : host.hashCode());
128 result = prime * result + (index == null ? 0 : index.hashCode());
129 result = prime * result + (node == null ? 0 : node.hashCode());
134 public boolean equals(Object obj) {
141 if (getClass() != obj.getClass()) {
144 EsConfig other = (EsConfig) obj;
145 if (cluster == null) {
146 if (other.cluster != null) {
149 } else if (!cluster.equals(other.cluster)) {
153 if (other.host != null) {
156 } else if (!host.equals(other.host)) {
160 if (other.index != null) {
163 } else if (!index.equals(other.index)) {
167 if (other.node != null) {
170 } else if (!node.equals(other.node)) {
179 this.getConfig().setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_CLUSTER, this.cluster);
182 public static boolean isInstantiated() {
183 return esConfig != null;
186 public static EsConfig getDefaultConfiguration() {
187 return new EsConfig();
190 public static EsConfig getEs(IniConfigurationFile config, ISubConfigHandler configHandler) {
191 if (esConfig == null) {
193 esConfig = new EsConfig(config, configHandler);
194 } catch (ConfigurationException e) {
195 esConfig = EsConfig.getDefaultConfiguration();
201 public static EsConfig reload() {
202 if (esConfig == null) {
207 tmpConfig = new EsConfig(esConfig.getConfig(), esConfig.getConfigHandler(), false);
208 } catch (ConfigurationException e) {
209 tmpConfig = EsConfig.getDefaultConfiguration();
211 esConfig = tmpConfig;
215 public static void clear() {