KAFKA-19109 Don't print null in kafka-metadata-quorum describe status (#19543)

If directory id is `Uuid.ZERO_UUID`, the command don't print the result.

Reviewers: Ken Huang <s7133700@gmail.com>, TengYao Chi
 <frankvicky@apache.org>, Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
PoAn Yang 2025-05-10 10:48:05 -05:00 committed by GitHub
parent 3696c49788
commit 61cb33f347
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -315,8 +315,10 @@ public class MetadataQuorumCommand {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("\"id\": ").append(id).append(", ");
sb.append("\"directoryId\": ").append(directoryId.equals(Uuid.ZERO_UUID) ? "null" : "\"" + directoryId + "\"");
sb.append("\"id\": ").append(id);
if (!directoryId.equals(Uuid.ZERO_UUID)) {
sb.append(", ").append("\"directoryId\": ").append("\"").append(directoryId).append("\"");
}
if (!endpoints.isEmpty()) {
sb.append(", \"endpoints\": [");
for (RaftVoterEndpoint endpoint : endpoints) {

View File

@ -116,7 +116,7 @@ class MetadataQuorumCommandTest {
assertTrue(outputs[4].matches("MaxFollowerLag:\\s+\\d+"), describeOutput);
assertTrue(outputs[5].matches("MaxFollowerLagTimeMs:\\s+-?\\d+"), describeOutput);
assertTrue(
outputs[6].matches("CurrentVoters:\\s+\\[\\{\"id\":\\s+\\d+,\\s+\"directoryId\":\\s+\\S+,\\s+" +
outputs[6].matches("CurrentVoters:\\s+\\[\\{\"id\":\\s+\\d+,\\s+" +
"\"endpoints\":\\s+\\[\"\\S+://\\[?\\S+]?:\\d+\",?.*]"),
describeOutput
);