1616 */
1717package org .apache .kafka .tools .reassign ;
1818
19- import org .apache .kafka .admin .BrokerMetadata ;
2019import org .apache .kafka .clients .admin .Admin ;
2120import org .apache .kafka .clients .admin .AdminClientConfig ;
2221import org .apache .kafka .clients .admin .AlterConfigOp ;
@@ -569,8 +568,8 @@ public static Entry<Map<TopicPartition, List<Integer>>, Map<TopicPartition, List
569568 List <String > topicsToReassign = t0 .getValue ();
570569
571570 Map <TopicPartition , List <Integer >> currentAssignments = getReplicaAssignmentForTopics (adminClient , topicsToReassign );
572- List <BrokerMetadata > brokerMetadatas = getBrokerMetadata (adminClient , brokersToReassign , enableRackAwareness );
573- Map <TopicPartition , List <Integer >> proposedAssignments = calculateAssignment (currentAssignments , brokerMetadatas );
571+ List <UsableBroker > usableBrokers = getBrokerMetadata (adminClient , brokersToReassign , enableRackAwareness );
572+ Map <TopicPartition , List <Integer >> proposedAssignments = calculateAssignment (currentAssignments , usableBrokers );
574573 System .out .printf ("Current partition replica assignment%n%s%n%n" ,
575574 formatAsReassignmentJson (currentAssignments , Collections .emptyMap ()));
576575 System .out .printf ("Proposed partition reassignment configuration%n%s%n" ,
@@ -582,12 +581,12 @@ public static Entry<Map<TopicPartition, List<Integer>>, Map<TopicPartition, List
582581 * Calculate the new partition assignments to suggest in --generate.
583582 *
584583 * @param currentAssignment The current partition assignments.
585- * @param brokerMetadatas The rack information for each broker.
584+ * @param brokers The rack information for each broker.
586585 *
587586 * @return A map from partitions to the proposed assignments for each.
588587 */
589588 private static Map <TopicPartition , List <Integer >> calculateAssignment (Map <TopicPartition , List <Integer >> currentAssignment ,
590- List <BrokerMetadata > brokerMetadatas ) {
589+ List <UsableBroker > usableBrokers ) {
591590 Map <String , List <Entry <TopicPartition , List <Integer >>>> groupedByTopic = new HashMap <>();
592591 for (Entry <TopicPartition , List <Integer >> e : currentAssignment .entrySet ())
593592 groupedByTopic .computeIfAbsent (e .getKey ().topic (), k -> new ArrayList <>()).add (e );
@@ -601,11 +600,7 @@ private static Map<TopicPartition, List<Integer>> calculateAssignment(Map<TopicP
601600 new ClusterDescriber () {
602601 @ Override
603602 public Iterator <UsableBroker > usableBrokers () {
604- return brokerMetadatas .stream ().map (brokerMetadata -> new UsableBroker (
605- brokerMetadata .id ,
606- brokerMetadata .rack ,
607- false
608- )).iterator ();
603+ return usableBrokers .iterator ();
609604 }
610605
611606 @ Override
@@ -701,16 +696,16 @@ static Map<TopicPartition, List<Integer>> getReplicaAssignmentForPartitions(Admi
701696 * @return The metadata for each broker that was found.
702697 * Brokers that were not found will be omitted.
703698 */
704- static List <BrokerMetadata > getBrokerMetadata (Admin adminClient , List <Integer > brokers , boolean enableRackAwareness ) throws ExecutionException , InterruptedException {
699+ static List <UsableBroker > getBrokerMetadata (Admin adminClient , List <Integer > brokers , boolean enableRackAwareness ) throws ExecutionException , InterruptedException {
705700 Set <Integer > brokerSet = new HashSet <>(brokers );
706- List <BrokerMetadata > results = adminClient .describeCluster ().nodes ().get ().stream ()
701+ List <UsableBroker > results = adminClient .describeCluster ().nodes ().get ().stream ()
707702 .filter (node -> brokerSet .contains (node .id ()))
708703 .map (node -> (enableRackAwareness && node .rack () != null )
709- ? new BrokerMetadata (node .id (), Optional .of (node .rack ()))
710- : new BrokerMetadata (node .id (), Optional .empty ())
704+ ? new UsableBroker (node .id (), Optional .of (node .rack ()), false )
705+ : new UsableBroker (node .id (), Optional .empty (), false )
711706 ).collect (Collectors .toList ());
712707
713- long numRackless = results .stream ().filter (m -> m .rack .isEmpty ()).count ();
708+ long numRackless = results .stream ().filter (m -> m .rack () .isEmpty ()).count ();
714709 if (enableRackAwareness && numRackless != 0 && numRackless != results .size ()) {
715710 throw new AdminOperationException ("Not all brokers have rack information. Add " +
716711 "--disable-rack-aware in command line to make replica assignment without rack " +
0 commit comments