Search in sources :

Example 1 with DeleteAclsMatchingAcl

use of org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl in project kafka by apache.

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> aclBindingFiltersSent = new ArrayList<>();
    final List<DeleteAclsFilter> deleteAclsFilters = new ArrayList<>();
    for (AclBindingFilter filter : filters) {
        if (futures.get(filter) == null) {
            aclBindingFiltersSent.add(filter);
            deleteAclsFilters.add(DeleteAclsRequest.deleteAclsFilter(filter));
            futures.put(filter, new KafkaFutureImpl<>());
        }
    }
    final DeleteAclsRequestData data = new DeleteAclsRequestData().setFilters(deleteAclsFilters);
    runnable.call(new Call("deleteAcls", calcDeadlineMs(now, options.timeoutMs()), new LeastLoadedNodeProvider()) {

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

        @Override
        void handleResponse(AbstractResponse abstractResponse) {
            DeleteAclsResponse response = (DeleteAclsResponse) abstractResponse;
            List<DeleteAclsResponseData.DeleteAclsFilterResult> results = response.filterResults();
            Iterator<DeleteAclsResponseData.DeleteAclsFilterResult> iter = results.iterator();
            for (AclBindingFilter bindingFilter : aclBindingFiltersSent) {
                KafkaFutureImpl<FilterResults> future = futures.get(bindingFilter);
                if (!iter.hasNext()) {
                    future.completeExceptionally(new UnknownServerException("The broker reported no deletion result for the given filter."));
                } else {
                    DeleteAclsFilterResult filterResult = iter.next();
                    ApiError error = new ApiError(Errors.forCode(filterResult.errorCode()), filterResult.errorMessage());
                    if (error.isFailure()) {
                        future.completeExceptionally(error.exception());
                    } else {
                        List<FilterResult> filterResults = new ArrayList<>();
                        for (DeleteAclsMatchingAcl matchingAcl : filterResult.matchingAcls()) {
                            ApiError aclError = new ApiError(Errors.forCode(matchingAcl.errorCode()), matchingAcl.errorMessage());
                            AclBinding aclBinding = DeleteAclsResponse.aclBinding(matchingAcl);
                            filterResults.add(new FilterResult(aclBinding, aclError.exception()));
                        }
                        future.complete(new FilterResults(filterResults));
                    }
                }
            }
        }

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

Example 2 with DeleteAclsMatchingAcl

use of org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl in project kafka by apache.

the class DeleteAclsResponse method filterResult.

public static DeleteAclsFilterResult filterResult(AclDeleteResult result) {
    ApiError error = result.exception().map(e -> ApiError.fromThrowable(e)).orElse(ApiError.NONE);
    List<DeleteAclsMatchingAcl> matchingAcls = result.aclBindingDeleteResults().stream().map(DeleteAclsResponse::matchingAcl).collect(Collectors.toList());
    return new DeleteAclsFilterResult().setErrorCode(error.error().code()).setErrorMessage(error.message()).setMatchingAcls(matchingAcls);
}
Also used : Logger(org.slf4j.Logger) DeleteAclsMatchingAcl(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) AclPermissionType(org.apache.kafka.common.acl.AclPermissionType) LoggerFactory(org.slf4j.LoggerFactory) DeleteAclsFilterResult(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult) ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) AclOperation(org.apache.kafka.common.acl.AclOperation) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) PatternType(org.apache.kafka.common.resource.PatternType) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) List(java.util.List) ResourceType(org.apache.kafka.common.resource.ResourceType) AclBinding(org.apache.kafka.common.acl.AclBinding) Map(java.util.Map) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Errors(org.apache.kafka.common.protocol.Errors) DeleteAclsFilterResult(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult) DeleteAclsMatchingAcl(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl)

Example 3 with DeleteAclsMatchingAcl

use of org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl in project kafka by apache.

the class DeleteAclsResponse method matchingAcl.

private static DeleteAclsMatchingAcl matchingAcl(AclDeleteResult.AclBindingDeleteResult result) {
    ApiError error = result.exception().map(e -> ApiError.fromThrowable(e)).orElse(ApiError.NONE);
    AclBinding acl = result.aclBinding();
    return matchingAcl(acl, error);
}
Also used : Logger(org.slf4j.Logger) DeleteAclsMatchingAcl(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) AclPermissionType(org.apache.kafka.common.acl.AclPermissionType) LoggerFactory(org.slf4j.LoggerFactory) DeleteAclsFilterResult(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult) ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) AclOperation(org.apache.kafka.common.acl.AclOperation) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) PatternType(org.apache.kafka.common.resource.PatternType) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) List(java.util.List) ResourceType(org.apache.kafka.common.resource.ResourceType) AclBinding(org.apache.kafka.common.acl.AclBinding) Map(java.util.Map) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Errors(org.apache.kafka.common.protocol.Errors) AclBinding(org.apache.kafka.common.acl.AclBinding)

Aggregations

List (java.util.List)3 AclBinding (org.apache.kafka.common.acl.AclBinding)3 DeleteAclsResponseData (org.apache.kafka.common.message.DeleteAclsResponseData)3 DeleteAclsFilterResult (org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult)3 DeleteAclsMatchingAcl (org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl)3 ByteBuffer (java.nio.ByteBuffer)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 AccessControlEntry (org.apache.kafka.common.acl.AccessControlEntry)2 AclOperation (org.apache.kafka.common.acl.AclOperation)2 AclPermissionType (org.apache.kafka.common.acl.AclPermissionType)2 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)2 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)2 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)2 Errors (org.apache.kafka.common.protocol.Errors)2 PatternType (org.apache.kafka.common.resource.PatternType)2 ResourcePattern (org.apache.kafka.common.resource.ResourcePattern)2 ResourceType (org.apache.kafka.common.resource.ResourceType)2 AclDeleteResult (org.apache.kafka.server.authorizer.AclDeleteResult)2 Logger (org.slf4j.Logger)2