public JSONArray ring()

in priam/src/main/java/com/netflix/priam/connection/JMXNodeTool.java [303:359]


    public JSONArray ring(String keyspace) throws JSONException {
        JSONArray ring = new JSONArray();
        Map<String, String> tokenToEndpoint = getTokenToEndpointMap();
        List<String> sortedTokens = new ArrayList<>(tokenToEndpoint.keySet());

        Collection<String> liveNodes = getLiveNodes();
        Collection<String> deadNodes = getUnreachableNodes();
        Collection<String> joiningNodes = getJoiningNodes();
        Collection<String> leavingNodes = getLeavingNodes();
        Collection<String> movingNodes = getMovingNodes();
        Map<String, String> loadMap = getLoadMap();

        String format = "%-16s%-12s%-12s%-7s%-8s%-16s%-20s%-44s%n";

        // Calculate per-token ownership of the ring
        Map<InetAddress, Float> ownerships;
        try {
            ownerships = effectiveOwnership(keyspace);
        } catch (IllegalStateException ex) {
            ownerships = getOwnership();
        }

        for (String token : sortedTokens) {
            String primaryEndpoint = tokenToEndpoint.get(token);
            String dataCenter;
            try {
                dataCenter = getEndpointSnitchInfoProxy().getDatacenter(primaryEndpoint);
            } catch (UnknownHostException e) {
                dataCenter = "Unknown";
            }
            String rack;
            try {
                rack = 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.getOrDefault(primaryEndpoint, "?");
            String owns =
                    new DecimalFormat("##0.00%")
                            .format(ownerships.get(token) == null ? 0.0F : ownerships.get(token));
            ring.put(
                    createJson(
                            primaryEndpoint, dataCenter, rack, status, state, load, owns, token));
        }
        return ring;
    }