diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-05-25 13:32:48 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-05-31 21:30:56 +0200 |
commit | 05266f94881823d0c78a5a4f1a7cb905db8a8550 (patch) | |
tree | 542130d4ed812d0468f627b7392ded9f6c852351 /server/sonar-search | |
parent | 7767037eb95e5e3c807ffdffbdfe8b7ee68f9e1a (diff) | |
download | sonarqube-05266f94881823d0c78a5a4f1a7cb905db8a8550.tar.gz sonarqube-05266f94881823d0c78a5a4f1a7cb905db8a8550.zip |
SONAR-7653 upgrade to Elasticsearch 2.3.3
Diffstat (limited to 'server/sonar-search')
5 files changed, 50 insertions, 37 deletions
diff --git a/server/sonar-search/pom.xml b/server/sonar-search/pom.xml index c006f179e25..d155517a242 100644 --- a/server/sonar-search/pom.xml +++ b/server/sonar-search/pom.xml @@ -24,6 +24,10 @@ <artifactId>elasticsearch</artifactId> </dependency> <dependency> + <groupId>net.java.dev.jna</groupId> + <artifactId>jna</artifactId> + </dependency> + <dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> <scope>provided</scope> diff --git a/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java b/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java index 50802429918..950afcfbc76 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java +++ b/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java @@ -20,13 +20,14 @@ package org.sonar.search; import java.io.File; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Set; import java.util.TreeSet; import org.apache.commons.lang.StringUtils; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,7 +73,7 @@ public class EsSettings implements EsSettingsMBean { } Settings build() { - ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder(); + Settings.Builder builder = Settings.builder(); configureFileSystem(builder); configureIndexDefaults(builder); configureNetwork(builder); @@ -81,10 +82,9 @@ public class EsSettings implements EsSettingsMBean { return builder.build(); } - private void configureFileSystem(ImmutableSettings.Builder builder) { + private void configureFileSystem(Settings.Builder builder) { File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME); File dataDir; - File workDir; File logDir; // data dir @@ -96,15 +96,8 @@ public class EsSettings implements EsSettingsMBean { } builder.put("path.data", dataDir.getAbsolutePath()); - // working dir - String workPath = props.value(ProcessProperties.PATH_TEMP); - if (StringUtils.isNotEmpty(workPath)) { - workDir = new File(workPath); - } else { - workDir = new File(homeDir, "temp"); - } - builder.put("path.work", workDir.getAbsolutePath()); - builder.put("path.plugins", workDir.getAbsolutePath()); + String tempPath = props.value(ProcessProperties.PATH_TEMP); + builder.put("path.home", new File(tempPath, "es")); // log dir String logPath = props.value(ProcessProperties.PATH_LOGS); @@ -116,16 +109,16 @@ public class EsSettings implements EsSettingsMBean { builder.put("path.logs", logDir.getAbsolutePath()); } - private void configureNetwork(ImmutableSettings.Builder builder) { - // the following properties can't be null as default values are defined by app process - String host = props.nonNullValue(ProcessProperties.SEARCH_HOST); + private void configureNetwork(Settings.Builder builder) { + InetAddress host = readHost(); int port = Integer.parseInt(props.nonNullValue(ProcessProperties.SEARCH_PORT)); LOGGER.info("Elasticsearch listening on {}:{}", host, port); // disable multicast builder.put("discovery.zen.ping.multicast.enabled", "false"); builder.put("transport.tcp.port", port); - builder.put("transport.host", host); + builder.put("transport.host", host.getHostAddress()); + builder.put("network.host", host.getHostAddress()); // Elasticsearch sets the default value of TCP reuse address to true only on non-MSWindows machines, but why ? builder.put("network.tcp.reuse_address", true); @@ -140,12 +133,21 @@ public class EsSettings implements EsSettingsMBean { // see https://github.com/lmenezes/elasticsearch-kopf/issues/195 builder.put("http.cors.enabled", true); builder.put("http.enabled", true); - builder.put("http.host", host); + builder.put("http.host", host.getHostAddress()); builder.put("http.port", httpPort); } } - private static void configureIndexDefaults(ImmutableSettings.Builder builder) { + private InetAddress readHost() { + String hostProperty = props.nonNullValue(ProcessProperties.SEARCH_HOST); + try { + return InetAddress.getByName(hostProperty); + } catch (UnknownHostException e) { + throw new IllegalStateException("Can not resolve host [" + hostProperty + "]. Please check network settings and property " + ProcessProperties.SEARCH_HOST, e); + } + } + + private static void configureIndexDefaults(Settings.Builder builder) { builder .put("index.number_of_shards", "1") .put("index.refresh_interval", "30s") @@ -153,7 +155,7 @@ public class EsSettings implements EsSettingsMBean { .put("index.mapper.dynamic", false); } - private void configureCluster(ImmutableSettings.Builder builder) { + private void configureCluster(Settings.Builder builder) { int replicationFactor = 0; if (inCluster()) { replicationFactor = 1; @@ -178,7 +180,7 @@ public class EsSettings implements EsSettingsMBean { builder.put("node.name", nodeName); } - private void configureMarvel(ImmutableSettings.Builder builder) { + private void configureMarvel(Settings.Builder builder) { Set<String> marvels = new TreeSet<>(); marvels.addAll(Arrays.asList(StringUtils.split(props.value(PROP_MARVEL_HOSTS, ""), ","))); diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java index 899ab6891b8..f21987fb994 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java +++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java @@ -19,9 +19,11 @@ */ package org.sonar.search; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; +import org.apache.lucene.util.StringHelper; +import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.node.internal.InternalNode; +import org.elasticsearch.node.Node; +import org.elasticsearch.node.NodeBuilder; import org.sonar.process.Jmx; import org.sonar.process.MinimumViableSystem; import org.sonar.process.Monitored; @@ -31,7 +33,7 @@ import org.sonar.process.Props; public class SearchServer implements Monitored { private final EsSettings settings; - private InternalNode node; + private Node node; public SearchServer(Props props) { this.settings = new EsSettings(props); @@ -42,10 +44,17 @@ public class SearchServer implements Monitored { @Override public void start() { Jmx.register(EsSettingsMBean.OBJECT_NAME, settings); - node = new InternalNode(settings.build(), false); + initBootstrap(); + node = NodeBuilder.nodeBuilder().settings(settings.build()).build(); node.start(); } + // copied from https://github.com/elastic/elasticsearch/blob/v2.3.3/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java + private void initBootstrap() { + // init lucene random seed. it will use /dev/urandom where available: + StringHelper.randomId(); + } + @Override public boolean isUp() { return node != null && node.client().admin().cluster().prepareHealth() diff --git a/server/sonar-search/src/test/java/org/sonar/search/EsSettingsTest.java b/server/sonar-search/src/test/java/org/sonar/search/EsSettingsTest.java index f8f12f25272..35fd0c236ef 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/EsSettingsTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/EsSettingsTest.java @@ -19,6 +19,9 @@ */ package org.sonar.search; +import java.io.File; +import java.io.IOException; +import java.util.Properties; import org.elasticsearch.common.settings.Settings; import org.junit.Rule; import org.junit.Test; @@ -27,10 +30,6 @@ import org.sonar.process.MessageException; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; -import java.io.File; -import java.io.IOException; -import java.util.Properties; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -60,7 +59,7 @@ public class EsSettingsTest { assertThat(generated.get("path.data")).isNotNull(); assertThat(generated.get("path.logs")).isNotNull(); - assertThat(generated.get("path.work")).isNotNull(); + assertThat(generated.get("path.home")).isNotNull(); // http is disabled for security reasons assertThat(generated.get("http.enabled")).isEqualTo("false"); @@ -98,7 +97,7 @@ public class EsSettingsTest { assertThat(settings.get("path.data")).isEqualTo(new File(dataDir, "es").getAbsolutePath()); assertThat(settings.get("path.logs")).isEqualTo(logDir.getAbsolutePath()); - assertThat(settings.get("path.work")).isEqualTo(tempDir.getAbsolutePath()); + assertThat(settings.get("path.home")).isEqualTo(new File(tempDir, "es").getAbsolutePath()); } @Test diff --git a/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java b/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java index ebf7e106f4b..8b63fb52eb4 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java @@ -21,11 +21,10 @@ package org.sonar.search; import java.net.InetAddress; import java.util.Properties; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.junit.After; @@ -72,8 +71,8 @@ public class SearchServerTest { public void start_stop_server() throws Exception { Props props = new Props(new Properties()); // the following properties have always default values (see ProcessProperties) - String host = InetAddress.getLocalHost().getHostAddress(); - props.set(ProcessProperties.SEARCH_HOST, host); + InetAddress host = InetAddress.getLocalHost(); + props.set(ProcessProperties.SEARCH_HOST, host.getHostAddress()); props.set(ProcessProperties.SEARCH_PORT, String.valueOf(port)); props.set(ProcessProperties.CLUSTER_NAME, CLUSTER_NAME); props.set(ProcessProperties.CLUSTER_NODE_NAME, "test"); @@ -84,8 +83,8 @@ public class SearchServerTest { searchServer.start(); assertThat(searchServer.isUp()).isTrue(); - Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", CLUSTER_NAME).build(); - client = new TransportClient(settings) + Settings settings = Settings.builder().put("cluster.name", CLUSTER_NAME).build(); + client = TransportClient.builder().settings(settings).build() .addTransportAddress(new InetSocketTransportAddress(host, port)); assertThat(client.admin().cluster().prepareClusterStats().get().getStatus()).isEqualTo(ClusterHealthStatus.GREEN); |