diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2021-07-20 13:32:17 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-07-21 20:03:01 +0000 |
commit | 1dff5a612667788aed965d14945767b277a2b313 (patch) | |
tree | 86610662ab7afce57f1ecea679ed6612f4fc56b4 | |
parent | a0ee583b52c7fff78b6458a21d1f3dd29b2a3b37 (diff) | |
download | sonarqube-1dff5a612667788aed965d14945767b277a2b313.tar.gz sonarqube-1dff5a612667788aed965d14945767b277a2b313.zip |
SONAR-15192 Disable ip addr validation for sonar.cluster.es.hosts
* provide new propert sonar.cluster.es.discovery.seed.hosts to allow dynamic node discovery in k8s
4 files changed, 15 insertions, 10 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java index b6415d42483..140a0f6944a 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java @@ -96,7 +96,7 @@ public class ClusterSettings implements Consumer<Props> { private void checkForApplicationNode(Props props) { ensureNotH2(props); requireValue(props, AUTH_JWT_SECRET); - Set<AddressAndPort> hzNodes = parseHosts(CLUSTER_HZ_HOSTS, requireValue(props, CLUSTER_HZ_HOSTS)); + Set<AddressAndPort> hzNodes = parseAndCheckHosts(CLUSTER_HZ_HOSTS, requireValue(props, CLUSTER_HZ_HOSTS)); ensureNotLoopbackAddresses(CLUSTER_HZ_HOSTS, hzNodes); checkClusterNodeHost(props); checkClusterSearchHosts(props); @@ -117,28 +117,32 @@ public class ClusterSettings implements Consumer<Props> { } private void checkClusterSearchHosts(Props props) { - Set<AddressAndPort> searchHosts = parseHosts(CLUSTER_SEARCH_HOSTS, requireValue(props, CLUSTER_SEARCH_HOSTS)); + Set<AddressAndPort> searchHosts = parseAndCheckHosts(CLUSTER_SEARCH_HOSTS, requireValue(props, CLUSTER_SEARCH_HOSTS)); ensureNotLoopbackAddresses(CLUSTER_SEARCH_HOSTS, searchHosts); } private void checkClusterEsHosts(Props props) { - Set<AddressAndPort> esHosts = parseHosts(CLUSTER_ES_HOSTS, requireValue(props, CLUSTER_ES_HOSTS)); + Set<AddressAndPort> esHosts = parseHosts(requireValue(props, CLUSTER_ES_HOSTS)); ensureNotLoopbackAddresses(CLUSTER_ES_HOSTS, esHosts); ensureEitherPortsAreProvidedOrOnlyHosts(CLUSTER_ES_HOSTS, esHosts); } - private Set<AddressAndPort> parseHosts(Property property, String value) { - Set<AddressAndPort> res = stream(value.split(",")) + private static Set<AddressAndPort> parseHosts(String value) { + return stream(value.split(",")) .filter(Objects::nonNull) .map(String::trim) .map(ClusterSettings::parseHost) .collect(toSet()); + } + + private Set<AddressAndPort> parseAndCheckHosts(Property property, String value) { + Set<AddressAndPort> res = parseHosts( value); checkValidHosts(property, res); return res; } private void checkValidHosts(Property property, Set<AddressAndPort> addressAndPorts) { - List<String> invalidHosts = addressAndPorts.stream() + List<String> invalidHosts = addressAndPorts.stream() .map(AddressAndPort::getHost) .filter(t -> !network.toInetAddress(t).isPresent()) .sorted() 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 79072191cce..562fba9d87b 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 @@ -36,6 +36,7 @@ import org.sonar.process.System2; import static java.lang.String.valueOf; import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ES_DISCOVERY_SEED_HOSTS; import static org.sonar.process.ProcessProperties.Property.CLUSTER_ES_HOSTS; import static org.sonar.process.ProcessProperties.Property.CLUSTER_ES_KEYSTORE; import static org.sonar.process.ProcessProperties.Property.CLUSTER_ES_TRUSTSTORE; @@ -211,8 +212,9 @@ public class EsSettings { builder.put(ES_NETWORK_HOST_KEY, nodeTransportHost); String hosts = props.value(CLUSTER_ES_HOSTS.getKey(), loopbackAddress.getHostAddress()); + String discoveryHosts = props.value(CLUSTER_ES_DISCOVERY_SEED_HOSTS.getKey(), hosts); LOGGER.info("Elasticsearch cluster enabled. Connect to hosts [{}]", hosts); - builder.put("discovery.seed_hosts", hosts); + builder.put("discovery.seed_hosts", discoveryHosts); builder.put("cluster.initial_master_nodes", hosts); } diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java index 7a10706dbd3..789c8664da2 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java @@ -379,7 +379,7 @@ public class ClusterSettingsTest { } @Test - public void validate_host_resolved_in_any_cluster_property_of_SEARCH_node() { + public void validate_host_resolved_in_node_search_host_property_of_SEARCH_node() { TestAppSettings settings = new TestAppSettings(ImmutableMap.<String, String>builder() .put(CLUSTER_ENABLED.getKey(), "true") .put(CLUSTER_NODE_TYPE.getKey(), "search") @@ -387,8 +387,6 @@ public class ClusterSettingsTest { .put(CLUSTER_NODE_SEARCH_HOST.getKey(), "search_host") .put(CLUSTER_NODE_ES_HOST.getKey(), "search_host").build()); - verifyHostIsChecked(settings, ImmutableList.of("remote_search_host_1"), "Address in property sonar.cluster.es.hosts is not a valid address: remote_search_host_1"); - verifyHostIsChecked(settings, ImmutableList.of("remote_search_host_2"), "Address in property sonar.cluster.es.hosts is not a valid address: remote_search_host_2"); verifyHostIsChecked(settings, ImmutableList.of("search_host"), "Address in property sonar.cluster.node.search.host is not a valid address: search_host"); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java index a7da1d7672d..9217274a281 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java @@ -132,6 +132,7 @@ public class ProcessProperties { // search node only settings CLUSTER_ES_HOSTS("sonar.cluster.es.hosts"), + CLUSTER_ES_DISCOVERY_SEED_HOSTS("sonar.cluster.es.discovery.seed.hosts"), CLUSTER_NODE_SEARCH_HOST("sonar.cluster.node.search.host"), CLUSTER_NODE_SEARCH_PORT("sonar.cluster.node.search.port"), CLUSTER_NODE_ES_HOST("sonar.cluster.node.es.host"), |