diff options
author | Michal Duda <michal.duda@sonarsource.com> | 2020-10-27 23:02:20 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-11-05 20:06:21 +0000 |
commit | 8493c2b1bb1921573bd5a4a84d34b7b8c24d52da (patch) | |
tree | 22ff73cf4bfb899e8decece1b51ef347e6b5e52e /server/sonar-main/src/main/java | |
parent | 15bfd33b82de889b720af0539ae3ac0068106265 (diff) | |
download | sonarqube-8493c2b1bb1921573bd5a4a84d34b7b8c24d52da.tar.gz sonarqube-8493c2b1bb1921573bd5a4a84d34b7b8c24d52da.zip |
SONAR-13979 Fail when sonar.search.host or sonar.search.port are defined in DCE
- Orchestrator upgrade was required as by default it was setting these properties
Diffstat (limited to 'server/sonar-main/src/main/java')
-rw-r--r-- | server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java | 16 | ||||
-rw-r--r-- | server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java | 25 |
2 files changed, 30 insertions, 11 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 7b059868940..504f6885483 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 @@ -21,6 +21,7 @@ package org.sonar.application.config; import com.google.common.net.HostAndPort; import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import java.util.Objects; import java.util.Set; @@ -54,8 +55,11 @@ import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE; import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS; import static org.sonar.process.ProcessProperties.Property.CLUSTER_WEB_STARTUP_LEADER; import static org.sonar.process.ProcessProperties.Property.JDBC_URL; +import static org.sonar.process.ProcessProperties.Property.SEARCH_HOST; +import static org.sonar.process.ProcessProperties.Property.SEARCH_PORT; public class ClusterSettings implements Consumer<Props> { + private static final Set<Property> FORBIDDEN_SEARCH_NODE_SETTINGS = EnumSet.of(SEARCH_HOST, SEARCH_PORT); private final NetworkUtils network; @@ -87,6 +91,7 @@ public class ClusterSettings implements Consumer<Props> { checkClusterSearchHosts(props); break; case SEARCH: + ensureNoSearchNodeForbiddenSettings(props); AddressAndPort searchHost = parseAndCheckHost(CLUSTER_NODE_SEARCH_HOST, requireValue(props, CLUSTER_NODE_SEARCH_HOST)); ensureLocalButNotLoopbackAddress(CLUSTER_NODE_SEARCH_HOST, searchHost); AddressAndPort esHost = parseAndCheckHost(CLUSTER_NODE_ES_HOST, requireValue(props, CLUSTER_NODE_ES_HOST)); @@ -166,6 +171,17 @@ public class ClusterSettings implements Consumer<Props> { return trimmedValue; } + private static void ensureNoSearchNodeForbiddenSettings(Props props) { + List<String> violations = FORBIDDEN_SEARCH_NODE_SETTINGS.stream() + .filter(setting -> props.value(setting.getKey()) != null) + .map(Property::getKey) + .collect(toList()); + + if (!violations.isEmpty()) { + throw new MessageException(format("Properties [%s] are not allowed when running SonarQube in cluster mode.", String.join(", ", violations))); + } + } + private static void ensureNotH2(Props props) { String jdbcUrl = props.value(JDBC_URL.getKey()); String trimmedJdbcUrl = jdbcUrl == null ? null : jdbcUrl.trim(); 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 3993a1a43b4..ff3765e1639 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 @@ -51,6 +51,7 @@ public class EsSettings { private static final String ES_HTTP_PORT_KEY = "http.port"; private static final String ES_TRANSPORT_HOST_KEY = "transport.host"; private static final String ES_TRANSPORT_PORT_KEY = "transport.port"; + private static final String ES_NETWORK_HOST_KEY = "network.host"; private static final Logger LOGGER = LoggerFactory.getLogger(EsSettings.class); private static final String STANDALONE_NODE_NAME = "sonarqube"; @@ -100,23 +101,25 @@ public class EsSettings { } private void configureNetwork(Map<String, String> builder) { - InetAddress searchHost = resolveAddress(SEARCH_HOST); - int searchPort = Integer.parseInt(props.nonNullValue(SEARCH_PORT.getKey())); + if (!clusterEnabled) { + InetAddress searchHost = resolveAddress(SEARCH_HOST); + int searchPort = Integer.parseInt(props.nonNullValue(SEARCH_PORT.getKey())); + builder.put(ES_HTTP_HOST_KEY, searchHost.getHostAddress()); + builder.put(ES_HTTP_PORT_KEY, valueOf(searchPort)); + builder.put(ES_NETWORK_HOST_KEY, valueOf(searchHost.getHostAddress())); + + // FIXME remove definition of transport properties when Web and CE have moved to ES Rest client + int transportPort = props.valueAsInt(SEARCH_TRANSPORT_PORT.getKey(), 9002); + builder.put(ES_TRANSPORT_HOST_KEY, searchHost.getHostAddress()); + builder.put(ES_TRANSPORT_PORT_KEY, valueOf(transportPort)); + } // see https://github.com/lmenezes/elasticsearch-kopf/issues/195 builder.put("http.cors.enabled", valueOf(true)); builder.put("http.cors.allow-origin", "*"); - builder.put(ES_HTTP_HOST_KEY, searchHost.getHostAddress()); - builder.put(ES_HTTP_PORT_KEY, valueOf(searchPort)); - builder.put("network.host", valueOf(searchHost.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", valueOf(true)); - - // FIXME remove definition of transport properties when Web and CE have moved to ES Rest client - int transportPort = props.valueAsInt(SEARCH_TRANSPORT_PORT.getKey(), 9002); - builder.put(ES_TRANSPORT_HOST_KEY, searchHost.getHostAddress()); - builder.put(ES_TRANSPORT_PORT_KEY, valueOf(transportPort)); } private InetAddress resolveAddress(ProcessProperties.Property prop) { @@ -158,7 +161,7 @@ public class EsSettings { int nodeTransportPort = props.valueAsInt(CLUSTER_NODE_ES_PORT.getKey(), 9002); builder.put(ES_TRANSPORT_HOST_KEY, nodeTransportHost); builder.put(ES_TRANSPORT_PORT_KEY, valueOf(nodeTransportPort)); - builder.put("network.host", nodeTransportHost); + builder.put(ES_NETWORK_HOST_KEY, nodeTransportHost); String hosts = props.value(CLUSTER_ES_HOSTS.getKey(), loopbackAddress.getHostAddress()); LOGGER.info("Elasticsearch cluster enabled. Connect to hosts [{}]", hosts); |