Search in sources :

Example 6 with AclBinding

use of org.apache.kafka.common.acl.AclBinding in project apache-kafka-on-k8s by banzaicloud.

the class DescribeAclsResponse method toStruct.

@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.DESCRIBE_ACLS.responseSchema(version));
    struct.set(THROTTLE_TIME_MS, throttleTimeMs);
    error.write(struct);
    Map<Resource, List<AccessControlEntry>> resourceToData = new HashMap<>();
    for (AclBinding acl : acls) {
        List<AccessControlEntry> entry = resourceToData.get(acl.resource());
        if (entry == null) {
            entry = new ArrayList<>();
            resourceToData.put(acl.resource(), entry);
        }
        entry.add(acl.entry());
    }
    List<Struct> resourceStructs = new ArrayList<>();
    for (Map.Entry<Resource, List<AccessControlEntry>> tuple : resourceToData.entrySet()) {
        Resource resource = tuple.getKey();
        Struct resourceStruct = struct.instance(RESOURCES_KEY_NAME);
        RequestUtils.resourceSetStructFields(resource, resourceStruct);
        List<Struct> dataStructs = new ArrayList<>();
        for (AccessControlEntry entry : tuple.getValue()) {
            Struct dataStruct = resourceStruct.instance(ACLS_KEY_NAME);
            RequestUtils.aceSetStructFields(entry, dataStruct);
            dataStructs.add(dataStruct);
        }
        resourceStruct.set(ACLS_KEY_NAME, dataStructs.toArray());
        resourceStructs.add(resourceStruct);
    }
    struct.set(RESOURCES_KEY_NAME, resourceStructs.toArray());
    return struct;
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.kafka.common.resource.Resource) ArrayList(java.util.ArrayList) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) Struct(org.apache.kafka.common.protocol.types.Struct) ArrayList(java.util.ArrayList) List(java.util.List) AclBinding(org.apache.kafka.common.acl.AclBinding) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AclBinding (org.apache.kafka.common.acl.AclBinding)6 ArrayList (java.util.ArrayList)4 AccessControlEntry (org.apache.kafka.common.acl.AccessControlEntry)3 Resource (org.apache.kafka.common.resource.Resource)3 HashMap (java.util.HashMap)2 List (java.util.List)2 KafkaFuture (org.apache.kafka.common.KafkaFuture)2 ApiError (org.apache.kafka.common.requests.ApiError)2 AclCreation (org.apache.kafka.common.requests.CreateAclsRequest.AclCreation)2 AclDeletionResult (org.apache.kafka.common.requests.DeleteAclsResponse.AclDeletionResult)2 AclFilterResponse (org.apache.kafka.common.requests.DeleteAclsResponse.AclFilterResponse)2 Test (org.junit.Test)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 FilterResults (org.apache.kafka.clients.admin.DeleteAclsResult.FilterResults)1 AclBindingFilter (org.apache.kafka.common.acl.AclBindingFilter)1 InvalidRequestException (org.apache.kafka.common.errors.InvalidRequestException)1 UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1