Search in sources :

Example 1 with DeleteAclsResponseData

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

the class DeleteAclsResponseTest method shouldRoundTripV0.

@Test
public void shouldRoundTripV0() {
    final DeleteAclsResponse original = new DeleteAclsResponse(new DeleteAclsResponseData().setThrottleTimeMs(10).setFilterResults(singletonList(LITERAL_RESPONSE)), V0);
    final ByteBuffer buffer = original.serialize(V0);
    final DeleteAclsResponse result = DeleteAclsResponse.parse(buffer, V0);
    assertEquals(original.filterResults(), result.filterResults());
}
Also used : DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 2 with DeleteAclsResponseData

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

the class RequestResponseTest method createDeleteAclsResponse.

private DeleteAclsResponse createDeleteAclsResponse(short version) {
    List<DeleteAclsResponseData.DeleteAclsFilterResult> filterResults = new ArrayList<>();
    filterResults.add(new DeleteAclsResponseData.DeleteAclsFilterResult().setMatchingAcls(asList(new DeleteAclsResponseData.DeleteAclsMatchingAcl().setResourceType(ResourceType.TOPIC.code()).setResourceName("mytopic3").setPatternType(PatternType.LITERAL.code()).setPrincipal("User:ANONYMOUS").setHost("*").setOperation(AclOperation.DESCRIBE.code()).setPermissionType(AclPermissionType.ALLOW.code()), new DeleteAclsResponseData.DeleteAclsMatchingAcl().setResourceType(ResourceType.TOPIC.code()).setResourceName("mytopic4").setPatternType(PatternType.LITERAL.code()).setPrincipal("User:ANONYMOUS").setHost("*").setOperation(AclOperation.DESCRIBE.code()).setPermissionType(AclPermissionType.DENY.code()))));
    filterResults.add(new DeleteAclsResponseData.DeleteAclsFilterResult().setErrorCode(Errors.SECURITY_DISABLED.code()).setErrorMessage("No security"));
    return new DeleteAclsResponse(new DeleteAclsResponseData().setThrottleTimeMs(0).setFilterResults(filterResults), version);
}
Also used : DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) ArrayList(java.util.ArrayList)

Example 3 with DeleteAclsResponseData

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

the class DeleteAclsRequest method getErrorResponse.

@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable throwable) {
    ApiError apiError = ApiError.fromThrowable(throwable);
    List<DeleteAclsFilterResult> filterResults = Collections.nCopies(data.filters().size(), new DeleteAclsResponseData.DeleteAclsFilterResult().setErrorCode(apiError.error().code()).setErrorMessage(apiError.message()));
    return new DeleteAclsResponse(new DeleteAclsResponseData().setThrottleTimeMs(throttleTimeMs).setFilterResults(filterResults), version());
}
Also used : DeleteAclsFilterResult(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult) DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) DeleteAclsFilterResult(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult)

Example 4 with DeleteAclsResponseData

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

the class KafkaAdminClientTest method testDeleteAcls.

@Test
public void testDeleteAcls() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        // Test a call where one filter has an error.
        env.kafkaClient().prepareResponse(new DeleteAclsResponse(new DeleteAclsResponseData().setThrottleTimeMs(0).setFilterResults(asList(new DeleteAclsResponseData.DeleteAclsFilterResult().setMatchingAcls(asList(DeleteAclsResponse.matchingAcl(ACL1, ApiError.NONE), DeleteAclsResponse.matchingAcl(ACL2, ApiError.NONE))), new DeleteAclsResponseData.DeleteAclsFilterResult().setErrorCode(Errors.SECURITY_DISABLED.code()).setErrorMessage("No security"))), ApiKeys.DELETE_ACLS.latestVersion()));
        DeleteAclsResult results = env.adminClient().deleteAcls(asList(FILTER1, FILTER2));
        Map<AclBindingFilter, KafkaFuture<FilterResults>> filterResults = results.values();
        FilterResults filter1Results = filterResults.get(FILTER1).get();
        assertNull(filter1Results.values().get(0).exception());
        assertEquals(ACL1, filter1Results.values().get(0).binding());
        assertNull(filter1Results.values().get(1).exception());
        assertEquals(ACL2, filter1Results.values().get(1).binding());
        TestUtils.assertFutureError(filterResults.get(FILTER2), SecurityDisabledException.class);
        TestUtils.assertFutureError(results.all(), SecurityDisabledException.class);
        // Test a call where one deletion result has an error.
        env.kafkaClient().prepareResponse(new DeleteAclsResponse(new DeleteAclsResponseData().setThrottleTimeMs(0).setFilterResults(asList(new DeleteAclsResponseData.DeleteAclsFilterResult().setMatchingAcls(asList(DeleteAclsResponse.matchingAcl(ACL1, ApiError.NONE), new DeleteAclsResponseData.DeleteAclsMatchingAcl().setErrorCode(Errors.SECURITY_DISABLED.code()).setErrorMessage("No security").setPermissionType(AclPermissionType.ALLOW.code()).setOperation(AclOperation.ALTER.code()).setResourceType(ResourceType.CLUSTER.code()).setPatternType(FILTER2.patternFilter().patternType().code()))), new DeleteAclsResponseData.DeleteAclsFilterResult())), ApiKeys.DELETE_ACLS.latestVersion()));
        results = env.adminClient().deleteAcls(asList(FILTER1, FILTER2));
        assertTrue(results.values().get(FILTER2).get().values().isEmpty());
        TestUtils.assertFutureError(results.all(), SecurityDisabledException.class);
        // Test a call where there are no errors.
        env.kafkaClient().prepareResponse(new DeleteAclsResponse(new DeleteAclsResponseData().setThrottleTimeMs(0).setFilterResults(asList(new DeleteAclsResponseData.DeleteAclsFilterResult().setMatchingAcls(asList(DeleteAclsResponse.matchingAcl(ACL1, ApiError.NONE))), new DeleteAclsResponseData.DeleteAclsFilterResult().setMatchingAcls(asList(DeleteAclsResponse.matchingAcl(ACL2, ApiError.NONE))))), ApiKeys.DELETE_ACLS.latestVersion()));
        results = env.adminClient().deleteAcls(asList(FILTER1, FILTER2));
        Collection<AclBinding> deleted = results.all().get();
        assertCollectionIs(deleted, ACL1, ACL2);
    }
}
Also used : FilterResults(org.apache.kafka.clients.admin.DeleteAclsResult.FilterResults) AclBindingFilter(org.apache.kafka.common.acl.AclBindingFilter) KafkaFuture(org.apache.kafka.common.KafkaFuture) DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) DeleteAclsResponse(org.apache.kafka.common.requests.DeleteAclsResponse) AclBinding(org.apache.kafka.common.acl.AclBinding) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 5 with DeleteAclsResponseData

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

the class DeleteAclsResponseTest method shouldRoundTripV1.

@Test
public void shouldRoundTripV1() {
    final DeleteAclsResponse original = new DeleteAclsResponse(new DeleteAclsResponseData().setThrottleTimeMs(10).setFilterResults(asList(LITERAL_RESPONSE, PREFIXED_RESPONSE)), V1);
    final ByteBuffer buffer = original.serialize(V1);
    final DeleteAclsResponse result = DeleteAclsResponse.parse(buffer, V1);
    assertEquals(original.filterResults(), result.filterResults());
}
Also used : DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

DeleteAclsResponseData (org.apache.kafka.common.message.DeleteAclsResponseData)5 Test (org.junit.jupiter.api.Test)3 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)1 FilterResults (org.apache.kafka.clients.admin.DeleteAclsResult.FilterResults)1 KafkaFuture (org.apache.kafka.common.KafkaFuture)1 AclBinding (org.apache.kafka.common.acl.AclBinding)1 AclBindingFilter (org.apache.kafka.common.acl.AclBindingFilter)1 DeleteAclsFilterResult (org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult)1 DeleteAclsResponse (org.apache.kafka.common.requests.DeleteAclsResponse)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1