cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject svn commit: r1127336 - in /cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools: NodeCmd.java NodeProbe.java
Date Wed, 25 May 2011 00:02:23 GMT
Author: brandonwilliams
Date: Wed May 25 00:02:22 2011
New Revision: 1127336

URL: http://svn.apache.org/viewvc?rev=1127336&view=rev
Log:
Show rack and dc in nodetool ring/info.
Patch by Alex Araujo, reviewed by brandonwilliams for CASSANDRA-2531

Modified:
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeCmd.java
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeProbe.java

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeCmd.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeCmd.java?rev=1127336&r1=1127335&r2=1127336&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeCmd.java (original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeCmd.java Wed
May 25 00:02:22 2011
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.io.PrintStream;
 import java.lang.management.MemoryUsage;
 import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.text.DecimalFormat;
 import java.util.*;
 import java.util.Map.Entry;
@@ -161,11 +162,12 @@ public class NodeCmd
         Collection<String> movingNodes = probe.getMovingNodes();
         Map<String, String> loadMap = probe.getLoadMap();
 
-        outs.printf("%-16s%-7s%-8s%-16s%-8s%-44s%n", "Address", "Status", "State", "Load",
"Owns", "Token");
+        String format = "%-16s%-12s%-12s%-7s%-8s%-16s%-8s%-44s%n";
+        outs.printf(format, "Address", "DC", "Rack", "Status", "State", "Load", "Owns", "Token");
         // show pre-wrap token twice so you can always read a node's range as
         // (previous line token, current line token]
         if (sortedTokens.size() > 1)
-            outs.printf("%-16s%-7s%-8s%-16s%-8s%-44s%n", "", "", "", "", "", sortedTokens.get(sortedTokens.size()
- 1));
+            outs.printf(format, "", "", "", "", "", "", "", sortedTokens.get(sortedTokens.size()
- 1));
 
         // Calculate per-token ownership of the ring
         Map<Token, Float> ownerships = probe.getOwnership();
@@ -173,6 +175,24 @@ public class NodeCmd
         for (Token token : sortedTokens)
         {
             String primaryEndpoint = tokenToEndpoint.get(token);
+            String dataCenter;
+            try
+            {
+                dataCenter = probe.getEndpointSnitchInfoProxy().getDatacenter(primaryEndpoint);
+            }
+            catch (UnknownHostException e)
+            {
+                dataCenter = "Unknown";
+            }
+            String rack;
+            try
+            {
+                rack = probe.getEndpointSnitchInfoProxy().getRack(primaryEndpoint);
+            }
+            catch (UnknownHostException e)
+            {
+                rack = "Unknown";
+            }
             String status = liveNodes.contains(primaryEndpoint)
                             ? "Up"
                             : deadNodes.contains(primaryEndpoint)
@@ -192,7 +212,7 @@ public class NodeCmd
                           ? loadMap.get(primaryEndpoint)
                           : "?";
             String owns = new DecimalFormat("##0.00%").format(ownerships.get(token));
-            outs.printf("%-16s%-7s%-8s%-16s%-8s%-44s%n", primaryEndpoint, status, state,
load, owns, token);
+            outs.printf(format, primaryEndpoint, dataCenter, rack, status, state, load, owns,
token);
         }
     }
 
@@ -236,6 +256,10 @@ public class NodeCmd
         double memUsed = (double)heapUsage.getUsed() / (1024 * 1024);
         double memMax = (double)heapUsage.getMax() / (1024 * 1024);
         outs.printf("%-17s: %.2f / %.2f%n", "Heap Memory (MB)", memUsed, memMax);
+
+        // Data Center/Rack
+        outs.printf("%-17s: %s%n", "Data Center", probe.getDataCenter());
+        outs.printf("%-17s: %s%n", "Rack", probe.getRack());
     }
 
     public void printReleaseVersion(PrintStream outs)

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeProbe.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeProbe.java?rev=1127336&r1=1127335&r2=1127336&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeProbe.java (original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/tools/NodeProbe.java Wed
May 25 00:02:22 2011
@@ -25,6 +25,7 @@ import java.lang.management.MemoryMXBean
 import java.lang.management.MemoryUsage;
 import java.lang.management.RuntimeMXBean;
 import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
 import java.util.*;
 import java.util.Map.Entry;
@@ -47,6 +48,7 @@ import org.apache.cassandra.db.ColumnFam
 import org.apache.cassandra.db.CompactionManager;
 import org.apache.cassandra.db.CompactionManagerMBean;
 import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.locator.EndpointSnitchInfoMBean;
 import org.apache.cassandra.net.MessagingServiceMBean;
 import org.apache.cassandra.service.StorageServiceMBean;
 import org.apache.cassandra.streaming.StreamingService;
@@ -485,6 +487,18 @@ public class NodeProbe
             throw new RuntimeException("Error while executing truncate", e);
         }
     }
+
+    public EndpointSnitchInfoMBean getEndpointSnitchInfoProxy()
+    {
+        try
+        {
+            return JMX.newMBeanProxy(mbeanServerConn, new ObjectName("org.apache.cassandra.db:type=EndpointSnitchInfo"),
EndpointSnitchInfoMBean.class);
+        }
+        catch (MalformedObjectNameException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
     
     public MessagingServiceMBean getMsProxy()
     {
@@ -516,6 +530,30 @@ public class NodeProbe
         return cfsProxy;
     }
 
+    public String getDataCenter()
+    {
+        try
+        {
+            return getEndpointSnitchInfoProxy().getDatacenter(host);
+        }
+        catch (UnknownHostException e)
+        {
+            return "Unknown";
+        }
+    }
+
+    public String getRack()
+    {
+        try
+        {
+            return getEndpointSnitchInfoProxy().getRack(host);
+        }
+        catch (UnknownHostException e)
+        {
+            return "Unknown";
+        }
+    }
+
     public List<String> getKeyspaces()
     {
         return ssProxy.getKeyspaces();



Mime
View raw message