Search in sources :

Example 1 with ResourceNotFoundException

use of org.apache.kafka.common.errors.ResourceNotFoundException in project kafka by apache.

the class DescribeUserScramCredentialsResult method description.

/**
 * @param userName the name of the user description being requested
 * @return a future indicating the description results for the given user. The future will complete exceptionally if
 * the future returned by {@link #users()} completes exceptionally.  Note that if the given user does not exist in
 * the list of described users then the returned future will complete exceptionally with
 * {@link org.apache.kafka.common.errors.ResourceNotFoundException}.
 */
public KafkaFuture<UserScramCredentialsDescription> description(String userName) {
    final KafkaFutureImpl<UserScramCredentialsDescription> retval = new KafkaFutureImpl<>();
    dataFuture.whenComplete((data, throwable) -> {
        if (throwable != null) {
            retval.completeExceptionally(throwable);
        } else {
            // it is possible that there is no future for this user (for example, the original describe request was
            // for users 1, 2, and 3 but this is looking for user 4), so explicitly take care of that case
            Optional<DescribeUserScramCredentialsResponseData.DescribeUserScramCredentialsResult> optionalUserResult = data.results().stream().filter(result -> result.user().equals(userName)).findFirst();
            if (!optionalUserResult.isPresent()) {
                retval.completeExceptionally(new ResourceNotFoundException("No such user: " + userName));
            } else {
                DescribeUserScramCredentialsResponseData.DescribeUserScramCredentialsResult userResult = optionalUserResult.get();
                if (userResult.errorCode() != Errors.NONE.code()) {
                    // RESOURCE_NOT_FOUND is included here
                    retval.completeExceptionally(Errors.forCode(userResult.errorCode()).exception(userResult.errorMessage()));
                } else {
                    retval.complete(new UserScramCredentialsDescription(userResult.user(), getScramCredentialInfosFor(userResult)));
                }
            }
        }
    });
    return retval;
}
Also used : Objects(java.util.Objects) List(java.util.List) ResourceNotFoundException(org.apache.kafka.common.errors.ResourceNotFoundException) InterfaceStability(org.apache.kafka.common.annotation.InterfaceStability) Map(java.util.Map) Errors(org.apache.kafka.common.protocol.Errors) Optional(java.util.Optional) HashMap(java.util.HashMap) KafkaFuture(org.apache.kafka.common.KafkaFuture) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) DescribeUserScramCredentialsResponseData(org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData) Collectors(java.util.stream.Collectors) DescribeUserScramCredentialsResponseData(org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ResourceNotFoundException(org.apache.kafka.common.errors.ResourceNotFoundException)

Aggregations

HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 KafkaFuture (org.apache.kafka.common.KafkaFuture)1 InterfaceStability (org.apache.kafka.common.annotation.InterfaceStability)1 ResourceNotFoundException (org.apache.kafka.common.errors.ResourceNotFoundException)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1 DescribeUserScramCredentialsResponseData (org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData)1 Errors (org.apache.kafka.common.protocol.Errors)1