static Map<TopicPartition, List<Integer>> getReplicaAssignmentForPartitions(Admin adminClient,
                                                                                Set<TopicPartition> partitions
    ) throws ExecutionException, InterruptedException {
        Map<TopicPartition, List<Integer>> res = new HashMap<>();
        describeTopics(adminClient, partitions.stream().map(TopicPartition::topic).collect(Collectors.toSet())).forEach((topicName, topicDescription) ->
            topicDescription.partitions().forEach(info -> {
                TopicPartition tp = new TopicPartition(topicName, info.partition());
                if (partitions.contains(tp))
                    res.put(tp, info.replicas().stream().map(Node::id).collect(Collectors.toList()));
            })
        );

        if (!res.keySet().equals(partitions)) {
            Set<TopicPartition> missingPartitions = new HashSet<>(partitions);
            missingPartitions.removeAll(res.keySet());
            throw new ExecutionException(new UnknownTopicOrPartitionException("Unable to find partition: " +
                missingPartitions.stream().map(TopicPartition::toString).collect(Collectors.joining(", "))));
        }
        return res;
    }
Get the current replica assignments for some partitions.

@param adminClient     The AdminClient to use.
@param partitions      The partitions to get information about.
@return                A map from partitions to broker assignments.
                       If any topic or partition can't be found, an exception will be thrown.
tools/src/main/java/org/apache/kafka/tools/reassign/ReassignPartitionsCommand.java