Search in sources :

Example 1 with IncrementalAlterConfigsResponse

use of org.apache.kafka.common.requests.IncrementalAlterConfigsResponse 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 2 with IncrementalAlterConfigsResponse

use of org.apache.kafka.common.requests.IncrementalAlterConfigsResponse in project kafka by apache.

the class KafkaAdminClient method incrementalAlterConfigs.

private Map<ConfigResource, KafkaFutureImpl<Void>> incrementalAlterConfigs(Map<ConfigResource, Collection<AlterConfigOp>> configs, final AlterConfigsOptions options, Collection<ConfigResource> resources, NodeProvider nodeProvider) {
    final Map<ConfigResource, KafkaFutureImpl<Void>> futures = new HashMap<>();
    for (ConfigResource resource : resources) futures.put(resource, new KafkaFutureImpl<>());
    final long now = time.milliseconds();
    runnable.call(new Call("incrementalAlterConfigs", calcDeadlineMs(now, options.timeoutMs()), nodeProvider) {

        @Override
        public IncrementalAlterConfigsRequest.Builder createRequest(int timeoutMs) {
            return new IncrementalAlterConfigsRequest.Builder(resources, configs, options.shouldValidateOnly());
        }

        @Override
        public void handleResponse(AbstractResponse abstractResponse) {
            IncrementalAlterConfigsResponse response = (IncrementalAlterConfigsResponse) abstractResponse;
            Map<ConfigResource, ApiError> errors = IncrementalAlterConfigsResponse.fromResponseData(response.data());
            for (Map.Entry<ConfigResource, KafkaFutureImpl<Void>> entry : futures.entrySet()) {
                KafkaFutureImpl<Void> future = entry.getValue();
                ApiException exception = errors.get(entry.getKey()).exception();
                if (exception != null) {
                    future.completeExceptionally(exception);
                } else {
                    future.complete(null);
                }
            }
        }

        @Override
        void handleFailure(Throwable throwable) {
            completeAllExceptionally(futures.values(), throwable);
        }
    }, now);
    return futures;
}
Also used : HashMap(java.util.HashMap) IncrementalAlterConfigsRequest(org.apache.kafka.common.requests.IncrementalAlterConfigsRequest) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ConfigResource(org.apache.kafka.common.config.ConfigResource) IncrementalAlterConfigsResponse(org.apache.kafka.common.requests.IncrementalAlterConfigsResponse) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) ApiException(org.apache.kafka.common.errors.ApiException)

Aggregations

HashMap (java.util.HashMap)2 ConfigResource (org.apache.kafka.common.config.ConfigResource)2 IncrementalAlterConfigsResponse (org.apache.kafka.common.requests.IncrementalAlterConfigsResponse)2 Collection (java.util.Collection)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TopicCollection (org.apache.kafka.common.TopicCollection)1 ApiException (org.apache.kafka.common.errors.ApiException)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)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 IncrementalAlterConfigsResponseData (org.apache.kafka.common.message.IncrementalAlterConfigsResponseData)1 AlterConfigsResourceResponse (org.apache.kafka.common.message.IncrementalAlterConfigsResponseData.AlterConfigsResourceResponse)1 OffsetDeleteResponsePartitionCollection (org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponsePartitionCollection)1 OffsetDeleteResponseTopicCollection (org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponseTopicCollection)1 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1 IncrementalAlterConfigsRequest (org.apache.kafka.common.requests.IncrementalAlterConfigsRequest)1 Test (org.junit.jupiter.api.Test)1