cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [1/3] git commit: Fix nodetool ring and status output format for ipv6 addresses Patch by Michal Michalsky, reviewed by brandonwilliams for CASSANDRA-5302
Date Wed, 20 Mar 2013 15:46:47 GMT
Updated Branches:
  refs/heads/cassandra-1.2 c1332efe1 -> f3a93f95b
  refs/heads/trunk 367273190 -> 5d2d07f5a


Fix nodetool ring and status output format for ipv6 addresses
Patch by Michal Michalsky, reviewed by brandonwilliams for
CASSANDRA-5302


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f3a93f95
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f3a93f95
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f3a93f95

Branch: refs/heads/cassandra-1.2
Commit: f3a93f95ba1374986ea6d4ed12a84b888d22aa94
Parents: c1332ef
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Wed Mar 20 10:45:09 2013 -0500
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Wed Mar 20 10:45:09 2013 -0500

----------------------------------------------------------------------
 src/java/org/apache/cassandra/tools/NodeCmd.java |   33 ++++++++++++++++-
 1 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f3a93f95/src/java/org/apache/cassandra/tools/NodeCmd.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/NodeCmd.java b/src/java/org/apache/cassandra/tools/NodeCmd.java
index 8cd8b56..9d113a6 100644
--- a/src/java/org/apache/cassandra/tools/NodeCmd.java
+++ b/src/java/org/apache/cassandra/tools/NodeCmd.java
@@ -212,7 +212,16 @@ public class NodeCmd
         for (Map.Entry<String, String> entry : tokensToEndpoints.entrySet())
             endpointsToTokens.put(entry.getValue(), entry.getKey());
 
-        String format = "%-16s%-12s%-7s%-8s%-16s%-20s%-44s%n";
+        int maxAddressLength = Collections.max(endpointsToTokens.keys(), new Comparator<String>()
{
+            @Override
+            public int compare(String first, String second)
+            {
+                return ((Integer)first.length()).compareTo((Integer)second.length());
+            }
+        }).length();
+
+        String formatPlaceholder = "%%-%ds  %%-12s%%-7s%%-8s%%-16s%%-20s%%-44s%%n";
+        String format = String.format(formatPlaceholder, maxAddressLength);
 
         // Calculate per-token ownership of the ring
         Map<InetAddress, Float> ownerships;
@@ -328,6 +337,7 @@ public class NodeCmd
     private class ClusterStatus
     {
         String kSpace = null, format = null;
+        int maxAddressLength;
         Collection<String> joiningNodes, leavingNodes, movingNodes, liveNodes, unreachableNodes;
         Map<String, String> loadMap, hostIDMap, tokensToEndpoints;
         EndpointSnitchInfoMBean epSnitchInfo;
@@ -376,7 +386,10 @@ public class NodeCmd
             if (format == null)
             {
                 StringBuffer buf = new StringBuffer();
-                buf.append("%s%s  %-16s  %-9s  ");            // status, address, and load
+                String addressPlaceholder = String.format("%%-%ds  ", maxAddressLength);
+                buf.append("%s%s  ");                         // status
+                buf.append(addressPlaceholder);               // address
+                buf.append("%-9s  ");                         // load
                 if (!isTokenPerNode)  buf.append("%-6s  ");   // "Tokens"
                 if (hasEffectiveOwns) buf.append("%-16s  ");  // "Owns (effective)"
                 else                  buf.append("%-5s  ");   // "Owns
@@ -435,6 +448,7 @@ public class NodeCmd
         {
             Map<InetAddress, Float> ownerships;
             boolean hasEffectiveOwns = false, isTokenPerNode = true;
+
             try
             {
                 ownerships = probe.effectiveOwnership(kSpace);
@@ -449,6 +463,21 @@ public class NodeCmd
             if (new HashSet<String>(tokensToEndpoints.values()).size() < tokensToEndpoints.keySet().size())
                 isTokenPerNode = false;
 
+            maxAddressLength = 0;
+            for (Map.Entry<String, Map<InetAddress, Float>> dc : getOwnershipByDc(ownerships).entrySet())
+            {
+                int dcMaxAddressLength = Collections.max(dc.getValue().keySet(), new Comparator<InetAddress>()
{
+                    @Override
+                    public int compare(InetAddress first, InetAddress second)
+                    {
+                        return ((Integer)first.getHostAddress().length()).compareTo((Integer)second.getHostAddress().length());
+                    }
+                }).getHostAddress().length();
+
+                if(dcMaxAddressLength > maxAddressLength)
+                    maxAddressLength = dcMaxAddressLength;
+            }
+
             // Datacenters
             for (Map.Entry<String, Map<InetAddress, Float>> dc : getOwnershipByDc(ownerships).entrySet())
             {


Mime
View raw message