cmccabe commented on code in PR #16759:
URL: https://github.com/apache/kafka/pull/16759#discussion_r1699154238
##########
tools/src/main/java/org/apache/kafka/tools/MetadataQuorumCommand.java:
##########
@@ -232,9 +235,60 @@ else if (leader.lastCaughtUpTimestamp().isPresent() &&
maxLagFollower.lastCaught
"\nHighWatermark: " + quorumInfo.highWatermark() +
"\nMaxFollowerLag: " + maxFollowerLag +
"\nMaxFollowerLagTimeMs: " + maxFollowerLagTimeMs +
- "\nCurrentVoters: " +
quorumInfo.voters().stream().map(QuorumInfo.ReplicaState::replicaId).map(Object::toString).collect(Collectors.joining(",",
"[", "]")) +
- "\nCurrentObservers: " +
quorumInfo.observers().stream().map(QuorumInfo.ReplicaState::replicaId).map(Objects::toString).collect(Collectors.joining(",",
"[", "]"))
+ "\nCurrentVoters: " + printVoterState(quorumInfo) +
+ "\nCurrentObservers: " + printObserverState(quorumInfo)
);
}
+ // Constructs the CurrentVoters string
+ // CurrentVoters: [{"id": 0, "directoryId": "UUID1", "endpoints":
[{"name": "C", "securityProtocol": "SSL", "host": "controller-0", "port":
1234}]}, {"id": 1, ... }]}]
+ private static String printVoterState(QuorumInfo quorumInfo) {
+ return printReplicaState(quorumInfo, quorumInfo.voters());
+ }
+
+ // Constructs the CurrentObservers string
+ private static String printObserverState(QuorumInfo quorumInfo) {
+ return printReplicaState(quorumInfo, quorumInfo.observers());
+ }
+
+ private static String printReplicaState(QuorumInfo quorumInfo,
List<QuorumInfo.ReplicaState> replicas) {
+ List<Node> currentVoterList = replicas.stream().map(voter -> new Node(
+ voter.replicaId(),
+ voter.replicaDirectoryId(),
+
getEndpoints(quorumInfo.nodes().get(voter.replicaId())))).collect(Collectors.toList());
+ return
currentVoterList.stream().map(Objects::toString).collect(Collectors.joining(",
", "[", "]"));
+ }
+
+ private static List<RaftVoterEndpoint> getEndpoints(QuorumInfo.Node node) {
+ return node == null ? new ArrayList<>() : node.endpoints();
+ }
+
+ private static class Node {
+ private final int id;
+ private final Uuid directoryId;
+ private final List<RaftVoterEndpoint> endpoints;
+
+ private Node(int id, Uuid directoryId, List<RaftVoterEndpoint>
endpoints) {
+ this.id = id;
+ this.directoryId = directoryId;
+ this.endpoints = endpoints;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("{");
+ sb.append("\"id\": ").append(id).append(", ");
Review Comment:
If it's UUID_ZERO should we print out something special (like "none")?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]