Merge branch 'stable-2.15'
* stable-2.15: GroupField: Change UUID fields' type to KEYWORD Add keyword type to index type system Elasticsearch: Encapsulate supported versions in an enum setup_gjf.sh: amend SHA1 for GJF 1.6 Elasticsearch: Tidy up Javadoc in builders package setup_gjf.sh: Add support for google-java-format 1.6 ElasticRestClientProvider: Detect Elasticsearch version Convert ElasticRestClientBuilder to a provider WorkQueue: rename prefix to queueName Remove outdated Elasticsearch/Lucene comments from WORKSPACE AbstractElasticIndex: Move generation of index name to ElasticConfiguration ElasticProjectIndex is adapted to the changes done in: - Ie4696b4d5 (AbstractElasticIndex: Move generation of index name to ElasticConfiguration) - I4747114e2 (Convert ElasticRestClientBuilder to a provider) Change-Id: I5ee243cb696c5e3e14b8c881950eb27000efce5c
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -32,6 +33,8 @@ class ElasticConfiguration {
|
||||
private static final String DEFAULT_PORT = "9200";
|
||||
private static final String DEFAULT_PROTOCOL = "http";
|
||||
|
||||
private final Config cfg;
|
||||
|
||||
final List<HttpHost> urls;
|
||||
final String username;
|
||||
final String password;
|
||||
@@ -41,9 +44,11 @@ class ElasticConfiguration {
|
||||
final TimeUnit maxConnectionIdleUnit = TimeUnit.MILLISECONDS;
|
||||
final int maxTotalConnection;
|
||||
final int readTimeout;
|
||||
final String prefix;
|
||||
|
||||
@Inject
|
||||
ElasticConfiguration(@GerritServerConfig Config cfg) {
|
||||
this.cfg = cfg;
|
||||
this.username = cfg.getString("elasticsearch", null, "username");
|
||||
this.password = cfg.getString("elasticsearch", null, "password");
|
||||
this.requestCompression = cfg.getBoolean("elasticsearch", null, "requestCompression", false);
|
||||
@@ -55,6 +60,7 @@ class ElasticConfiguration {
|
||||
this.maxTotalConnection = cfg.getInt("elasticsearch", null, "maxTotalConnection", 1);
|
||||
this.readTimeout =
|
||||
(int) cfg.getTimeUnit("elasticsearch", null, "readTimeout", 3000, TimeUnit.MICROSECONDS);
|
||||
this.prefix = Strings.nullToEmpty(cfg.getString("elasticsearch", null, "prefix"));
|
||||
|
||||
Set<String> subsections = cfg.getSubsections("elasticsearch");
|
||||
if (subsections.isEmpty()) {
|
||||
@@ -74,6 +80,14 @@ class ElasticConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public String getIndexName(String name, int schemaVersion) {
|
||||
return String.format("%s%s_%04d", prefix, name, schemaVersion);
|
||||
}
|
||||
|
||||
private String getString(Config cfg, String subsection, String name, String defaultValue) {
|
||||
return MoreObjects.firstNonNull(cfg.getString("elasticsearch", subsection, name), defaultValue);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user