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 PROPERTY_KEY_ARCHIVE_INTERVAL = "esArchiveCheckIntervalSeconds";
33 private static final String PROPERTY_KEY_ARCHIVE_LIMIT = "esArchiveLifetimeSeconds";
35 private static final String DEFAULT_VALUE_CLUSTER = "";
37 * check db data in this interval [in seconds]
40 private static final long DEFAULT_ARCHIVE_INTERVAL_SEC = 0;
42 * keep data for this time [in seconds]
45 private static final long DEFAULT_ARCHIVE_LIMIT_SEC = 60 * 60 * 24 * 30;
47 private static EsConfig esConfig;
49 private String cluster;
53 private long archiveCheckIntervalSeconds;
54 private long archiveLifetimeSeconds;
61 this.cluster = DEFAULT_VALUE_CLUSTER;
62 this.archiveCheckIntervalSeconds = DEFAULT_ARCHIVE_INTERVAL_SEC;
63 this.archiveLifetimeSeconds = DEFAULT_ARCHIVE_LIMIT_SEC;
66 public EsConfig cloneWithIndex(String _index) {
67 EsConfig c = new EsConfig();
71 c.cluster = this.cluster;
72 c.archiveCheckIntervalSeconds = this.archiveCheckIntervalSeconds;
73 c.archiveLifetimeSeconds = this.archiveLifetimeSeconds;
77 public static String getESDATATYPENAME() {
78 return ESDATATYPENAME;
81 public String getCluster() {
85 public void setCluster(String cluster) {
86 this.cluster = cluster;
89 public String getHost() {
93 public void setHost(String host) {
97 public String getNode() {
101 public void setNode(String node) {
105 public String getIndex() {
109 public void setIndex(String index) {
113 public long getArchiveCheckIntervalSeconds() {
114 return this.archiveCheckIntervalSeconds;
117 public void setArchiveCheckIntervalSeconds(long x) {
118 this.archiveCheckIntervalSeconds = x;
121 public long getArchiveLifetimeSeconds() {
122 return this.archiveLifetimeSeconds;
125 public void setArchiveLimit(long x) {
126 this.archiveLifetimeSeconds = x;
130 public String toString() {
131 return "EsConfig [cluster=" + cluster + ", host=" + host + ", node=" + node + ", index=" + index + "]";
134 public EsConfig(IniConfigurationFile config, ISubConfigHandler configHandler) throws ConfigurationException {
135 this(config, configHandler, true);
138 public EsConfig(IniConfigurationFile config, ISubConfigHandler configHandler, boolean save)
139 throws ConfigurationException {
141 super(config, configHandler, SECTION_MARKER_ES);
142 String clustername = Environment.getVar("$HOSTNAME");
144 String c = this.getString(PROPERTY_KEY_CLUSTER, clustername);
145 if (c != null && c.startsWith("$")) {
146 c = Environment.getVar(c);
149 this.node = String.format("%s%s", this.cluster, "n1");
150 this.host = "localhost";
151 this.archiveCheckIntervalSeconds = this.getLong(PROPERTY_KEY_ARCHIVE_INTERVAL, DEFAULT_ARCHIVE_INTERVAL_SEC);
152 this.archiveLifetimeSeconds = this.getLong(PROPERTY_KEY_ARCHIVE_LIMIT, DEFAULT_ARCHIVE_LIMIT_SEC);
155 config.setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_CLUSTER, this.cluster);
156 config.setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_ARCHIVE_INTERVAL, this.archiveCheckIntervalSeconds);
157 config.setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_ARCHIVE_LIMIT, this.archiveLifetimeSeconds);
163 public int hashCode() {
164 final int prime = 31;
166 result = prime * result + (cluster == null ? 0 : cluster.hashCode());
167 result = prime * result + (host == null ? 0 : host.hashCode());
168 result = prime * result + (index == null ? 0 : index.hashCode());
169 result = prime * result + (node == null ? 0 : node.hashCode());
174 public boolean equals(Object obj) {
181 if (getClass() != obj.getClass()) {
184 EsConfig other = (EsConfig) obj;
185 if (cluster == null) {
186 if (other.cluster != null) {
189 } else if (!cluster.equals(other.cluster)) {
193 if (other.host != null) {
196 } else if (!host.equals(other.host)) {
200 if (other.index != null) {
203 } else if (!index.equals(other.index)) {
207 if (other.node != null) {
210 } else if (!node.equals(other.node)) {
213 if (archiveCheckIntervalSeconds != other.archiveCheckIntervalSeconds) {
216 if (archiveLifetimeSeconds != other.archiveLifetimeSeconds) {
224 this.getConfig().setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_CLUSTER, this.cluster);
228 public static boolean isInstantiated() {
229 return esConfig != null;
232 public static EsConfig getDefaultConfiguration() {
233 return new EsConfig();
236 public static EsConfig getEs(IniConfigurationFile config, ISubConfigHandler configHandler) {
237 if (esConfig == null) {
239 esConfig = new EsConfig(config, configHandler);
240 } catch (ConfigurationException e) {
241 esConfig = EsConfig.getDefaultConfiguration();
247 public static EsConfig reload() {
248 if (esConfig == null) {
253 tmpConfig = new EsConfig(esConfig.getConfig(), esConfig.getConfigHandler(), false);
254 } catch (ConfigurationException e) {
255 tmpConfig = EsConfig.getDefaultConfiguration();
257 esConfig = tmpConfig;
261 public static void clear() {