rondagostino commented on a change in pull request #9032: URL: https://github.com/apache/kafka/pull/9032#discussion_r475756645
########## File path: clients/src/main/java/org/apache/kafka/clients/admin/DescribeUserScramCredentialsResult.java ########## @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.clients.admin; + +import org.apache.kafka.common.KafkaFuture; +import org.apache.kafka.common.annotation.InterfaceStability; +import org.apache.kafka.common.errors.ResourceNotFoundException; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +/** + * The result of the {@link Admin#describeUserScramCredentials()} call. + * + * The API of this class is evolving, see {@link Admin} for details. + */ +@InterfaceStability.Evolving +public class DescribeUserScramCredentialsResult { + private final KafkaFuture<List<String>> usersFuture; + private final Map<String, KafkaFuture<UserScramCredentialsDescription>> perUserFutures; + + /** + * + * @param usersFuture the future indicating the users described by the call + * @param perUserFutures the required map of user names to futures representing the results of describing each + * user's SCRAM credentials. + */ + public DescribeUserScramCredentialsResult(KafkaFuture<List<String>> usersFuture, + Map<String, KafkaFuture<UserScramCredentialsDescription>> perUserFutures) { + this.usersFuture = Objects.requireNonNull(usersFuture); + this.perUserFutures = Objects.requireNonNull(perUserFutures); + } + + /** + * + * @return a future for the results of all requested (either explicitly or implicitly via describe-all) users. + * The future will complete successfully only if the users future first completes successfully and then all the + * futures for the user descriptions complete successfully. + */ + public KafkaFuture<Map<String, UserScramCredentialsDescription>> all() { + KafkaFuture<Void> succeedsOnlyIfUsersFutureSucceeds = KafkaFuture.allOf(users()); + return succeedsOnlyIfUsersFutureSucceeds.thenApply(void1 -> { + KafkaFuture<Void> succeedsOnlyIfAllDescriptionsSucceed = KafkaFuture.allOf(perUserFutures.values().toArray( + new KafkaFuture[perUserFutures.size()])); + KafkaFuture<Map<String, UserScramCredentialsDescription>> mapFuture = succeedsOnlyIfAllDescriptionsSucceed.thenApply(void2 -> + perUserFutures.entrySet().stream().collect(Collectors.toMap( + e -> e.getKey(), + e -> valueFromFutureGuaranteedToSucceedAtThisPoint(e.getValue())))); + /* At this point it is only the users future that is guaranteed to have succeeded. + * We want to return the future to the map, but we have to return a map at this point. + * We need to dereference the future while propagating any exception. + */ + return valueFromFuturePropagatingExceptionsAsUnchecked(mapFuture); + }); + } + + /** + * + * @return a future indicating the distinct users that were requested (either explicitly or implicitly via Review comment: We've gone back and forth on this. The KIP does not explicitly state what to do in the case of a describe request for a user that does not have credentials, and we originally coded it to silently drop them, but then we changed it to be consistent with other APIs and raise an error (https://github.com/apache/kafka/pull/9032#discussion_r468871453). I agree that it isn't totally clear what to do. Rather than making the change back, I'll leave both this Javadoc and the underlying implementation as-is right now unill we discuss further and decide for sure what we want. ---------------------------------------------------------------- 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