Search in sources :

Example 1 with FilterResult

use of org.apache.kafka.clients.admin.DeleteAclsResult.FilterResult in project apache-kafka-on-k8s by banzaicloud.

the class KafkaAdminClient method deleteAcls.

@Override
public DeleteAclsResult deleteAcls(Collection<AclBindingFilter> filters, DeleteAclsOptions options) {
    final long now = time.milliseconds();
    final Map<AclBindingFilter, KafkaFutureImpl<FilterResults>> futures = new HashMap<>();
    final List<AclBindingFilter> filterList = new ArrayList<>();
    for (AclBindingFilter filter : filters) {
        if (futures.get(filter) == null) {
            filterList.add(filter);
            futures.put(filter, new KafkaFutureImpl<FilterResults>());
        }
    }
    runnable.call(new Call("deleteAcls", calcDeadlineMs(now, options.timeoutMs()), new LeastLoadedNodeProvider()) {

        @Override
        AbstractRequest.Builder createRequest(int timeoutMs) {
            return new DeleteAclsRequest.Builder(filterList);
        }

        @Override
        void handleResponse(AbstractResponse abstractResponse) {
            DeleteAclsResponse response = (DeleteAclsResponse) abstractResponse;
            List<AclFilterResponse> responses = response.responses();
            Iterator<AclFilterResponse> iter = responses.iterator();
            for (AclBindingFilter filter : filterList) {
                KafkaFutureImpl<FilterResults> future = futures.get(filter);
                if (!iter.hasNext()) {
                    future.completeExceptionally(new UnknownServerException("The broker reported no deletion result for the given filter."));
                } else {
                    AclFilterResponse deletion = iter.next();
                    if (deletion.error().isFailure()) {
                        future.completeExceptionally(deletion.error().exception());
                    } else {
                        List<FilterResult> filterResults = new ArrayList<>();
                        for (AclDeletionResult deletionResult : deletion.deletions()) {
                            filterResults.add(new FilterResult(deletionResult.acl(), deletionResult.error().exception()));
                        }
                        future.complete(new FilterResults(filterResults));
                    }
                }
            }
        }

        @Override
        void handleFailure(Throwable throwable) {
            completeAllExceptionally(futures.values(), throwable);
        }
    }, now);
    return new DeleteAclsResult(new HashMap<AclBindingFilter, KafkaFuture<FilterResults>>(futures));
}
Also used : HashMap(java.util.HashMap) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) ArrayList(java.util.ArrayList) DeleteAclsResponse(org.apache.kafka.common.requests.DeleteAclsResponse) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) FilterResults(org.apache.kafka.clients.admin.DeleteAclsResult.FilterResults) AclBindingFilter(org.apache.kafka.common.acl.AclBindingFilter) KafkaFuture(org.apache.kafka.common.KafkaFuture) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) AclDeletionResult(org.apache.kafka.common.requests.DeleteAclsResponse.AclDeletionResult) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) DeleteAclsRequest(org.apache.kafka.common.requests.DeleteAclsRequest) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) AclFilterResponse(org.apache.kafka.common.requests.DeleteAclsResponse.AclFilterResponse) FilterResult(org.apache.kafka.clients.admin.DeleteAclsResult.FilterResult)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 FilterResult (org.apache.kafka.clients.admin.DeleteAclsResult.FilterResult)1 FilterResults (org.apache.kafka.clients.admin.DeleteAclsResult.FilterResults)1 KafkaFuture (org.apache.kafka.common.KafkaFuture)1 AclBindingFilter (org.apache.kafka.common.acl.AclBindingFilter)1 UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1 DeleteAclsRequest (org.apache.kafka.common.requests.DeleteAclsRequest)1 DeleteAclsResponse (org.apache.kafka.common.requests.DeleteAclsResponse)1 AclDeletionResult (org.apache.kafka.common.requests.DeleteAclsResponse.AclDeletionResult)1 AclFilterResponse (org.apache.kafka.common.requests.DeleteAclsResponse.AclFilterResponse)1