diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2020-01-09 16:48:01 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-11-05 20:06:21 +0000 |
commit | 8bcd89e733ce3dca9fef142a0db047a8f8dfd0ac (patch) | |
tree | 36f907ac89fce95b725ddc29be9e29e3d151bd35 /server/sonar-main | |
parent | eef81386c2ad2756cdb7a493d84f423ff7596e0f (diff) | |
download | sonarqube-8bcd89e733ce3dca9fef142a0db047a8f8dfd0ac.tar.gz sonarqube-8bcd89e733ce3dca9fef142a0db047a8f8dfd0ac.zip |
SONAR-12686 fix ES discovery settings in cluster mode
deprecated "discovery.zen.ping.unicast.hosts" has been removed, "discovery.seed_hosts" should be used instead
"discovery.zen.minimum_master_nodes" is ignored now: stop setting it and drop sonar property "sonar.search.minimumMasterNodes"
Diffstat (limited to 'server/sonar-main')
-rw-r--r-- | server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java | 6 | ||||
-rw-r--r-- | server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java | 37 |
2 files changed, 8 insertions, 35 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java index a8191531978..78a20cf6d6d 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java @@ -38,7 +38,6 @@ import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS; import static org.sonar.process.ProcessProperties.Property.SEARCH_HOST; import static org.sonar.process.ProcessProperties.Property.SEARCH_HTTP_PORT; import static org.sonar.process.ProcessProperties.Property.SEARCH_INITIAL_STATE_TIMEOUT; -import static org.sonar.process.ProcessProperties.Property.SEARCH_MINIMUM_MASTER_NODES; import static org.sonar.process.ProcessProperties.Property.SEARCH_PORT; public class EsSettings { @@ -126,20 +125,17 @@ public class EsSettings { private void configureCluster(Map<String, String> builder) { // Default value in a standalone mode, not overridable - int minimumMasterNodes = 1; String initialStateTimeOut = "30s"; if (clusterEnabled) { - minimumMasterNodes = props.valueAsInt(SEARCH_MINIMUM_MASTER_NODES.getKey(), 2); initialStateTimeOut = props.value(SEARCH_INITIAL_STATE_TIMEOUT.getKey(), "120s"); String hosts = props.value(CLUSTER_SEARCH_HOSTS.getKey(), ""); LOGGER.info("Elasticsearch cluster enabled. Connect to hosts [{}]", hosts); - builder.put("discovery.zen.ping.unicast.hosts", hosts); + builder.put("discovery.seed_hosts", hosts); builder.put("cluster.initial_master_nodes", hosts); } - builder.put("discovery.zen.minimum_master_nodes", valueOf(minimumMasterNodes)); builder.put("discovery.initial_state_timeout", initialStateTimeOut); builder.put("cluster.name", clusterName); builder.put("cluster.routing.allocation.awareness.attributes", "rack_id"); diff --git a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java index 7717edd8f14..275712e53d4 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java @@ -58,7 +58,6 @@ import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; import static org.sonar.process.ProcessProperties.Property.SEARCH_HOST; import static org.sonar.process.ProcessProperties.Property.SEARCH_HTTP_PORT; import static org.sonar.process.ProcessProperties.Property.SEARCH_INITIAL_STATE_TIMEOUT; -import static org.sonar.process.ProcessProperties.Property.SEARCH_MINIMUM_MASTER_NODES; import static org.sonar.process.ProcessProperties.Property.SEARCH_PORT; @RunWith(DataProviderRunner.class) @@ -154,8 +153,7 @@ public class EsSettingsTest { // http is disabled for security reasons assertThat(generated.get("http.enabled")).isEqualTo("false"); - assertThat(generated.get("discovery.zen.ping.unicast.hosts")).isNull(); - assertThat(generated.get("discovery.zen.minimum_master_nodes")).isEqualTo("1"); + assertThat(generated.get("discovery.seed_hosts")).isNull(); assertThat(generated.get("discovery.initial_state_timeout")).isEqualTo("30s"); assertThat(generated.get("action.auto_create_index")).isEqualTo("false"); @@ -243,30 +241,18 @@ public class EsSettingsTest { props.set(CLUSTER_SEARCH_HOSTS.getKey(), "1.2.3.4:9000,1.2.3.5:8080"); Map<String, String> settings = new EsSettings(props, new EsInstallation(props), system).build(); - assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isEqualTo("1.2.3.4:9000,1.2.3.5:8080"); - assertThat(settings.get("discovery.zen.minimum_master_nodes")).isEqualTo("2"); + assertThat(settings.get("discovery.seed_hosts")).isEqualTo("1.2.3.4:9000,1.2.3.5:8080"); assertThat(settings.get("discovery.initial_state_timeout")).isEqualTo("120s"); } @Test - public void incorrect_values_of_minimum_master_nodes() throws Exception { + public void set_initial_master_nodes_settings_if_cluster_is_enabled() throws Exception { Props props = minProps(CLUSTER_ENABLED); - props.set(SEARCH_MINIMUM_MASTER_NODES.getKey(), "ꝱꝲꝳପ"); - - EsSettings underTest = new EsSettings(props, new EsInstallation(props), system); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Value of property sonar.search.minimumMasterNodes is not an integer:"); - underTest.build(); - } - - @Test - public void cluster_is_enabled_with_defined_minimum_master_nodes() throws Exception { - Props props = minProps(CLUSTER_ENABLED); - props.set(SEARCH_MINIMUM_MASTER_NODES.getKey(), "5"); - Map<String, String> settings = new EsSettings(props, new EsInstallation(props), system).build(); + props.set(CLUSTER_SEARCH_HOSTS.getKey(), "1.2.3.4:9000,1.2.3.5:8080"); + Map<String, String> settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build(); - assertThat(settings.get("discovery.zen.minimum_master_nodes")).isEqualTo("5"); + assertThat(settings.get("cluster.initial_master_nodes")).isEqualTo("1.2.3.4:9000,1.2.3.5:8080"); + assertThat(settings.get("discovery.initial_state_timeout")).isEqualTo("120s"); } @Test @@ -288,15 +274,6 @@ public class EsSettingsTest { } @Test - public void in_standalone_minimumMasterNodes_is_not_overridable() throws Exception { - Props props = minProps(CLUSTER_DISABLED); - props.set(SEARCH_MINIMUM_MASTER_NODES.getKey(), "5"); - Map<String, String> settings = new EsSettings(props, new EsInstallation(props), system).build(); - - assertThat(settings.get("discovery.zen.minimum_master_nodes")).isEqualTo("1"); - } - - @Test public void enable_http_connector() throws Exception { Props props = minProps(CLUSTER_DISABLED); props.set(SEARCH_HTTP_PORT.getKey(), "9010"); |