From 68761c40c492533d35cc1de180d0c191c9181f1b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 25 Sep 2017 22:11:03 +0200 Subject: [PATCH] SONAR-9802 add host address to returned nodes --- .../monitoring/cluster/AppNodesInfoLoaderImpl.java | 6 +++++- .../monitoring/cluster/AppNodesInfoLoaderImplTest.java | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java index 565178f40a8..9fd408680bf 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java @@ -54,7 +54,11 @@ public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader { DistributedAnswer 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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImplTest.java index 806e6712e0d..62dea1be426 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImplTest.java @@ -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; } } -- 2.39.5