diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-03-16 23:01:11 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-03-25 09:58:44 +0100 |
commit | 6bc55b17ebd87802cb9b55d5b6625e1a935f3909 (patch) | |
tree | 0a50457cc294c211ad7a3ee081dabb93e4231286 /server/sonar-search | |
parent | 4250bb53f050b5a7f86b211ec2b34f85f7cc3ddc (diff) | |
download | sonarqube-6bc55b17ebd87802cb9b55d5b6625e1a935f3909.tar.gz sonarqube-6bc55b17ebd87802cb9b55d5b6625e1a935f3909.zip |
SONAR-7436 Monitoring of CE process in system WS and console
Diffstat (limited to 'server/sonar-search')
-rw-r--r-- | server/sonar-search/src/main/java/org/sonar/search/EsSettings.java (renamed from server/sonar-search/src/main/java/org/sonar/search/SearchSettings.java) | 35 | ||||
-rw-r--r-- | server/sonar-search/src/main/java/org/sonar/search/SearchServer.java | 8 | ||||
-rw-r--r-- | server/sonar-search/src/test/java/org/sonar/search/EsSettingsTest.java (renamed from server/sonar-search/src/test/java/org/sonar/search/SearchSettingsTest.java) | 30 | ||||
-rw-r--r-- | server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java | 7 |
4 files changed, 51 insertions, 29 deletions
diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchSettings.java b/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java index db634f5c587..2f0986e1e45 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchSettings.java +++ b/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java @@ -33,17 +33,18 @@ import org.slf4j.LoggerFactory; import org.sonar.process.MessageException; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; +import org.sonar.process.jmx.EsSettingsMBean; -class SearchSettings { +public class EsSettings implements EsSettingsMBean { - private static final Logger LOGGER = LoggerFactory.getLogger(SearchSettings.class); + private static final Logger LOGGER = LoggerFactory.getLogger(EsSettings.class); public static final String PROP_MARVEL_HOSTS = "sonar.search.marvelHosts"; private final Props props; private final Set<String> masterHosts = new LinkedHashSet<>(); - SearchSettings(Props props) { + EsSettings(Props props) { this.props = props; masterHosts.addAll(Arrays.asList(StringUtils.split(props.value(ProcessProperties.CLUSTER_MASTER_HOST, ""), ","))); } @@ -56,6 +57,21 @@ class SearchSettings { return props.valueAsBoolean(ProcessProperties.CLUSTER_MASTER, false); } + @Override + public int getHttpPort() { + return props.valueAsInt(ProcessProperties.SEARCH_HTTP_PORT, -1); + } + + @Override + public String getClusterName() { + return props.value(ProcessProperties.CLUSTER_NAME); + } + + @Override + public String getNodeName() { + return props.value(ProcessProperties.CLUSTER_NODE_NAME); + } + Settings build() { ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder(); configureFileSystem(builder); @@ -115,8 +131,8 @@ class SearchSettings { // 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); - Integer httpPort = props.valueAsInt(ProcessProperties.SEARCH_HTTP_PORT); - if (httpPort == null || httpPort < 0) { + int httpPort = getHttpPort(); + if (httpPort < 0) { // standard configuration builder.put("http.enabled", false); } else { @@ -130,7 +146,7 @@ class SearchSettings { } } - private void configureIndexDefaults(ImmutableSettings.Builder builder) { + private static void configureIndexDefaults(ImmutableSettings.Builder builder) { builder .put("index.number_of_shards", "1") .put("index.refresh_interval", "30s") @@ -156,10 +172,11 @@ class SearchSettings { } } builder.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicationFactor); - builder.put("cluster.name", props.value(ProcessProperties.CLUSTER_NAME)); + builder.put("cluster.name", getClusterName()); builder.put("cluster.routing.allocation.awareness.attributes", "rack_id"); - builder.put("node.rack_id", props.value(ProcessProperties.CLUSTER_NODE_NAME, "unknown")); - builder.put("node.name", props.value(ProcessProperties.CLUSTER_NODE_NAME)); + String nodeName = getNodeName(); + builder.put("node.rack_id", nodeName); + builder.put("node.name", nodeName); } private void configureMarvel(ImmutableSettings.Builder builder) { 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 0a7939abedf..31541ad259f 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 @@ -26,14 +26,16 @@ import org.sonar.process.MinimumViableSystem; import org.sonar.process.Monitored; import org.sonar.process.ProcessEntryPoint; import org.sonar.process.Props; +import org.sonar.process.jmx.EsSettingsMBean; +import org.sonar.process.jmx.Jmx; public class SearchServer implements Monitored { - private final SearchSettings settings; + private final EsSettings settings; private InternalNode node; public SearchServer(Props props) { - this.settings = new SearchSettings(props); + this.settings = new EsSettings(props); new MinimumViableSystem() .checkJavaVersion() .checkWritableTempDir(); @@ -41,6 +43,7 @@ public class SearchServer implements Monitored { @Override public void start() { + Jmx.register(EsSettingsMBean.OBJECT_NAME, settings); node = new InternalNode(settings.build(), false); node.start(); } @@ -70,6 +73,7 @@ public class SearchServer implements Monitored { if (node != null && !node.isClosed()) { node.close(); } + Jmx.unregister(EsSettingsMBean.OBJECT_NAME); } public static void main(String... args) { diff --git a/server/sonar-search/src/test/java/org/sonar/search/SearchSettingsTest.java b/server/sonar-search/src/test/java/org/sonar/search/EsSettingsTest.java index 607eab9d92e..f8f12f25272 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/SearchSettingsTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/EsSettingsTest.java @@ -34,7 +34,7 @@ import java.util.Properties; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -public class SearchSettingsTest { +public class EsSettingsTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); @@ -49,10 +49,10 @@ public class SearchSettingsTest { props.set(ProcessProperties.CLUSTER_NAME, "tests"); props.set(ProcessProperties.CLUSTER_NODE_NAME, "test"); - SearchSettings searchSettings = new SearchSettings(props); - assertThat(searchSettings.inCluster()).isFalse(); + EsSettings esSettings = new EsSettings(props); + assertThat(esSettings.inCluster()).isFalse(); - Settings generated = searchSettings.build(); + Settings generated = esSettings.build(); assertThat(generated.get("transport.tcp.port")).isEqualTo("1234"); assertThat(generated.get("transport.host")).isEqualTo("127.0.0.1"); assertThat(generated.get("cluster.name")).isEqualTo("tests"); @@ -74,10 +74,10 @@ public class SearchSettingsTest { public void test_default_hosts() throws Exception { Props props = minProps(); - SearchSettings searchSettings = new SearchSettings(props); - assertThat(searchSettings.inCluster()).isFalse(); + EsSettings esSettings = new EsSettings(props); + assertThat(esSettings.inCluster()).isFalse(); - Settings generated = searchSettings.build(); + Settings generated = esSettings.build(); assertThat(generated.get("transport.tcp.port")).isEqualTo("9001"); assertThat(generated.get("transport.host")).isEqualTo("127.0.0.1"); assertThat(generated.get("cluster.name")).isEqualTo("sonarqube"); @@ -94,7 +94,7 @@ public class SearchSettingsTest { props.set(ProcessProperties.PATH_LOGS, logDir.getAbsolutePath()); props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - Settings settings = new SearchSettings(props).build(); + Settings settings = new EsSettings(props).build(); assertThat(settings.get("path.data")).isEqualTo(new File(dataDir, "es").getAbsolutePath()); assertThat(settings.get("path.logs")).isEqualTo(logDir.getAbsolutePath()); @@ -106,7 +106,7 @@ public class SearchSettingsTest { Props props = minProps(); props.set(ProcessProperties.CLUSTER_ACTIVATE, "true"); props.set(ProcessProperties.CLUSTER_MASTER, "true"); - Settings settings = new SearchSettings(props).build(); + Settings settings = new EsSettings(props).build(); assertThat(settings.get("index.number_of_replicas")).isEqualTo("1"); assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isNull(); @@ -118,7 +118,7 @@ public class SearchSettingsTest { Props props = minProps(); props.set(ProcessProperties.CLUSTER_ACTIVATE, "true"); props.set(ProcessProperties.CLUSTER_MASTER_HOST, "127.0.0.2,127.0.0.3"); - Settings settings = new SearchSettings(props).build(); + Settings settings = new EsSettings(props).build(); assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isEqualTo("127.0.0.2,127.0.0.3"); assertThat(settings.get("node.master")).isEqualTo("false"); @@ -129,7 +129,7 @@ public class SearchSettingsTest { Props props = minProps(); props.set(ProcessProperties.CLUSTER_ACTIVATE, "true"); try { - new SearchSettings(props).build(); + new EsSettings(props).build(); fail(); } catch (MessageException ignored) { // expected @@ -139,8 +139,8 @@ public class SearchSettingsTest { @Test public void enable_marvel() throws Exception { Props props = minProps(); - props.set(SearchSettings.PROP_MARVEL_HOSTS, "127.0.0.2,127.0.0.3"); - Settings settings = new SearchSettings(props).build(); + props.set(EsSettings.PROP_MARVEL_HOSTS, "127.0.0.2,127.0.0.3"); + Settings settings = new EsSettings(props).build(); assertThat(settings.get("marvel.agent.exporter.es.hosts")).isEqualTo("127.0.0.2,127.0.0.3"); } @@ -149,7 +149,7 @@ public class SearchSettingsTest { public void enable_http_connector() throws Exception { Props props = minProps(); props.set(ProcessProperties.SEARCH_HTTP_PORT, "9010"); - Settings settings = new SearchSettings(props).build(); + Settings settings = new EsSettings(props).build(); assertThat(settings.get("http.port")).isEqualTo("9010"); assertThat(settings.get("http.host")).isEqualTo("127.0.0.1"); @@ -161,7 +161,7 @@ public class SearchSettingsTest { Props props = minProps(); props.set(ProcessProperties.SEARCH_HTTP_PORT, "9010"); props.set(ProcessProperties.SEARCH_HOST, "127.0.0.2"); - Settings settings = new SearchSettings(props).build(); + Settings settings = new EsSettings(props).build(); assertThat(settings.get("http.port")).isEqualTo("9010"); assertThat(settings.get("http.host")).isEqualTo("127.0.0.2"); 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 5ce6cf13a0b..ebf7e106f4b 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 @@ -19,6 +19,8 @@ */ 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; @@ -34,12 +36,10 @@ import org.junit.rules.TemporaryFolder; import org.junit.rules.TestRule; import org.junit.rules.Timeout; import org.sonar.process.NetworkUtils; +import org.sonar.process.ProcessEntryPoint; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; -import java.net.InetAddress; -import java.util.Properties; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -78,6 +78,7 @@ public class SearchServerTest { props.set(ProcessProperties.CLUSTER_NAME, CLUSTER_NAME); props.set(ProcessProperties.CLUSTER_NODE_NAME, "test"); props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); + props.set(ProcessEntryPoint.PROPERTY_SHARED_PATH, temp.newFolder().getAbsolutePath()); searchServer = new SearchServer(props); searchServer.start(); |