static Map<TopicPartition, Throwable> alterPartitionReassignments(Admin adminClient,
                                                                      Map<TopicPartition, List<Integer>> reassignments) throws InterruptedException {
        Map<TopicPartition, Optional<NewPartitionReassignment>> args = new HashMap<>();
        reassignments.forEach((part, replicas) -> args.put(part, Optional.of(new NewPartitionReassignment(replicas))));
        Map<TopicPartition, KafkaFuture<Void>> results = adminClient.alterPartitionReassignments(args).values();
        Map<TopicPartition, Throwable> errors = new HashMap<>();
        for (Entry<TopicPartition, KafkaFuture<Void>> e :  results.entrySet()) {
            try {
                e.getValue().get();
            } catch (ExecutionException t) {
                errors.put(e.getKey(), t.getCause());
            }
        }
        return errors;
    }
Execute the given partition reassignments.

@param adminClient       The admin client object to use.
@param reassignments     A map from topic names to target replica assignments.
@return                  A map from partition objects to error strings.
tools/src/main/java/org/apache/kafka/tools/reassign/ReassignPartitionsCommand.java