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("@networkHost") 056 protected String networkHost = "127.0.0.1"; 057 058 public String getClusterName() { 059 return clusterName; 060 } 061 062 public String getDataPath() { 063 if (dataPath == null) { 064 File dir = new File(Framework.getRuntime().getHome(), "data/elasticsearch"); 065 dataPath = dir.getPath(); 066 } 067 return dataPath; 068 } 069 070 public String getIndexStorageType() { 071 if (indexStoreType == null) { 072 if (Framework.isTestModeSet()) { 073 indexStoreType = "memory"; 074 } else { 075 indexStoreType = "mmapfs"; 076 } 077 } 078 return indexStoreType; 079 } 080 081 /** 082 * @since 7.4 083 */ 084 public String getNetworkHost() { 085 return networkHost; 086 } 087 088 public String getNodeName() { 089 return nodeName; 090 } 091 092 public boolean httpEnabled() { 093 return httpEnabled; 094 } 095 096 public boolean isEnabled() { 097 return isEnabled; 098 } 099 100 public void setClusterName(String clusterName) { 101 this.clusterName = clusterName; 102 } 103 104 public void setDataPath(String dataPath) { 105 this.dataPath = dataPath; 106 } 107 108 public void setEnabled(boolean isEnabled) { 109 this.isEnabled = isEnabled; 110 } 111 112 public void setHttpEnabled(boolean httpEnabled) { 113 this.httpEnabled = httpEnabled; 114 } 115 116 public void setIndexStorageType(String indexStorageType) { 117 this.indexStoreType = indexStorageType; 118 } 119 120 /** 121 * @since 7.4 122 */ 123 public void setNetworkHost(String networkHost) { 124 this.networkHost = networkHost; 125 } 126 127 public void setNodeName(String nodeName) { 128 this.nodeName = nodeName; 129 } 130 131 @Override 132 public String toString() { 133 if (isEnabled()) { 134 return String.format("EsLocalConfig(%s, %s, %s, %s)", getClusterName(), getDataPath(), httpEnabled(), 135 getIndexStorageType()); 136 } 137 return "EsLocalConfig disabled"; 138 } 139}