]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9802 remove useless attributes of HazelcastMember
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 25 Sep 2017 20:46:26 +0000 (22:46 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 26 Sep 2017 21:49:39 +0000 (23:49 +0200)
server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java
server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java
server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java
server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java
server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java

index 2876b2eccbcf357b9d20ee283da157c8b741adf6..9da103a29795082445eff9729cd3dc02ff232b42 100644 (file)
@@ -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<Member> 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();
index 234b930d2419a11e69c85f80aa98aa7332f69bea..b5419dfc28b12179929fc7b57b36e8aaabffb32f 100644 (file)
@@ -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}.
index 3f7d6892f35cf66d06bd50b186ec26323fbb810c..1a9feb0da56082644f05d89f024166d0ed720a09 100644 (file)
@@ -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)) {
index d2e081d4443e02ac566910659b1f4219d246a369..4815890f8ca425f48294516c3783dfae4136db3d 100644 (file)
@@ -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
      */
index 73ba63abfa42cebefe1f07a2ea7254ee3d7b0e85..7440c562843b586b77a27560675ceca1f5ba5f14 100644 (file)
@@ -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());