You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "chia7712 (via GitHub)" <gi...@apache.org> on 2026/07/03 16:37:29 UTC
Re: [PR] KAFKA-19663: kafka-broker-api tool should support to get controller api version [kafka]
chia7712 commented on code in PR #20598:
URL: https://github.com/apache/kafka/pull/20598#discussion_r3521020495
##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/DescribeFeaturesTest.java:
##########
@@ -29,15 +32,39 @@
import org.apache.kafka.server.common.StreamsVersion;
import org.apache.kafka.server.common.TransactionVersion;
+import java.util.Arrays;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class DescribeFeaturesTest {
+ @ClusterTest(types = {Type.KRAFT})
+ public void testApiVersions(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+ var all = Arrays.stream(ApiKeys.values()).collect(Collectors.toMap(v -> v.id, v -> v));
+ try (Admin admin = clusterInstance.admin()) {
+ var versions = ((InternalDescribeFeaturesResult) admin.describeFeatures()).nodeApiVersions().get();
+ versions.allSupportedApiVersions().forEach((key, version) -> {
+ var apiKey = Objects.requireNonNull(all.get(key.id));
+ assertTrue(apiKey.inScope(ApiMessageType.ListenerType.BROKER));
+ });
+ }
+
+ try (Admin admin = clusterInstance.admin(Map.of(), true)) {
+ var versions = ((InternalDescribeFeaturesResult) admin.describeFeatures()).nodeApiVersions().get();
+ versions.allSupportedApiVersions().forEach((key, versionv) -> {
Review Comment:
typo: versionv -> version
##########
tools/src/main/java/org/apache/kafka/tools/ClusterTool.java:
##########
@@ -208,4 +222,23 @@ static void listEndpoints(PrintStream stream, Admin adminClient, boolean listCon
}
}
}
+
+ static void apiVersionsCommand(PrintStream stream, Admin adminClient) throws Exception {
+ Collection<Node> nodes = adminClient.describeCluster().nodes().get();
+ Map<Node, InternalDescribeFeaturesResult> nodeApiVersions = new TreeMap<>(Comparator.comparingInt(Node::id));
+ nodes.forEach(node -> {
+ InternalDescribeFeaturesResult result = (InternalDescribeFeaturesResult) adminClient.describeFeatures(
+ new DescribeFeaturesOptions().nodeId(node.id()));
+ nodeApiVersions.put(node, result);
+ });
+
+ nodeApiVersions.forEach((broker, future) -> {
+ try {
+ NodeApiVersions apiVersions = future.nodeApiVersions().get();
+ stream.print(broker + " -> " + apiVersions.toString(true) + "\n");
+ } catch (Exception e) {
+ stream.print(broker + " -> ERROR: " + e.getMessage() + "\n");
Review Comment:
Do we need to unwrap it?
##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -4571,8 +4578,11 @@ void handleResponse(AbstractResponse response) {
final ApiVersionsResponse apiVersionsResponse = (ApiVersionsResponse) response;
if (apiVersionsResponse.data().errorCode() == Errors.NONE.code()) {
future.complete(createFeatureMetadata(apiVersionsResponse));
+ nodeApiVersionsFuture.complete(createNodeApiVersion(apiVersionsResponse));
} else {
- future.completeExceptionally(Errors.forCode(apiVersionsResponse.data().errorCode()).exception());
+ Exception excpetion = Errors.forCode(apiVersionsResponse.data().errorCode()).exception();
Review Comment:
typo: excpetion -> exception
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org