diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2021-07-22 13:52:18 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-07-29 20:04:50 +0000 |
commit | 78a0a38cd36db3d2c38ffd7ccc494bcd9d366ad9 (patch) | |
tree | 9b9c73394cc663c472a0afa1a3b0d9e81d3c6d04 /server/sonar-main | |
parent | c5d6ef5f209111463580bc9bfe7013af30c9ad4b (diff) | |
download | sonarqube-78a0a38cd36db3d2c38ffd7ccc494bcd9d366ad9.tar.gz sonarqube-78a0a38cd36db3d2c38ffd7ccc494bcd9d366ad9.zip |
SONAR-15230 Enable DNS lookup in k8s for HZ
Diffstat (limited to 'server/sonar-main')
-rw-r--r-- | server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java | 7 | ||||
-rw-r--r-- | server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java | 4 |
2 files changed, 7 insertions, 4 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java b/server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java index 936dcb64996..74541528cb2 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java +++ b/server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java @@ -33,15 +33,17 @@ import org.sonar.process.ProcessId; import org.sonar.process.Props; import org.sonar.process.cluster.hz.HazelcastMember; import org.sonar.process.cluster.hz.HazelcastMemberBuilder; -import org.sonar.process.cluster.hz.InetAdressResolver; import static java.util.Arrays.asList; import static org.sonar.process.ProcessProperties.Property.CLUSTER_HZ_HOSTS; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_KUBERNETES; import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT; import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME; import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS; import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_PASSWORD; +import static org.sonar.process.cluster.hz.JoinConfigurationType.KUBERNETES; +import static org.sonar.process.cluster.hz.JoinConfigurationType.TCP_IP; public class AppStateFactory { private final AppSettings settings; @@ -61,7 +63,8 @@ public class AppStateFactory { } private static HazelcastMember createHzMember(Props props) { - HazelcastMemberBuilder builder = new HazelcastMemberBuilder(new InetAdressResolver()) + boolean isRunningOnKubernetes = props.valueAsBoolean(CLUSTER_KUBERNETES.getKey(), Boolean.parseBoolean(CLUSTER_KUBERNETES.getDefaultValue())); + HazelcastMemberBuilder builder = new HazelcastMemberBuilder(isRunningOnKubernetes ? KUBERNETES : TCP_IP) .setNetworkInterface(props.nonNullValue(CLUSTER_NODE_HOST.getKey())) .setMembers(asList(props.nonNullValue(CLUSTER_HZ_HOSTS.getKey()).split(","))) .setNodeName(props.nonNullValue(CLUSTER_NODE_NAME.getKey())) diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java index 1501f6f6243..16bbb81773b 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java @@ -35,7 +35,7 @@ import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; import org.sonar.process.cluster.hz.HazelcastMember; import org.sonar.process.cluster.hz.HazelcastMemberBuilder; -import org.sonar.process.cluster.hz.InetAdressResolver; +import org.sonar.process.cluster.hz.JoinConfigurationType; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -171,7 +171,7 @@ public class ClusterAppStateImplTest { // use loopback for support of offline builds InetAddress loopback = InetAddress.getLoopbackAddress(); - return new HazelcastMemberBuilder(new InetAdressResolver()) + return new HazelcastMemberBuilder(JoinConfigurationType.TCP_IP) .setProcessId(ProcessId.COMPUTE_ENGINE) .setNodeName("bar") .setPort(NetworkUtilsImpl.INSTANCE.getNextLoopbackAvailablePort()) |