001/* 002 * (C) Copyright 2014-2016 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bdelbosc 018 */ 019 020package org.nuxeo.elasticsearch.config; 021 022import java.io.File; 023import java.io.Serializable; 024 025import org.nuxeo.common.Environment; 026import org.nuxeo.common.xmap.annotation.XNode; 027import org.nuxeo.common.xmap.annotation.XObject; 028import org.nuxeo.runtime.api.Framework; 029 030/** 031 * Configuration of an embedded (same JVM as Nuxeo) Elasticsearch server. 032 */ 033@XObject(value = "elasticSearchEmbeddedServer") 034public class ElasticSearchEmbeddedServerConfig implements Serializable { 035 036 private static final long serialVersionUID = 1L; 037 038 @XNode("@enabled") 039 protected boolean isEnabled = true; 040 041 @XNode("@clusterName") 042 protected String clusterName; 043 044 @XNode("@nodeName") 045 protected String nodeName = "Nuxeo"; 046 047 // @since 8.4 048 @XNode("@pathHome") 049 private String homePath; 050 051 @XNode("@pathData") 052 protected String dataPath; 053 054 @XNode("@indexStoreType") 055 protected String indexStoreType; 056 057 @XNode("@httpEnabled") 058 protected boolean httpEnabled = false; 059 060 @XNode("@httpPort") 061 protected String httpPort = "9200"; 062 063 @XNode("@networkHost") 064 protected String networkHost = "127.0.0.1"; 065 066 // @since 8.3 067 @XNode("@useExternalVersion") 068 protected boolean externalVersion = true; 069 070 public String getClusterName() { 071 return clusterName; 072 } 073 074 public void setClusterName(String clusterName) { 075 this.clusterName = clusterName; 076 } 077 078 /** 079 * @since 8.4 080 */ 081 public String getHomePath() { 082 if (homePath == null) { 083 // Since ES 2.X we need to set a home path for embedded node, but it is not used by the bundle 084 File dir = new File(Environment.getDefault().getTemp(), "elasticsearch"); 085 homePath = dir.getPath(); 086 } 087 return homePath; 088 } 089 090 /** 091 * @since 8.4 092 */ 093 public void setHomePath(String homePath) { 094 this.homePath = homePath; 095 } 096 097 public String getDataPath() { 098 if (dataPath == null) { 099 File dir = new File(Framework.getRuntime().getHome(), "data/elasticsearch"); 100 dataPath = dir.getPath(); 101 } 102 return dataPath; 103 } 104 105 public void setDataPath(String dataPath) { 106 this.dataPath = dataPath; 107 } 108 109 public String getIndexStorageType() { 110 if (indexStoreType == null) { 111 indexStoreType = "mmapfs"; 112 } 113 return indexStoreType; 114 } 115 116 public void setIndexStorageType(String indexStorageType) { 117 this.indexStoreType = indexStorageType; 118 } 119 120 /** 121 * @since 7.4 122 */ 123 public String getNetworkHost() { 124 return networkHost; 125 } 126 127 /** 128 * @since 7.4 129 */ 130 public void setNetworkHost(String networkHost) { 131 this.networkHost = networkHost; 132 } 133 134 public String getNodeName() { 135 return nodeName; 136 } 137 138 public void setNodeName(String nodeName) { 139 this.nodeName = nodeName; 140 } 141 142 public boolean httpEnabled() { 143 return httpEnabled; 144 } 145 146 public boolean isEnabled() { 147 return isEnabled; 148 } 149 150 public void setEnabled(boolean isEnabled) { 151 this.isEnabled = isEnabled; 152 } 153 154 public void setHttpEnabled(boolean httpEnabled) { 155 this.httpEnabled = httpEnabled; 156 } 157 158 public boolean useExternalVersion() { 159 return externalVersion; 160 } 161 162 @Override 163 public String toString() { 164 if (isEnabled()) { 165 return String.format("EsLocalConfig(%s, %s, %s, %s)", getClusterName(), getDataPath(), httpEnabled(), 166 getIndexStorageType()); 167 } 168 return "EsLocalConfig disabled"; 169 } 170 171 public String getHttpPort() { 172 return httpPort; 173 } 174}