in adapters/base/src/main/java/org/apache/cassandra/sidecar/adapters/base/RingProvider.java [67:124]
public RingResponse ring(@Nullable String keyspace) throws UnknownHostException
{
StorageJmxOperations storageOps = initializeStorageOps();
EndpointSnitchJmxOperations epSnitchInfo = initializeEndpointProxy();
// Collect required data from the probe
List<String> liveNodes = storageOps.getLiveNodesWithPort();
List<String> deadNodes = storageOps.getUnreachableNodesWithPort();
Status status = new Status(liveNodes, deadNodes);
List<String> joiningNodes = storageOps.getJoiningNodesWithPort();
List<String> leavingNodes = storageOps.getLeavingNodesWithPort();
List<String> movingNodes = storageOps.getMovingNodesWithPort();
State state = new State(joiningNodes, leavingNodes, movingNodes);
Map<String, String> loadMap = storageOps.getLoadMapWithPort();
Map<String, String> tokensToEndpoints = storageOps.getTokenToEndpointWithPortMap();
Map<String, String> endpointsToHostIds = storageOps.getEndpointWithPortToHostId();
boolean showEffectiveOwnership = true;
// Calculate per-token ownership of the ring
Map<String, Float> ownerships;
try
{
ownerships = storageOps.effectiveOwnershipWithPort(keyspace);
}
catch (IllegalStateException ex)
{
ownerships = storageOps.getOwnershipWithPort();
LOGGER.warn("Unable to retrieve effective ownership information for keyspace={}", keyspace, ex);
showEffectiveOwnership = false;
}
// DecimalFormat is not thread-safe, so we need to create a new instance per thread
DecimalFormat ownsFormat = new DecimalFormat(DECIMAL_FORMAT);
RingResponse response = new RingResponse(tokensToEndpoints.size());
for (Map.Entry<String, String> entry : tokensToEndpoints.entrySet())
{
String endpoint = entry.getValue();
String token = entry.getKey();
HostAndPort hap = resolve(endpoint, dnsResolver);
Float owns = ownerships.get(endpoint);
RingEntry ringEntry = new RingEntry.Builder()
.datacenter(epSnitchInfo.getDatacenter(endpoint))
.rack(queryRack(epSnitchInfo, endpoint))
.status(status.of(endpoint))
.state(state.of(endpoint))
.load(loadMap.getOrDefault(endpoint, UNKNOWN_SHORT))
.owns(formatOwns(showEffectiveOwnership, ownsFormat, owns))
.token(token)
.address(hap.getHost())
.port(hap.getPort())
.fqdn(dnsResolver.reverseResolve(hap.getHost()))
.hostId(endpointsToHostIds.getOrDefault(endpoint, UNKNOWN))
.build();
response.add(ringEntry);
}
return response;
}