dengziming commented on a change in pull request #9769: URL: https://github.com/apache/kafka/pull/9769#discussion_r556180111
########## File path: core/src/main/scala/kafka/admin/TopicCommand.scala ########## @@ -313,42 +313,54 @@ object TopicCommand extends Logging { } override def describeTopic(opts: TopicCommandOptions): Unit = { - val topics = getTopics(opts.topic, opts.excludeInternalTopics) - ensureTopicExists(topics, opts.topic, !opts.ifExists) + val topicId = opts.topicId.map(Uuid.fromString).filter(_ != Uuid.ZERO_UUID) + val topics = if (topicId.isEmpty) + getTopics(opts.topic, opts.excludeInternalTopics) + else + Seq() - if (topics.nonEmpty) { - val allConfigs = adminClient.describeConfigs(topics.map(new ConfigResource(Type.TOPIC, _)).asJavaCollection).values() - val liveBrokers = adminClient.describeCluster().nodes().get().asScala.map(_.id()) - val topicDescriptions = adminClient.describeTopics(topics.asJavaCollection).all().get().values().asScala - val describeOptions = new DescribeOptions(opts, liveBrokers.toSet) - val topicPartitions = topicDescriptions - .flatMap(td => td.partitions.iterator().asScala.map(p => new TopicPartition(td.name(), p.partition()))) - .toSet.asJava - val reassignments = listAllReassignments(topicPartitions) - - for (td <- topicDescriptions) { - val topicName = td.name - val topicId = td.topicId() - val config = allConfigs.get(new ConfigResource(Type.TOPIC, topicName)).get() - val sortedPartitions = td.partitions.asScala.sortBy(_.partition) - - if (describeOptions.describeConfigs) { - val hasNonDefault = config.entries().asScala.exists(!_.isDefault) - if (!opts.reportOverriddenConfigs || hasNonDefault) { - val numPartitions = td.partitions().size - val firstPartition = td.partitions.iterator.next() - val reassignment = reassignments.get(new TopicPartition(td.name, firstPartition.partition)) - val topicDesc = TopicDescription(topicName, topicId, numPartitions, getReplicationFactor(firstPartition, reassignment), config, markedForDeletion = false) - topicDesc.printDescription() - } + if (topicId.isEmpty) + ensureTopicExists(topics, opts.topic, !opts.ifExists) Review comment: Here, if topic is provided, we ensure topic exists since the given topic maybe a regular expr. should we also check the topicId exists? then we should add a listTopicId method `listTopicIds` in the AdminClient ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org