001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * bdelbosc 016 */ 017 018package org.nuxeo.elasticsearch.config; 019 020import java.io.File; 021import java.io.Serializable; 022 023import org.nuxeo.common.xmap.annotation.XNode; 024import org.nuxeo.common.xmap.annotation.XObject; 025import org.nuxeo.runtime.api.Framework; 026 027/** 028 * XMap descriptor used to configure a local in JVM Elasticsearch instance 029 */ 030@XObject(value = "elasticSearchLocal") 031public class ElasticSearchLocalConfig implements Serializable { 032 033 private static final long serialVersionUID = 1L; 034 035 @XNode("@enabled") 036 protected boolean isEnabled = true; 037 038 @XNode("@clusterName") 039 protected String clusterName; 040 041 @XNode("@nodeName") 042 protected String nodeName = "Nuxeo"; 043 044 @XNode("@pathData") 045 protected String dataPath; 046 047 @XNode("@indexStoreType") 048 protected String indexStoreType; 049 050 @XNode("@httpEnabled") 051 protected boolean httpEnabled = false; 052 053 @XNode("@networkHost") 054 protected String networkHost = "127.0.0.1"; 055 056 public String getClusterName() { 057 return clusterName; 058 } 059 060 public String getDataPath() { 061 if (dataPath == null) { 062 File dir = new File(Framework.getRuntime().getHome(), "data/elasticsearch"); 063 dataPath = dir.getPath(); 064 } 065 return dataPath; 066 } 067 068 public String getIndexStorageType() { 069 if (indexStoreType == null) { 070 if (Framework.isTestModeSet()) { 071 indexStoreType = "memory"; 072 } else { 073 indexStoreType = "mmapfs"; 074 } 075 } 076 return indexStoreType; 077 } 078 079 /** 080 * @since 7.4 081 */ 082 public String getNetworkHost() { 083 return networkHost; 084 } 085 086 public String getNodeName() { 087 return nodeName; 088 } 089 090 public boolean httpEnabled() { 091 return httpEnabled; 092 } 093 094 public boolean isEnabled() { 095 return isEnabled; 096 } 097 098 public void setClusterName(String clusterName) { 099 this.clusterName = clusterName; 100 } 101 102 public void setDataPath(String dataPath) { 103 this.dataPath = dataPath; 104 } 105 106 public void setEnabled(boolean isEnabled) { 107 this.isEnabled = isEnabled; 108 } 109 110 public void setHttpEnabled(boolean httpEnabled) { 111 this.httpEnabled = httpEnabled; 112 } 113 114 public void setIndexStorageType(String indexStorageType) { 115 this.indexStoreType = indexStorageType; 116 } 117 118 /** 119 * @since 7.4 120 */ 121 public void setNetworkHost(String networkHost) { 122 this.networkHost = networkHost; 123 } 124 125 public void setNodeName(String nodeName) { 126 this.nodeName = nodeName; 127 } 128 129 @Override 130 public String toString() { 131 if (isEnabled()) { 132 return String.format("EsLocalConfig(%s, %s, %s, %s)", getClusterName(), getDataPath(), httpEnabled(), 133 getIndexStorageType()); 134 } 135 return "EsLocalConfig disabled"; 136 } 137}