Search in sources :

Example 1 with DescribeUserScramCredentialsRequestData

use of org.apache.kafka.common.message.DescribeUserScramCredentialsRequestData in project kafka by apache.

the class KafkaAdminClient method describeUserScramCredentials.

@Override
public DescribeUserScramCredentialsResult describeUserScramCredentials(List<String> users, DescribeUserScramCredentialsOptions options) {
    final KafkaFutureImpl<DescribeUserScramCredentialsResponseData> dataFuture = new KafkaFutureImpl<>();
    final long now = time.milliseconds();
    Call call = new Call("describeUserScramCredentials", calcDeadlineMs(now, options.timeoutMs()), new LeastLoadedNodeProvider()) {

        @Override
        public DescribeUserScramCredentialsRequest.Builder createRequest(final int timeoutMs) {
            final DescribeUserScramCredentialsRequestData requestData = new DescribeUserScramCredentialsRequestData();
            if (users != null && !users.isEmpty()) {
                final List<UserName> userNames = new ArrayList<>(users.size());
                for (final String user : users) {
                    if (user != null) {
                        userNames.add(new UserName().setName(user));
                    }
                }
                requestData.setUsers(userNames);
            }
            return new DescribeUserScramCredentialsRequest.Builder(requestData);
        }

        @Override
        public void handleResponse(AbstractResponse abstractResponse) {
            DescribeUserScramCredentialsResponse response = (DescribeUserScramCredentialsResponse) abstractResponse;
            DescribeUserScramCredentialsResponseData data = response.data();
            short messageLevelErrorCode = data.errorCode();
            if (messageLevelErrorCode != Errors.NONE.code()) {
                dataFuture.completeExceptionally(Errors.forCode(messageLevelErrorCode).exception(data.errorMessage()));
            } else {
                dataFuture.complete(data);
            }
        }

        @Override
        void handleFailure(Throwable throwable) {
            dataFuture.completeExceptionally(throwable);
        }
    };
    runnable.call(call, now);
    return new DescribeUserScramCredentialsResult(dataFuture);
}
Also used : UserName(org.apache.kafka.common.message.DescribeUserScramCredentialsRequestData.UserName) DescribeUserScramCredentialsRequestData(org.apache.kafka.common.message.DescribeUserScramCredentialsRequestData) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) ArrayList(java.util.ArrayList) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) DescribeUserScramCredentialsResponseData(org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData) DescribeUserScramCredentialsRequest(org.apache.kafka.common.requests.DescribeUserScramCredentialsRequest) DescribeUserScramCredentialsResponse(org.apache.kafka.common.requests.DescribeUserScramCredentialsResponse)

Aggregations

ArrayList (java.util.ArrayList)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1 DescribeUserScramCredentialsRequestData (org.apache.kafka.common.message.DescribeUserScramCredentialsRequestData)1 UserName (org.apache.kafka.common.message.DescribeUserScramCredentialsRequestData.UserName)1 DescribeUserScramCredentialsResponseData (org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData)1 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1 DescribeUserScramCredentialsRequest (org.apache.kafka.common.requests.DescribeUserScramCredentialsRequest)1 DescribeUserScramCredentialsResponse (org.apache.kafka.common.requests.DescribeUserScramCredentialsResponse)1