summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <dpursehouse@collab.net>2018-07-02 10:38:43 +0900
committerDavid Pursehouse <dpursehouse@collab.net>2018-07-02 10:38:43 +0900
commitb6034ed80c06ae1939d754e72fec04d2225bd16f (patch)
tree89e5230eb6bccf49a295333a7fc87f94ab2d0c13
parent150d965e43e2ff9b9bde71c9feb29c4c9fbf06a9 (diff)
ElasticConfiguration: Make hosts private
Make the hosts member private and add a getter method. Move conversion of the List to Array to this method. In ElasticRestClientProvider, rather than keeping each used configuration item as a member, keep the configuration and get each value from it as needed. This will avoid having to add a new member for any new configs that are added in future. Change-Id: I711a53e90d59bb348a974872851856491755fb87
-rw-r--r--gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticConfiguration.java6
-rw-r--r--gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticRestClientProvider.java14
2 files changed, 10 insertions, 10 deletions
diff --git a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticConfiguration.java b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticConfiguration.java
index 1768e15b1c..6b2fa130db 100644
--- a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticConfiguration.java
+++ b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticConfiguration.java
@@ -38,8 +38,8 @@ class ElasticConfiguration {
private static final String DEFAULT_PROTOCOL = "http";
private final Config cfg;
+ private final List<HttpHost> hosts;
- final List<HttpHost> hosts;
final String username;
final String password;
final boolean requestCompression;
@@ -89,6 +89,10 @@ class ElasticConfiguration {
return cfg;
}
+ HttpHost[] getHosts() {
+ return hosts.toArray(new HttpHost[hosts.size()]);
+ }
+
String getIndexName(String name, int schemaVersion) {
return String.format("%s%s_%04d", prefix, name, schemaVersion);
}
diff --git a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticRestClientProvider.java b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticRestClientProvider.java
index d7e1bd765a..f7580bd136 100644
--- a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticRestClientProvider.java
+++ b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticRestClientProvider.java
@@ -21,8 +21,6 @@ import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
-import java.util.List;
-import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.auth.AuthScope;
@@ -40,18 +38,14 @@ import org.slf4j.LoggerFactory;
class ElasticRestClientProvider implements Provider<RestClient>, LifecycleListener {
private static final Logger log = LoggerFactory.getLogger(ElasticRestClientProvider.class);
- private final List<HttpHost> hosts;
- private final String username;
- private final String password;
+ private final ElasticConfiguration cfg;
private RestClient client;
private ElasticQueryAdapter adapter;
@Inject
ElasticRestClientProvider(ElasticConfiguration cfg) {
- hosts = cfg.hosts;
- username = cfg.username;
- password = cfg.password;
+ this.cfg = cfg;
}
public static LifecycleModule module() {
@@ -133,12 +127,14 @@ class ElasticRestClientProvider implements Provider<RestClient>, LifecycleListen
}
private RestClient build() {
- RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()]));
+ RestClientBuilder builder = RestClient.builder(cfg.getHosts());
setConfiguredCredentialsIfAny(builder);
return builder.build();
}
private void setConfiguredCredentialsIfAny(RestClientBuilder builder) {
+ String username = cfg.username;
+ String password = cfg.password;
if (username != null && password != null) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(