in adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/TokenRangeReplicaProvider.java [135:178]
private Map<String, ReplicaMetadata> replicaMetadata(List<TokenRangeReplicas> replicaSet,
StorageJmxOperations storage,
Map<String, String> hostToDatacenter)
{
List<String> joiningNodes = storage.getJoiningNodesWithPort();
List<String> leavingNodes = storage.getLeavingNodesWithPort();
List<String> movingNodes = storage.getMovingNodesWithPort();
List<String> liveNodes = storage.getLiveNodesWithPort();
List<String> deadNodes = storage.getUnreachableNodesWithPort();
String rawGossipInfo = getRawGossipInfo();
GossipInfoResponse gossipInfo = GossipInfoParser.parse(rawGossipInfo);
StateWithReplacement state = new StateWithReplacement(joiningNodes, leavingNodes, movingNodes, gossipInfo);
RingProvider.Status status = new RingProvider.Status(liveNodes, deadNodes);
return replicaSet.stream()
.map(TokenRangeReplicas::replicaSet)
.flatMap(Collection::stream)
.distinct()
.map(replica -> {
try
{
HostAndPort hap = HostAndPort.fromString(replica);
String fqdn = dnsResolver.reverseResolve(hap.getHost());
String datacenter = hostToDatacenter.get(replica);
return new AbstractMap.SimpleEntry<>(replica,
new ReplicaMetadata(state.of(replica),
status.of(replica),
fqdn,
hap.getHost(),
hap.getPort(),
datacenter));
}
catch (UnknownHostException e)
{
throw new RuntimeException(
String.format("Failed to resolve fqdn for replica %s ", replica), e);
}
})
.collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
}