From c8206d355a62a813a90a7b73af6af12456efd05a Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 25 Sep 2017 22:46:26 +0200 Subject: [PATCH] SONAR-9802 remove useless attributes of HazelcastMember --- .../cluster/ClusterAppStateImpl.java | 5 +--- .../java/org/sonar/process/NetworkUtils.java | 7 ----- .../org/sonar/process/NetworkUtilsImpl.java | 30 ------------------- .../process/cluster/hz/HazelcastMember.java | 8 ----- .../cluster/hz/HazelcastMemberBuilder.java | 3 -- 5 files changed, 1 insertion(+), 52 deletions(-) diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java index 2876b2eccbc..9da103a2979 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java @@ -51,8 +51,6 @@ import org.sonar.process.cluster.NodeType; import org.sonar.process.cluster.hz.HazelcastMember; import static java.lang.String.format; -import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.HOSTNAME; -import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.IP_ADDRESSES; import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_TYPE; import static org.sonar.process.cluster.hz.HazelcastObjects.CLUSTER_NAME; import static org.sonar.process.cluster.hz.HazelcastObjects.LEADER; @@ -189,8 +187,7 @@ public class ClusterAppStateImpl implements ClusterAppState { if (leaderId != null) { Optional leader = hzMember.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderId)).findFirst(); if (leader.isPresent()) { - return Optional.of( - format("%s (%s)", leader.get().getStringAttribute(HOSTNAME.getKey()), leader.get().getStringAttribute(IP_ADDRESSES.getKey()))); + return Optional.of(leader.get().getAddress().getHost()); } } return Optional.empty(); diff --git a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java index 234b930d241..b5419dfc28b 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java +++ b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java @@ -38,13 +38,6 @@ public interface NetworkUtils { */ String getHostname(); - /** - * Identifying the IPs addresses - * - * @return "ipv4_1, ipv4_2" - */ - String getIPAddresses(); - /** * Converts a text representation of an IP address or host name to * a {@link InetAddress}. diff --git a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java index 3f7d6892f35..1a9feb0da56 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java +++ b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java @@ -22,7 +22,6 @@ package org.sonar.process; import com.google.common.annotations.VisibleForTesting; import com.google.common.net.InetAddresses; import java.io.IOException; -import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.ServerSocket; @@ -33,10 +32,6 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; import java.util.function.Predicate; -import java.util.stream.Collectors; - -import static java.util.Collections.list; -import static org.apache.commons.lang.StringUtils.isBlank; public class NetworkUtilsImpl implements NetworkUtils { @@ -85,7 +80,6 @@ public class NetworkUtilsImpl implements NetworkUtils { throw new IllegalStateException("Fail to find an available port on " + address, e); } } - } @Override @@ -100,30 +94,6 @@ public class NetworkUtilsImpl implements NetworkUtils { return hostname; } - @Override - public String getIPAddresses() { - String ips; - - try { - ips = list(NetworkInterface.getNetworkInterfaces()).stream() - .flatMap(netif -> list(netif.getInetAddresses()).stream() - .filter(inetAddress -> - // Removing IPv6 for the time being - inetAddress instanceof Inet4Address && - // Removing loopback addresses, useless for identifying a server - !inetAddress.isLoopbackAddress() && - // Removing interfaces without IPs - !isBlank(inetAddress.getHostAddress())) - .map(InetAddress::getHostAddress)) - .filter(p -> !isBlank(p)) - .collect(Collectors.joining(",")); - } catch (SocketException e) { - ips = "unresolved IPs"; - } - - return ips; - } - @Override public InetAddress toInetAddress(String hostOrAddress) throws UnknownHostException { if (InetAddresses.isInetAddress(hostOrAddress)) { diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java index d2e081d4443..4815890f8ca 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java @@ -32,14 +32,6 @@ import org.sonar.process.cluster.NodeType; public interface HazelcastMember extends AutoCloseable { enum Attribute { - /** - * The key of the hostname attribute of a member - */ - HOSTNAME("HOSTNAME"), - /** - * The key of the ips list attribute of a member - */ - IP_ADDRESSES("IP_ADDRESSES"), /** * The key of the node name attribute of a member */ diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java index 73ba63abfa4..7440c562843 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java @@ -29,7 +29,6 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import javax.annotation.CheckForNull; -import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; import org.sonar.process.ProcessProperties; import org.sonar.process.cluster.NodeType; @@ -128,8 +127,6 @@ public class HazelcastMemberBuilder { .setProperty("hazelcast.logging.type", "slf4j"); MemberAttributeConfig attributes = config.getMemberAttributeConfig(); - attributes.setStringAttribute(Attribute.HOSTNAME.getKey(), NetworkUtilsImpl.INSTANCE.getHostname()); - attributes.setStringAttribute(Attribute.IP_ADDRESSES.getKey(), NetworkUtilsImpl.INSTANCE.getIPAddresses()); attributes.setStringAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing")); attributes.setStringAttribute(Attribute.NODE_TYPE.getKey(), requireNonNull(nodeType, "Node type is missing").getValue()); attributes.setStringAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey()); -- 2.39.5