From 874973829ca3a7ba8e39709d478695216357cf97 Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 27 Oct 2020 11:20:27 +0100 Subject: SONAR-14039 replace 'sonar.search.transportPort' with 'sonar.es.port' on non-DCE --- .../main/java/org/sonar/process/ProcessProperties.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'server/sonar-process/src/main') 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 a1e7089900f..7038fc4952c 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 @@ -36,6 +36,7 @@ import org.sonar.core.extension.ServiceLoaderWrapper; import static com.google.common.base.Preconditions.checkState; import static java.lang.String.format; import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.ES_PORT; import static org.sonar.process.ProcessProperties.Property.SEARCH_HOST; import static org.sonar.process.ProcessProperties.Property.SEARCH_PORT; @@ -77,8 +78,7 @@ public class ProcessProperties { SEARCH_HOST("sonar.search.host"), SEARCH_PORT("sonar.search.port"), - // FIXME default is 0 until we move out of usage of TransportClient and we can put the expected default: 9002 - SEARCH_TRANSPORT_PORT("sonar.search.transportPort", "0"), + ES_PORT("sonar.es.port"), SEARCH_JAVA_OPTS("sonar.search.javaOpts", "-Xmx512m -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError"), SEARCH_JAVA_ADDITIONAL_OPTS("sonar.search.javaAdditionalOpts", ""), SEARCH_REPLICAS("sonar.search.replicas"), @@ -239,8 +239,7 @@ public class ProcessProperties { props.setDefault(SEARCH_HOST.getKey(), InetAddress.getLoopbackAddress().getHostAddress()); props.setDefault(SEARCH_PORT.getKey(), "9001"); fixPortIfZero(props, Property.SEARCH_HOST.getKey(), SEARCH_PORT.getKey()); - // FIXME remove when transport is not used anymore in non-DCE editions: sonar.search.transportPort must not support port 0 - fixPortIfZero(props, Property.SEARCH_HOST.getKey(), Property.SEARCH_TRANSPORT_PORT.getKey()); + fixEsTransportPortIfNull(props); } } @@ -278,6 +277,15 @@ public class ProcessProperties { } } + private static void fixEsTransportPortIfNull(Props props) { + String port = props.value(ES_PORT.getKey()); + if (port == null) { + int allocatedPort = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress().getHostAddress()) + .orElseThrow(() -> new IllegalStateException("Cannot resolve address for Elasticsearch TCP transport port")); + props.set(ES_PORT.getKey(), String.valueOf(allocatedPort)); + } + } + public static long parseTimeoutMs(Property property, String value) { long l = Long.parseLong(value); checkState(l >= 1, "value of %s must be >= 1", property); -- cgit v1.2.3