modify elasticsearch cluster name and context name

This commit is contained in:
Shinsuke Sugaya 2015-12-10 20:35:16 +09:00
parent fd1db29199
commit d0c07c343d
7 changed files with 32 additions and 33 deletions

View file

@ -71,7 +71,7 @@ JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8"
APP_NAME=fess
ES_HOME=$FESS_HOME/es
FESS_JAVA_OPTS="$FESS_JAVA_OPTS -Dfess.home=$FESS_HOME"
FESS_JAVA_OPTS="$FESS_JAVA_OPTS -Dfess.context.path=/$APP_NAME"
FESS_JAVA_OPTS="$FESS_JAVA_OPTS -Dfess.context.path=/"
FESS_JAVA_OPTS="$FESS_JAVA_OPTS -Dfess.port=8080"
FESS_JAVA_OPTS="$FESS_JAVA_OPTS -Dfess.webapp.path=$FESS_HOME/app"
FESS_JAVA_OPTS="$FESS_JAVA_OPTS -Dfess.temp.path=$FESS_HOME/temp"

View file

@ -97,7 +97,7 @@ public class FessBoot extends TomcatBoot {
if (value != null) {
return value;
}
return "/fess";
return "/";
}
protected static String getTomcatConfigPath() {

View file

@ -95,7 +95,7 @@ public class EsApiManager extends BaseApiManager {
protected void processRequest(final HttpServletRequest request, final HttpServletResponse response, final String path) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final Method httpMethod = Method.valueOf(request.getMethod().toUpperCase(Locale.ROOT));
final CurlRequest curlRequest = new CurlRequest(httpMethod, fessConfig.getElasticsearchUrl() + path);
final CurlRequest curlRequest = new CurlRequest(httpMethod, fessConfig.getElasticsearchHttpUrl() + path);
request.getParameterMap().entrySet().stream().forEach(entry -> {
if (entry.getValue().length > 1) {
curlRequest.param(entry.getKey(), String.join(",", entry.getValue()));

View file

@ -56,7 +56,7 @@ public class DictionaryManager {
public DictionaryFile<? extends DictionaryItem>[] getDictionaryFiles() {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
try (CurlResponse response =
Curl.get(fessConfig.getElasticsearchUrl() + "/_configsync/file").param("fields", "path,@timestamp").execute()) {
Curl.get(fessConfig.getElasticsearchHttpUrl() + "/_configsync/file").param("fields", "path,@timestamp").execute()) {
final Map<String, Object> contentMap = response.getContentAsMap();
@SuppressWarnings("unchecked")
final List<Map<String, Object>> fileList = (List<Map<String, Object>>) contentMap.get("file");
@ -102,7 +102,7 @@ public class DictionaryManager {
// TODO use stream
try (CurlResponse response =
Curl.post(fessConfig.getElasticsearchUrl() + "/_configsync/file").param("path", dictFile.getPath())
Curl.post(fessConfig.getElasticsearchHttpUrl() + "/_configsync/file").param("path", dictFile.getPath())
.body(FileUtil.readUTF8(file)).execute()) {
final Map<String, Object> contentMap = response.getContentAsMap();
if (!Constants.TRUE.equalsIgnoreCase(contentMap.get("acknowledged").toString())) {
@ -120,7 +120,7 @@ public class DictionaryManager {
public InputStream getContentInputStream(final DictionaryFile<? extends DictionaryItem> dictFile) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
try {
return Curl.get(fessConfig.getElasticsearchUrl() + "/_configsync/file").param("path", dictFile.getPath()).execute()
return Curl.get(fessConfig.getElasticsearchHttpUrl() + "/_configsync/file").param("path", dictFile.getPath()).execute()
.getContentAsStream();
} catch (final IOException e) {
throw new DictionaryException("Failed to access " + dictFile.getPath(), e);

View file

@ -176,8 +176,6 @@ public class FessEsClient implements Client {
protected Client client;
protected String clusterName = "fess";
protected Map<String, String> settings;
protected String indexConfigPath = "fess_indices";
@ -207,14 +205,6 @@ public class FessEsClient implements Client {
this.settings = settings;
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(final String clusterName) {
this.clusterName = clusterName;
}
public String getStatus() {
return admin().cluster().prepareHealth().execute().actionGet().getStatus().name();
}
@ -233,10 +223,8 @@ public class FessEsClient implements Client {
@PostConstruct
public void open() {
final String clusterNameValue = System.getProperty(Constants.FESS_ES_CLUSTER_NAME);
if (StringUtil.isNotBlank(clusterNameValue)) {
clusterName = clusterNameValue;
}
FessConfig fessConfig = ComponentUtil.getFessConfig();
final String transportAddressesValue = System.getProperty(Constants.FESS_ES_TRANSPORT_ADDRESSES);
if (StringUtil.isNotBlank(transportAddressesValue)) {
for (final String transportAddressValue : transportAddressesValue.split(",")) {
@ -257,7 +245,7 @@ public class FessEsClient implements Client {
if (transportAddressList.isEmpty()) {
if (runner == null) {
runner = new ElasticsearchClusterRunner();
final Configs config = newConfigs().clusterName(clusterName).numOfNode(1).useLogger();
final Configs config = newConfigs().clusterName(fessConfig.getElasticsearchClusterName()).numOfNode(1).useLogger();
final String esDir = System.getProperty("fess.es.dir");
if (esDir != null) {
config.basePath(esDir);
@ -279,7 +267,7 @@ public class FessEsClient implements Client {
addTransportAddress("localhost", runner.node().settings().getAsInt("transport.tcp.port", 9300));
} else {
final Builder settingsBuilder = Settings.settingsBuilder();
settingsBuilder.put("cluster.name", clusterName);
settingsBuilder.put("cluster.name", fessConfig.getElasticsearchClusterName());
final Settings settings = settingsBuilder.build();
final TransportClient transportClient = TransportClient.builder().settings(settings).build();
for (final TransportAddress address : transportAddressList) {
@ -288,10 +276,6 @@ public class FessEsClient implements Client {
client = transportClient;
}
if (StringUtil.isBlank(clusterNameValue)) {
System.setProperty(Constants.FESS_ES_CLUSTER_NAME, clusterName);
}
if (StringUtil.isBlank(transportAddressesValue)) {
final StringBuilder buf = new StringBuilder();
for (final TransportAddress transportAddress : transportAddressList) {

View file

@ -25,8 +25,11 @@ public interface FessConfig extends FessEnv {
/** The key of the configuration. e.g. Fess */
String DOMAIN_TITLE = "domain.title";
/** The key of the configuration. e.g. elasticsearch */
String ELASTICSEARCH_CLUSTER_NAME = "elasticsearch.cluster.name";
/** The key of the configuration. e.g. http://localhost:9201 */
String ELASTICSEARCH_URL = "elasticsearch.url";
String ELASTICSEARCH_HTTP_URL = "elasticsearch.http.url";
/** The key of the configuration. e.g. false */
String CRAWLER_DOCUMENT_CACHE_ENABLE = "crawler.document.cache.enable";
@ -311,12 +314,19 @@ public interface FessConfig extends FessEnv {
String getDomainTitle();
/**
* Get the value for the key 'elasticsearch.url'. <br>
* The value is, e.g. http://localhost:9201 <br>
* Get the value for the key 'elasticsearch.cluster.name'. <br>
* The value is, e.g. elasticsearch <br>
* comment: elasticsearch
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getElasticsearchUrl();
String getElasticsearchClusterName();
/**
* Get the value for the key 'elasticsearch.http.url'. <br>
* The value is, e.g. http://localhost:9201 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getElasticsearchHttpUrl();
/**
* Get the value for the key 'crawler.document.cache.enable'. <br>
@ -1109,8 +1119,12 @@ public interface FessConfig extends FessEnv {
return get(FessConfig.DOMAIN_TITLE);
}
public String getElasticsearchUrl() {
return get(FessConfig.ELASTICSEARCH_URL);
public String getElasticsearchClusterName() {
return get(FessConfig.ELASTICSEARCH_CLUSTER_NAME);
}
public String getElasticsearchHttpUrl() {
return get(FessConfig.ELASTICSEARCH_HTTP_URL);
}
public String getCrawlerDocumentCacheEnable() {

View file

@ -9,7 +9,8 @@
domain.title = Fess
# elasticsearch
elasticsearch.url=http://localhost:9201
elasticsearch.cluster.name=elasticsearch
elasticsearch.http.url=http://localhost:9201
# ========================================================================================
# Index