src/java/org/apache/cassandra/tools/NodeCmd.java
/**
     * Write a textual representation of the Cassandra ring.
     * 
     * @param outs the stream to write to
     */
Write a textual representation of the Cassandra ring.

@param outs the stream to write to
Write a textual representation of the Cassandra ring . @param outs the stream to write to
public void printRing(PrintStream outs)
    {
        Map<String, String> tokenToEndpoint = probe.getTokenToEndpointMap();
        List<String> sortedTokens = new ArrayList<String>(tokenToEndpoint.keySet());
        Collections.sort(sortedTokens);
        Collection<String> liveNodes = probe.getLiveNodes();
        Collection<String> deadNodes = probe.getUnreachableNodes();
        Collection<String> joiningNodes = probe.getJoiningNodes();
        Collection<String> leavingNodes = probe.getLeavingNodes();
        Collection<String> movingNodes = probe.getMovingNodes();
        Map<String, String> loadMap = probe.getLoadMap();
        String format = "%-16s%-12s%-12s%-7s%-8s%-16s%-8s%-44s%n";
        outs.printf(format, "Address", "DC", "Rack", "Status", "State", "Load", "Owns", "Token");
        if (sortedTokens.size() > 1)
            outs.printf(format, "", "", "", "", "", "", "", sortedTokens.get(sortedTokens.size() - 1));
        Map<String, Float> ownerships = probe.getOwnership();
        for (String 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)
                              ? "Down"
                              : "?";
            String state = "Normal";
            if (joiningNodes.contains(primaryEndpoint))
                state = "Joining";
            else if (leavingNodes.contains(primaryEndpoint))
                state = "Leaving";
            else if (movingNodes.contains(primaryEndpoint))
                state = "Moving";
            String load = loadMap.containsKey(primaryEndpoint)
                          ? loadMap.get(primaryEndpoint)
                          : "?";
            String owns = new DecimalFormat("##0.00%").format(ownerships.get(token));
            outs.printf(format, primaryEndpoint, dataCenter, rack, status, state, load, owns, token);
        }
    }
public void printRing ( PrintStream outs ) { Map < String , String > tokenToEndpoint = probe . getTokenToEndpointMap ( ) ; List < String > sortedTokens = new ArrayList < String > ( tokenToEndpoint . keySet ( ) ) ; Collections . sort ( sortedTokens ) ; Collection < String > liveNodes = probe . getLiveNodes ( ) ; Collection < String > deadNodes = probe . getUnreachableNodes ( ) ; Collection < String > joiningNodes = probe . getJoiningNodes ( ) ; Collection < String > leavingNodes = probe . getLeavingNodes ( ) ; Collection < String > movingNodes = probe . getMovingNodes ( ) ; Map < String , String > loadMap = probe . getLoadMap ( ) ; String format = "%-16s%-12s%-12s%-7s%-8s%-16s%-8s%-44s%n" ; outs . printf ( format , "Address" , "DC" , "Rack" , "Status" , "State" , "Load" , "Owns" , "Token" ) ; if ( sortedTokens . size ( ) > 1 ) outs . printf ( format , "" , "" , "" , "" , "" , "" , "" , sortedTokens . get ( sortedTokens . size ( ) - 1 ) ) ; Map < String , Float > ownerships = probe . getOwnership ( ) ; for ( String 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 ) ? "Down" : "?" ; String state = "Normal" ; if ( joiningNodes . contains ( primaryEndpoint ) ) state = "Joining" ; else if ( leavingNodes . contains ( primaryEndpoint ) ) state = "Leaving" ; else if ( movingNodes . contains ( primaryEndpoint ) ) state = "Moving" ; String load = loadMap . containsKey ( primaryEndpoint ) ? loadMap . get ( primaryEndpoint ) : "?" ; String owns = new DecimalFormat ( "##0.00%" ) . format ( ownerships . get ( token ) ) ; outs . printf ( format , primaryEndpoint , dataCenter , rack , status , state , load , owns , token ) ; } }
Write a textual representation of the Cassandra ring.
Write a textual representation of the Cassandra ring .
// show pre-wrap token twice so you can always read a node's range as // (previous line token, current line token] // Calculate per-token ownership of the ring