From a57336a30bcc8683a2ff64aeceed2b360912d306 Mon Sep 17 00:00:00 2001 From: Eric Hartmann Date: Tue, 23 May 2017 17:54:48 +0200 Subject: [PATCH] SONAR-9296 Do not check sonar.search.host if search is disabled --- .../application/config/ClusterSettings.java | 8 +++++-- .../config/ClusterSettingsTest.java | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/config/ClusterSettings.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/config/ClusterSettings.java index 445fe3c73d4..b6b8ce39128 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/application/config/ClusterSettings.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/application/config/ClusterSettings.java @@ -65,8 +65,13 @@ public class ClusterSettings implements Consumer { throw new MessageException(format("Property [%s] is forbidden", CLUSTER_WEB_LEADER)); } + if (props.valueAsBoolean(ProcessProperties.CLUSTER_ENABLED) && + !props.valueAsBoolean(ProcessProperties.CLUSTER_SEARCH_DISABLED, false) + ) { + ensureMandatoryProperty(props, SEARCH_HOST); + ensureNotLoopback(props, SEARCH_HOST); + } // Mandatory properties - ensureMandatoryProperty(props, SEARCH_HOST); ensureMandatoryProperty(props, CLUSTER_HOSTS); ensureMandatoryProperty(props, CLUSTER_SEARCH_HOSTS); @@ -77,7 +82,6 @@ public class ClusterSettings implements Consumer { } // Loopback interfaces are forbidden for SEARCH_HOST and CLUSTER_NETWORK_INTERFACES - ensureNotLoopback(props, SEARCH_HOST); ensureNotLoopback(props, CLUSTER_HOSTS); ensureNotLoopback(props, CLUSTER_NETWORK_INTERFACES); ensureNotLoopback(props, CLUSTER_SEARCH_HOSTS); diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/config/ClusterSettingsTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/config/ClusterSettingsTest.java index 3737f42ee22..5a487687983 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/config/ClusterSettingsTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/config/ClusterSettingsTest.java @@ -33,6 +33,7 @@ import static org.sonar.process.ProcessId.ELASTICSEARCH; import static org.sonar.process.ProcessId.WEB_SERVER; import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS; +import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_DISABLED; import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS; import static org.sonar.process.ProcessProperties.JDBC_URL; import static org.sonar.process.ProcessProperties.SEARCH_HOST; @@ -95,6 +96,29 @@ public class ClusterSettingsTest { new ClusterSettings().accept(settings.getProps()); } + @Test + public void accept_throws_MessageException_if_search_enabled_with_loopback() { + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_SEARCH_DISABLED, "false"); + settings.set(CLUSTER_SEARCH_HOSTS, "192.168.1.1,192.168.1.2"); + settings.set(SEARCH_HOST, "::1"); + + expectedException.expect(MessageException.class); + expectedException.expectMessage("The interface address [::1] of [sonar.search.host] must not be a loopback address"); + + new ClusterSettings().accept(settings.getProps()); + } + + @Test + public void accept_not_throwing_MessageException_if_search_disabled_with_loopback() { + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_SEARCH_DISABLED, "true"); + settings.set(CLUSTER_SEARCH_HOSTS, "192.168.1.1,192.168.1.2"); + settings.set(SEARCH_HOST, "::1"); + + new ClusterSettings().accept(settings.getProps()); + } + @Test public void accept_does_nothing_if_cluster_is_disabled() { settings.set(CLUSTER_ENABLED, "false"); -- 2.39.5