16
16
*/
17
17
package org .apache .kafka .tools .reassign ;
18
18
19
- import org .apache .kafka .admin .BrokerMetadata ;
20
19
import org .apache .kafka .clients .admin .Admin ;
21
20
import org .apache .kafka .clients .admin .AdminClientConfig ;
22
21
import org .apache .kafka .clients .admin .AlterConfigOp ;
@@ -569,8 +568,8 @@ public static Entry<Map<TopicPartition, List<Integer>>, Map<TopicPartition, List
569
568
List <String > topicsToReassign = t0 .getValue ();
570
569
571
570
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 );
574
573
System .out .printf ("Current partition replica assignment%n%s%n%n" ,
575
574
formatAsReassignmentJson (currentAssignments , Collections .emptyMap ()));
576
575
System .out .printf ("Proposed partition reassignment configuration%n%s%n" ,
@@ -582,12 +581,12 @@ public static Entry<Map<TopicPartition, List<Integer>>, Map<TopicPartition, List
582
581
* Calculate the new partition assignments to suggest in --generate.
583
582
*
584
583
* @param currentAssignment The current partition assignments.
585
- * @param brokerMetadatas The rack information for each broker.
584
+ * @param brokers The rack information for each broker.
586
585
*
587
586
* @return A map from partitions to the proposed assignments for each.
588
587
*/
589
588
private static Map <TopicPartition , List <Integer >> calculateAssignment (Map <TopicPartition , List <Integer >> currentAssignment ,
590
- List <BrokerMetadata > brokerMetadatas ) {
589
+ List <UsableBroker > usableBrokers ) {
591
590
Map <String , List <Entry <TopicPartition , List <Integer >>>> groupedByTopic = new HashMap <>();
592
591
for (Entry <TopicPartition , List <Integer >> e : currentAssignment .entrySet ())
593
592
groupedByTopic .computeIfAbsent (e .getKey ().topic (), k -> new ArrayList <>()).add (e );
@@ -601,11 +600,7 @@ private static Map<TopicPartition, List<Integer>> calculateAssignment(Map<TopicP
601
600
new ClusterDescriber () {
602
601
@ Override
603
602
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 ();
609
604
}
610
605
611
606
@ Override
@@ -701,16 +696,16 @@ static Map<TopicPartition, List<Integer>> getReplicaAssignmentForPartitions(Admi
701
696
* @return The metadata for each broker that was found.
702
697
* Brokers that were not found will be omitted.
703
698
*/
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 {
705
700
Set <Integer > brokerSet = new HashSet <>(brokers );
706
- List <BrokerMetadata > results = adminClient .describeCluster ().nodes ().get ().stream ()
701
+ List <UsableBroker > results = adminClient .describeCluster ().nodes ().get ().stream ()
707
702
.filter (node -> brokerSet .contains (node .id ()))
708
703
.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 )
711
706
).collect (Collectors .toList ());
712
707
713
- long numRackless = results .stream ().filter (m -> m .rack .isEmpty ()).count ();
708
+ long numRackless = results .stream ().filter (m -> m .rack () .isEmpty ()).count ();
714
709
if (enableRackAwareness && numRackless != 0 && numRackless != results .size ()) {
715
710
throw new AdminOperationException ("Not all brokers have rack information. Add " +
716
711
"--disable-rack-aware in command line to make replica assignment without rack " +
0 commit comments