Search in sources :

Example 1 with IncrementalAlterConfigsResponseData

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

the class IncrementalAlterConfigsRequest method getErrorResponse.

@Override
public AbstractResponse getErrorResponse(final int throttleTimeMs, final Throwable e) {
    IncrementalAlterConfigsResponseData response = new IncrementalAlterConfigsResponseData();
    ApiError apiError = ApiError.fromThrowable(e);
    for (AlterConfigsResource resource : data.resources()) {
        response.responses().add(new AlterConfigsResourceResponse().setResourceName(resource.resourceName()).setResourceType(resource.resourceType()).setErrorCode(apiError.error().code()).setErrorMessage(apiError.message()));
    }
    return new IncrementalAlterConfigsResponse(response);
}
Also used : IncrementalAlterConfigsResponseData(org.apache.kafka.common.message.IncrementalAlterConfigsResponseData) AlterConfigsResourceResponse(org.apache.kafka.common.message.IncrementalAlterConfigsResponseData.AlterConfigsResourceResponse) AlterConfigsResource(org.apache.kafka.common.message.IncrementalAlterConfigsRequestData.AlterConfigsResource)

Example 2 with IncrementalAlterConfigsResponseData

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

the class KafkaAdminClientTest method testIncrementalAlterConfigs.

@Test
public void testIncrementalAlterConfigs() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        // test error scenarios
        IncrementalAlterConfigsResponseData responseData = new IncrementalAlterConfigsResponseData();
        responseData.responses().add(new AlterConfigsResourceResponse().setResourceName("").setResourceType(ConfigResource.Type.BROKER.id()).setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code()).setErrorMessage("authorization error"));
        responseData.responses().add(new AlterConfigsResourceResponse().setResourceName("topic1").setResourceType(ConfigResource.Type.TOPIC.id()).setErrorCode(Errors.INVALID_REQUEST.code()).setErrorMessage("Config value append is not allowed for config"));
        env.kafkaClient().prepareResponse(new IncrementalAlterConfigsResponse(responseData));
        ConfigResource brokerResource = new ConfigResource(ConfigResource.Type.BROKER, "");
        ConfigResource topicResource = new ConfigResource(ConfigResource.Type.TOPIC, "topic1");
        AlterConfigOp alterConfigOp1 = new AlterConfigOp(new ConfigEntry("log.segment.bytes", "1073741"), AlterConfigOp.OpType.SET);
        AlterConfigOp alterConfigOp2 = new AlterConfigOp(new ConfigEntry("compression.type", "gzip"), AlterConfigOp.OpType.APPEND);
        final Map<ConfigResource, Collection<AlterConfigOp>> configs = new HashMap<>();
        configs.put(brokerResource, singletonList(alterConfigOp1));
        configs.put(topicResource, singletonList(alterConfigOp2));
        AlterConfigsResult result = env.adminClient().incrementalAlterConfigs(configs);
        TestUtils.assertFutureError(result.values().get(brokerResource), ClusterAuthorizationException.class);
        TestUtils.assertFutureError(result.values().get(topicResource), InvalidRequestException.class);
        // Test a call where there are no errors.
        responseData = new IncrementalAlterConfigsResponseData();
        responseData.responses().add(new AlterConfigsResourceResponse().setResourceName("").setResourceType(ConfigResource.Type.BROKER.id()).setErrorCode(Errors.NONE.code()).setErrorMessage(ApiError.NONE.message()));
        env.kafkaClient().prepareResponse(new IncrementalAlterConfigsResponse(responseData));
        env.adminClient().incrementalAlterConfigs(Collections.singletonMap(brokerResource, singletonList(alterConfigOp1))).all().get();
    }
}
Also used : IncrementalAlterConfigsResponseData(org.apache.kafka.common.message.IncrementalAlterConfigsResponseData) AlterConfigsResourceResponse(org.apache.kafka.common.message.IncrementalAlterConfigsResponseData.AlterConfigsResourceResponse) HashMap(java.util.HashMap) DeletableTopicResultCollection(org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResultCollection) CreatableTopicResultCollection(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResultCollection) OffsetDeleteResponsePartitionCollection(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponsePartitionCollection) Collection(java.util.Collection) OffsetDeleteResponseTopicCollection(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponseTopicCollection) TopicCollection(org.apache.kafka.common.TopicCollection) DeletableGroupResultCollection(org.apache.kafka.common.message.DeleteGroupsResponseData.DeletableGroupResultCollection) ConfigResource(org.apache.kafka.common.config.ConfigResource) IncrementalAlterConfigsResponse(org.apache.kafka.common.requests.IncrementalAlterConfigsResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with IncrementalAlterConfigsResponseData

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

the class RequestResponseTest method createIncrementalAlterConfigsResponse.

private IncrementalAlterConfigsResponse createIncrementalAlterConfigsResponse() {
    IncrementalAlterConfigsResponseData data = new IncrementalAlterConfigsResponseData();
    data.responses().add(new AlterConfigsResourceResponse().setResourceName("testtopic").setResourceType(ResourceType.TOPIC.code()).setErrorCode(Errors.NONE.code()).setErrorMessage("Duplicate Keys"));
    return new IncrementalAlterConfigsResponse(data);
}
Also used : IncrementalAlterConfigsResponseData(org.apache.kafka.common.message.IncrementalAlterConfigsResponseData) AlterConfigsResourceResponse(org.apache.kafka.common.message.IncrementalAlterConfigsResponseData.AlterConfigsResourceResponse)

Aggregations

IncrementalAlterConfigsResponseData (org.apache.kafka.common.message.IncrementalAlterConfigsResponseData)3 AlterConfigsResourceResponse (org.apache.kafka.common.message.IncrementalAlterConfigsResponseData.AlterConfigsResourceResponse)3 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 TopicCollection (org.apache.kafka.common.TopicCollection)1 ConfigResource (org.apache.kafka.common.config.ConfigResource)1 CreatableTopicResultCollection (org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResultCollection)1 DeletableGroupResultCollection (org.apache.kafka.common.message.DeleteGroupsResponseData.DeletableGroupResultCollection)1 DeletableTopicResultCollection (org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResultCollection)1 AlterConfigsResource (org.apache.kafka.common.message.IncrementalAlterConfigsRequestData.AlterConfigsResource)1 OffsetDeleteResponsePartitionCollection (org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponsePartitionCollection)1 OffsetDeleteResponseTopicCollection (org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponseTopicCollection)1 IncrementalAlterConfigsResponse (org.apache.kafka.common.requests.IncrementalAlterConfigsResponse)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1