Search in sources :

Example 1 with DescribeAclsResource

use of org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource in project kafka by apache.

the class DescribeAclsResponseTest method shouldRoundTripV0.

@Test
public void shouldRoundTripV0() {
    List<DescribeAclsResource> resources = Arrays.asList(LITERAL_ACL1, LITERAL_ACL2);
    final DescribeAclsResponse original = buildResponse(10, Errors.NONE, resources);
    final ByteBuffer buffer = original.serialize(V0);
    final DescribeAclsResponse result = DescribeAclsResponse.parse(buffer, V0);
    assertResponseEquals(original, result);
    final DescribeAclsResponse result2 = buildResponse(10, Errors.NONE, DescribeAclsResponse.aclsResources(DescribeAclsResponse.aclBindings(resources)));
    assertResponseEquals(original, result2);
}
Also used : DescribeAclsResource(org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 2 with DescribeAclsResource

use of org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource in project kafka by apache.

the class DescribeAclsResponse method aclsResources.

public static List<DescribeAclsResource> aclsResources(Collection<AclBinding> acls) {
    Map<ResourcePattern, List<AccessControlEntry>> patternToEntries = new HashMap<>();
    for (AclBinding acl : acls) {
        patternToEntries.computeIfAbsent(acl.pattern(), v -> new ArrayList<>()).add(acl.entry());
    }
    List<DescribeAclsResource> resources = new ArrayList<>(patternToEntries.size());
    for (Entry<ResourcePattern, List<AccessControlEntry>> entry : patternToEntries.entrySet()) {
        ResourcePattern key = entry.getKey();
        List<AclDescription> aclDescriptions = new ArrayList<>();
        for (AccessControlEntry ace : entry.getValue()) {
            AclDescription ad = new AclDescription().setHost(ace.host()).setOperation(ace.operation().code()).setPermissionType(ace.permissionType().code()).setPrincipal(ace.principal());
            aclDescriptions.add(ad);
        }
        DescribeAclsResource dar = new DescribeAclsResource().setResourceName(key.name()).setPatternType(key.patternType().code()).setResourceType(key.resourceType().code()).setAcls(aclDescriptions);
        resources.add(dar);
    }
    return resources;
}
Also used : DescribeAclsResponseData(org.apache.kafka.common.message.DescribeAclsResponseData) Collection(java.util.Collection) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) AclPermissionType(org.apache.kafka.common.acl.AclPermissionType) HashMap(java.util.HashMap) ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) AclOperation(org.apache.kafka.common.acl.AclOperation) DescribeAclsResource(org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) PatternType(org.apache.kafka.common.resource.PatternType) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) List(java.util.List) Stream(java.util.stream.Stream) ResourceType(org.apache.kafka.common.resource.ResourceType) AclDescription(org.apache.kafka.common.message.DescribeAclsResponseData.AclDescription) AclBinding(org.apache.kafka.common.acl.AclBinding) Map(java.util.Map) Entry(java.util.Map.Entry) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Errors(org.apache.kafka.common.protocol.Errors) Optional(java.util.Optional) DescribeAclsResource(org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource) HashMap(java.util.HashMap) ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) ArrayList(java.util.ArrayList) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) ArrayList(java.util.ArrayList) List(java.util.List) AclBinding(org.apache.kafka.common.acl.AclBinding) AclDescription(org.apache.kafka.common.message.DescribeAclsResponseData.AclDescription)

Example 3 with DescribeAclsResource

use of org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource in project kafka by apache.

the class DescribeAclsResponseTest method shouldRoundTripV1.

@Test
public void shouldRoundTripV1() {
    List<DescribeAclsResource> resources = Arrays.asList(LITERAL_ACL1, PREFIXED_ACL1);
    final DescribeAclsResponse original = buildResponse(100, Errors.NONE, resources);
    final ByteBuffer buffer = original.serialize(V1);
    final DescribeAclsResponse result = DescribeAclsResponse.parse(buffer, V1);
    assertResponseEquals(original, result);
    final DescribeAclsResponse result2 = buildResponse(100, Errors.NONE, DescribeAclsResponse.aclsResources(DescribeAclsResponse.aclBindings(resources)));
    assertResponseEquals(original, result2);
}
Also used : DescribeAclsResource(org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)3 DescribeAclsResource (org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource)3 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 AccessControlEntry (org.apache.kafka.common.acl.AccessControlEntry)1 AclBinding (org.apache.kafka.common.acl.AclBinding)1 AclOperation (org.apache.kafka.common.acl.AclOperation)1 AclPermissionType (org.apache.kafka.common.acl.AclPermissionType)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1 DescribeAclsResponseData (org.apache.kafka.common.message.DescribeAclsResponseData)1 AclDescription (org.apache.kafka.common.message.DescribeAclsResponseData.AclDescription)1 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)1