001/* 002 * (C) Copyright 2014 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.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XObject; 027import org.nuxeo.runtime.api.Framework; 028 029/** 030 * XMap descriptor used to configure a local in JVM Elasticsearch instance 031 */ 032@XObject(value = "elasticSearchLocal") 033public class ElasticSearchLocalConfig implements Serializable { 034 035 private static final long serialVersionUID = 1L; 036 037 @XNode("@enabled") 038 protected boolean isEnabled = true; 039 040 @XNode("@clusterName") 041 protected String clusterName; 042 043 @XNode("@nodeName") 044 protected String nodeName = "Nuxeo"; 045 046 @XNode("@pathData") 047 protected String dataPath; 048 049 @XNode("@indexStoreType") 050 protected String indexStoreType; 051 052 @XNode("@httpEnabled") 053 protected boolean httpEnabled = false; 054 055 @XNode("@httpPort") 056 protected String httpPort = "9200"; 057 058 @XNode("@networkHost") 059 protected String networkHost = "127.0.0.1"; 060 061 // @since 8.3 062 @XNode("@useExternalVersion") 063 protected boolean externalVersion = true; 064 065 public String getClusterName() { 066 return clusterName; 067 } 068 069 public String getDataPath() { 070 if (dataPath == null) { 071 File dir = new File(Framework.getRuntime().getHome(), "data/elasticsearch"); 072 dataPath = dir.getPath(); 073 } 074 return dataPath; 075 } 076 077 public String getIndexStorageType() { 078 if (indexStoreType == null) { 079 if (Framework.isTestModeSet()) { 080 indexStoreType = "memory"; 081 } else { 082 indexStoreType = "mmapfs"; 083 } 084 } 085 return indexStoreType; 086 } 087 088 /** 089 * @since 7.4 090 */ 091 public String getNetworkHost() { 092 return networkHost; 093 } 094 095 public String getNodeName() { 096 return nodeName; 097 } 098 099 public boolean httpEnabled() { 100 return httpEnabled; 101 } 102 103 public boolean isEnabled() { 104 return isEnabled; 105 } 106 107 public void setClusterName(String clusterName) { 108 this.clusterName = clusterName; 109 } 110 111 public void setDataPath(String dataPath) { 112 this.dataPath = dataPath; 113 } 114 115 public void setEnabled(boolean isEnabled) { 116 this.isEnabled = isEnabled; 117 } 118 119 public void setHttpEnabled(boolean httpEnabled) { 120 this.httpEnabled = httpEnabled; 121 } 122 123 public void setIndexStorageType(String indexStorageType) { 124 this.indexStoreType = indexStorageType; 125 } 126 127 /** 128 * @since 7.4 129 */ 130 public void setNetworkHost(String networkHost) { 131 this.networkHost = networkHost; 132 } 133 134 public void setNodeName(String nodeName) { 135 this.nodeName = nodeName; 136 } 137 138 public boolean useExternalVersion() { 139 return externalVersion; 140 } 141 142 @Override 143 public String toString() { 144 if (isEnabled()) { 145 return String.format("EsLocalConfig(%s, %s, %s, %s)", getClusterName(), getDataPath(), httpEnabled(), 146 getIndexStorageType()); 147 } 148 return "EsLocalConfig disabled"; 149 } 150 151 public String getHttpPort() { 152 return httpPort; 153 } 154}