]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9802 add host address to returned nodes
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 25 Sep 2017 20:11:03 +0000 (22:11 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 26 Sep 2017 21:49:38 +0000 (23:49 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImplTest.java

index 565178f40a81278102db867bc36f8f588cb7876a..9fd408680bf6a1d0ea657091be620f926e3fa926 100644 (file)
@@ -54,7 +54,11 @@ public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader {
     DistributedAnswer<ProtobufSystemInfo.SystemInfo> distributedAnswer = hzMember.call(ProcessInfoProvider::provide, memberSelector, DISTRIBUTED_TIMEOUT_MS);
     for (Member member : distributedAnswer.getMembers()) {
       String nodeName = member.getStringAttribute(NODE_NAME.getKey());
-      NodeInfo nodeInfo = nodesByName.computeIfAbsent(nodeName, NodeInfo::new);
+      NodeInfo nodeInfo = nodesByName.computeIfAbsent(nodeName, name -> {
+        NodeInfo info = new NodeInfo(name);
+        info.setHost(member.getAddress().getHost());
+        return info;
+      });
       completeNodeInfo(distributedAnswer, member, nodeInfo);
     }
     return nodesByName.values();
index 806e6712e0d627bac785f4edac97efd602a134ed..62dea1be42674b313a3c57c9ef42ed08b02fc126 100644 (file)
@@ -21,7 +21,9 @@ package org.sonar.server.platform.monitoring.cluster;
 
 import com.hazelcast.core.Member;
 import com.hazelcast.core.MemberSelector;
+import com.hazelcast.nio.Address;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.util.Collection;
 import org.junit.Rule;
 import org.junit.Test;
@@ -42,6 +44,8 @@ import static org.mockito.Mockito.when;
 
 public class AppNodesInfoLoaderImplTest {
 
+  private static final InetAddress AN_ADDRESS = InetAddress.getLoopbackAddress();
+
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
@@ -62,6 +66,7 @@ public class AppNodesInfoLoaderImplTest {
 
     NodeInfo successfulNodeInfo = findNode(nodes, "foo");
     assertThat(successfulNodeInfo.getName()).isEqualTo("foo");
+    assertThat(successfulNodeInfo.getHost()).hasValue(AN_ADDRESS.getHostAddress());
     assertThat(successfulNodeInfo.getErrorMessage()).isEmpty();
     assertThat(successfulNodeInfo.getSections()).hasSize(1);
 
@@ -84,8 +89,9 @@ public class AppNodesInfoLoaderImplTest {
   }
 
   private Member newMember(String name) {
-    Member member = mock(Member.class, Mockito.RETURNS_DEEP_STUBS);
+    Member member = mock(Member.class, Mockito.RETURNS_MOCKS);
     when(member.getStringAttribute(HazelcastMember.Attribute.NODE_NAME.getKey())).thenReturn(name);
+    when(member.getAddress()).thenReturn(new Address(AN_ADDRESS, 6789));
     return member;
   }
 }