diff options
author | lukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com> | 2024-10-25 15:20:50 +0200 |
---|---|---|
committer | Lukasz Jarocki <lukasz.jarocki@sonarsource.com> | 2025-02-28 09:57:46 +0100 |
commit | 9d4672c454b808d6fa5496c57e5cc7d3bb5bdb25 (patch) | |
tree | d26411937f1eecddf97f939be0ca89e7c32fc402 /server | |
parent | d782f35cfeae338e2dbf3e039cd04166b949a1d3 (diff) | |
download | sonarqube-9d4672c454b808d6fa5496c57e5cc7d3bb5bdb25.tar.gz sonarqube-9d4672c454b808d6fa5496c57e5cc7d3bb5bdb25.zip |
SONAR-23456 ElasticSearch changes
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-main/src/main/java/org/sonar/application/es/EsConnectorImpl.java | 5 | ||||
-rw-r--r-- | server/sonar-server-common/src/main/java/org/sonar/server/es/EsClientProvider.java | 3 |
2 files changed, 8 insertions, 0 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsConnectorImpl.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsConnectorImpl.java index 0c5ae857700..a641ae20c57 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/es/EsConnectorImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsConnectorImpl.java @@ -138,6 +138,11 @@ public class EsConnectorImpl implements EsConnector { private HttpHost toHttpHost(HostAndPort host) { try { String scheme = keyStorePath != null ? "https" : HttpHost.DEFAULT_SCHEME_NAME; + if ("true".equalsIgnoreCase(System.getProperty("java.net.preferIPv6Addresses"))) { + // host.getHost() returns IP address. This is required for HttpHost to work as we need to use IP address in the RestClient to + // correctly resolve the host. Otherwise, RestClient will try to find the ip using hostname, and it might fail in case of IPv6. + return new HttpHost(InetAddress.getByName(host.getHost()), host.getHost(), host.getPortOrDefault(9001), scheme); + } return new HttpHost(InetAddress.getByName(host.getHost()), host.getPortOrDefault(9001), scheme); } catch (UnknownHostException e) { throw new IllegalStateException("Can not resolve host [" + host + "]", e); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClientProvider.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClientProvider.java index e3b59850d56..0040303b83b 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClientProvider.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClientProvider.java @@ -95,6 +95,9 @@ public class EsClientProvider { private static HttpHost toHttpHost(HostAndPort host, Configuration config) { try { String scheme = config.get(CLUSTER_ES_HTTP_KEYSTORE.getKey()).isPresent() ? "https" : HttpHost.DEFAULT_SCHEME_NAME; + if ("true".equalsIgnoreCase(System.getProperty("java.net.preferIPv6Addresses"))) { + return new HttpHost(InetAddress.getByName(host.getHost()), host.getHost(), host.getPortOrDefault(9001), scheme); + } return new HttpHost(InetAddress.getByName(host.getHost()), host.getPortOrDefault(9001), scheme); } catch (UnknownHostException e) { throw new IllegalStateException("Can not resolve host [" + host + "]", e); |