2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.dal.elasticsearch.config;
25 import java.util.Properties;
27 import org.onap.aai.sparky.util.ConfigHelper;
28 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
32 * The Class ElasticSearchConfig.
34 public class ElasticSearchConfig {
36 public static final String CONFIG_FILE =
37 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "elasticsearch.properties";
39 private static ElasticSearchConfig instance;
41 private String ipAddress;
43 private String httpPort;
45 private String javaApiPort;
47 private String indexName;
51 private String clusterName;
53 private String mappingsFileName;
55 private String settingsFileName;
57 private String topographicalSearchIndex;
59 private String entityCountHistoryIndex;
61 private String autosuggestIndexname;
63 private String entityCountHistoryMappingsFileName;
65 private String autoSuggestSettingsFileName;
67 private String autoSuggestMappingsFileName;
69 private String dynamicMappingsFileName;
71 private static final String IP_ADDRESS_DEFAULT = "localhost";
73 private static final String HTTP_PORT_DEFAULT = "9200";
75 private static final String JAVA_API_PORT_DEFAULT = "9300";
77 private static final String TYPE_DEFAULT = "aaiEntities";
79 private static final String CLUSTER_NAME_DEFAULT = "elasticsearch";
81 private static final String INDEX_NAME_DEFAULT = "entitySearchIndex";
83 private static final String AUDIT_INDEX_NAME_DEFAULT = "auditdataindex";
85 private static final String TOPOGRAPHICAL_INDEX_NAME_DEFAULT = "topographicalSearchIndex";
87 private static final String ENTITY_COUNT_HISTORY_INDEX_NAME_DEFAULT = "entityCountHistory";
89 private static final String ENTITY_AUTO_SUGGEST_INDEX_NAME_DEFAULT =
90 TierSupportUiConstants.ENTITY_AUTO_SUGGEST_INDEX_NAME_DEFAULT;
92 private static final String ENTITY_AUTO_SUGGEST_SETTINGS_FILE_DEFAULT =
93 TierSupportUiConstants.ENTITY_AUTO_SUGGEST_SETTINGS_FILE_DEFAULT;
95 private static final String ENTITY_AUTO_SUGGEST_MAPPINGS_FILE_DEFAULT =
96 TierSupportUiConstants.ENTITY_AUTO_SUGGEST_SETTINGS_FILE_DEFAULT;
98 private static final String ENTITY_DYNAMIC_MAPPINGS_FILE_DEFAULT =
99 TierSupportUiConstants.ENTITY_DYNAMIC_MAPPINGS_FILE_DEFAULT;
101 private static final String BULK_API = "_bulk";
103 public static ElasticSearchConfig getConfig() throws Exception {
105 if (instance == null) {
106 instance = new ElasticSearchConfig();
107 instance.initializeProperties();
113 public static void setConfig(ElasticSearchConfig config) {
115 * Explicitly allow setting the configuration singleton. This will be useful for automation.
118 ElasticSearchConfig.instance = config;
122 * Instantiates a new elastic search config.
124 public ElasticSearchConfig() {
128 public String getElasticFullUrl(String resourceUrl, String indexName, String indexType)
130 final String host = getIpAddress();
131 final String port = getHttpPort();
132 return String.format("http://%s:%s/%s/%s%s", host, port, indexName, indexType, resourceUrl);
135 public String getElasticFullUrl(String resourceUrl, String indexName) throws Exception {
136 final String host = getIpAddress();
137 final String port = getHttpPort();
138 return String.format("http://%s:%s/%s/%s%s", host, port, indexName,
139 ElasticSearchConfig.getConfig().getType(), resourceUrl);
142 public String getElasticFullUrl(String resourceUrl) throws Exception {
143 final String host = getIpAddress();
144 final String port = getHttpPort();
145 final String indexName = getIndexName();
146 return String.format("http://%s:%s/%s/%s%s", host, port, indexName, getType(), resourceUrl);
150 * Initialize properties.
152 private void initializeProperties() {
153 Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
155 if (props == null || props.isEmpty()) {
159 ipAddress = props.getProperty("elasticsearch.ipAddress", IP_ADDRESS_DEFAULT);
160 httpPort = props.getProperty("elasticsearch.httpPort", "" + HTTP_PORT_DEFAULT);
161 javaApiPort = props.getProperty("elasticsearch.javaApiPort", "" + JAVA_API_PORT_DEFAULT);
162 type = props.getProperty("elasticsearch.type", TYPE_DEFAULT);
163 clusterName = props.getProperty("elasticsearch.clusterName", CLUSTER_NAME_DEFAULT);
164 indexName = props.getProperty("elasticsearch.indexName", INDEX_NAME_DEFAULT);
165 mappingsFileName = props.getProperty("elasticsearch.mappingsFileName");
166 settingsFileName = props.getProperty("elasticsearch.settingsFileName");
167 topographicalSearchIndex =
168 props.getProperty("elasticsearch.topographicalIndexName", TOPOGRAPHICAL_INDEX_NAME_DEFAULT);
169 entityCountHistoryIndex = props.getProperty("elasticsearch.entityCountHistoryIndexName",
170 ENTITY_COUNT_HISTORY_INDEX_NAME_DEFAULT);
172 entityCountHistoryMappingsFileName =
173 props.getProperty("elasticsearch.entityCountHistoryMappingsFileName");
175 autosuggestIndexname = props.getProperty("elasticsearch.autosuggestIndexname",
176 ENTITY_AUTO_SUGGEST_INDEX_NAME_DEFAULT);
177 autoSuggestSettingsFileName = props.getProperty("elasticsearch.autosuggestSettingsFileName",
178 ENTITY_AUTO_SUGGEST_SETTINGS_FILE_DEFAULT);
179 autoSuggestMappingsFileName = props.getProperty("elasticsearch.autosuggestMappingsFileName",
180 ENTITY_AUTO_SUGGEST_MAPPINGS_FILE_DEFAULT);
181 dynamicMappingsFileName = props.getProperty("elasticsearch.dynamicMappingsFileName",
182 ENTITY_DYNAMIC_MAPPINGS_FILE_DEFAULT);
186 public String getIpAddress() {
190 public void setIpAddress(String ipAddress) {
191 this.ipAddress = ipAddress;
194 public String getHttpPort() {
198 public void setHttpPort(String httpPort) {
199 this.httpPort = httpPort;
202 public String getJavaApiPort() {
206 public void setJavaApiPort(String javaApiPort) {
207 this.javaApiPort = javaApiPort;
210 public String getIndexName() {
214 public void setIndexName(String indexName) {
215 this.indexName = indexName;
218 public String getType() {
222 public void setType(String type) {
226 public String getClusterName() {
230 public void setClusterName(String clusterName) {
231 this.clusterName = clusterName;
234 public String getMappingsFileName() {
235 return mappingsFileName;
238 public void setMappingsFileName(String mappingsFileName) {
239 this.mappingsFileName = mappingsFileName;
242 public String getSettingsFileName() {
243 return settingsFileName;
246 public void setSettingsFileName(String settingsFileName) {
247 this.settingsFileName = settingsFileName;
250 public String getTopographicalSearchIndex() {
251 return topographicalSearchIndex;
254 public void setTopographicalSearchIndex(String topographicalSearchIndex) {
255 this.topographicalSearchIndex = topographicalSearchIndex;
258 public String getEntityCountHistoryIndex() {
259 return entityCountHistoryIndex;
262 public void setEntityCountHistoryIndex(String entityCountHistoryIndex) {
263 this.entityCountHistoryIndex = entityCountHistoryIndex;
267 public String getEntityCountHistoryMappingsFileName() {
268 return entityCountHistoryMappingsFileName;
271 public void setEntityCountHistoryMappingsFileName(String entityCountHistoryMappingsFileName) {
272 this.entityCountHistoryMappingsFileName = entityCountHistoryMappingsFileName;
275 public String getBulkUrl() {
276 String url = this.getIpAddress();
277 String port = this.getHttpPort();
278 return String.format("http://%s:%s/%s", url, port, BULK_API);
281 public String getAutosuggestIndexname() {
282 return autosuggestIndexname;
285 public void setAutosuggestIndexname(String autosuggestIndexname) {
286 this.autosuggestIndexname = autosuggestIndexname;
289 public String getAutoSuggestSettingsFileName() {
290 return autoSuggestSettingsFileName;
293 public void setAutoSuggestSettingsFileName(String autoSuggestSettingsFileName) {
294 this.autoSuggestSettingsFileName = autoSuggestSettingsFileName;
297 public String getAutoSuggestMappingsFileName() {
298 return autoSuggestMappingsFileName;
301 public void setAutoSuggestMappingsFileName(String autoSuggestMappingsFileName) {
302 this.autoSuggestMappingsFileName = autoSuggestMappingsFileName;