Search in sources :

Example 1 with DescribeConfigsResponse

use of org.apache.kafka.common.requests.DescribeConfigsResponse in project apache-kafka-on-k8s by banzaicloud.

the class KafkaAdminClient method describeConfigs.

@Override
public DescribeConfigsResult describeConfigs(Collection<ConfigResource> configResources, final DescribeConfigsOptions options) {
    final Map<ConfigResource, KafkaFutureImpl<Config>> unifiedRequestFutures = new HashMap<>();
    final Map<ConfigResource, KafkaFutureImpl<Config>> brokerFutures = new HashMap<>(configResources.size());
    // The BROKER resources which we want to describe.  We must make a separate DescribeConfigs
    // request for every BROKER resource we want to describe.
    final Collection<Resource> brokerResources = new ArrayList<>();
    // The non-BROKER resources which we want to describe.  These resources can be described by a
    // single, unified DescribeConfigs request.
    final Collection<Resource> unifiedRequestResources = new ArrayList<>(configResources.size());
    for (ConfigResource resource : configResources) {
        if (resource.type() == ConfigResource.Type.BROKER && !resource.isDefault()) {
            brokerFutures.put(resource, new KafkaFutureImpl<Config>());
            brokerResources.add(configResourceToResource(resource));
        } else {
            unifiedRequestFutures.put(resource, new KafkaFutureImpl<Config>());
            unifiedRequestResources.add(configResourceToResource(resource));
        }
    }
    final long now = time.milliseconds();
    if (!unifiedRequestResources.isEmpty()) {
        runnable.call(new Call("describeConfigs", calcDeadlineMs(now, options.timeoutMs()), new LeastLoadedNodeProvider()) {

            @Override
            AbstractRequest.Builder createRequest(int timeoutMs) {
                return new DescribeConfigsRequest.Builder(unifiedRequestResources).includeSynonyms(options.includeSynonyms());
            }

            @Override
            void handleResponse(AbstractResponse abstractResponse) {
                DescribeConfigsResponse response = (DescribeConfigsResponse) abstractResponse;
                for (Map.Entry<ConfigResource, KafkaFutureImpl<Config>> entry : unifiedRequestFutures.entrySet()) {
                    ConfigResource configResource = entry.getKey();
                    KafkaFutureImpl<Config> future = entry.getValue();
                    DescribeConfigsResponse.Config config = response.config(configResourceToResource(configResource));
                    if (config == null) {
                        future.completeExceptionally(new UnknownServerException("Malformed broker response: missing config for " + configResource));
                        continue;
                    }
                    if (config.error().isFailure()) {
                        future.completeExceptionally(config.error().exception());
                        continue;
                    }
                    List<ConfigEntry> configEntries = new ArrayList<>();
                    for (DescribeConfigsResponse.ConfigEntry configEntry : config.entries()) {
                        configEntries.add(new ConfigEntry(configEntry.name(), configEntry.value(), configSource(configEntry.source()), configEntry.isSensitive(), configEntry.isReadOnly(), configSynonyms(configEntry)));
                    }
                    future.complete(new Config(configEntries));
                }
            }

            @Override
            void handleFailure(Throwable throwable) {
                completeAllExceptionally(unifiedRequestFutures.values(), throwable);
            }
        }, now);
    }
    for (Map.Entry<ConfigResource, KafkaFutureImpl<Config>> entry : brokerFutures.entrySet()) {
        final KafkaFutureImpl<Config> brokerFuture = entry.getValue();
        final Resource resource = configResourceToResource(entry.getKey());
        final int nodeId = Integer.parseInt(resource.name());
        runnable.call(new Call("describeBrokerConfigs", calcDeadlineMs(now, options.timeoutMs()), new ConstantNodeIdProvider(nodeId)) {

            @Override
            AbstractRequest.Builder createRequest(int timeoutMs) {
                return new DescribeConfigsRequest.Builder(Collections.singleton(resource)).includeSynonyms(options.includeSynonyms());
            }

            @Override
            void handleResponse(AbstractResponse abstractResponse) {
                DescribeConfigsResponse response = (DescribeConfigsResponse) abstractResponse;
                DescribeConfigsResponse.Config config = response.configs().get(resource);
                if (config == null) {
                    brokerFuture.completeExceptionally(new UnknownServerException("Malformed broker response: missing config for " + resource));
                    return;
                }
                if (config.error().isFailure())
                    brokerFuture.completeExceptionally(config.error().exception());
                else {
                    List<ConfigEntry> configEntries = new ArrayList<>();
                    for (DescribeConfigsResponse.ConfigEntry configEntry : config.entries()) {
                        configEntries.add(new ConfigEntry(configEntry.name(), configEntry.value(), configSource(configEntry.source()), configEntry.isSensitive(), configEntry.isReadOnly(), configSynonyms(configEntry)));
                    }
                    brokerFuture.complete(new Config(configEntries));
                }
            }

            @Override
            void handleFailure(Throwable throwable) {
                brokerFuture.completeExceptionally(throwable);
            }
        }, now);
    }
    final Map<ConfigResource, KafkaFuture<Config>> allFutures = new HashMap<>();
    allFutures.putAll(brokerFutures);
    allFutures.putAll(unifiedRequestFutures);
    return new DescribeConfigsResult(allFutures);
}
Also used : HashMap(java.util.HashMap) MetricConfig(org.apache.kafka.common.metrics.MetricConfig) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) KafkaFuture(org.apache.kafka.common.KafkaFuture) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) ConfigResource(org.apache.kafka.common.config.ConfigResource) Resource(org.apache.kafka.common.requests.Resource) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) ConfigResource(org.apache.kafka.common.config.ConfigResource) Map(java.util.Map) HashMap(java.util.HashMap) DescribeConfigsResponse(org.apache.kafka.common.requests.DescribeConfigsResponse)

Example 2 with DescribeConfigsResponse

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

the class KafkaAdminClient method describeConfigs.

@Override
public DescribeConfigsResult describeConfigs(Collection<ConfigResource> configResources, final DescribeConfigsOptions options) {
    // Partition the requested config resources based on which broker they must be sent to with the
    // null broker being used for config resources which can be obtained from any broker
    final Map<Integer, Map<ConfigResource, KafkaFutureImpl<Config>>> brokerFutures = new HashMap<>(configResources.size());
    for (ConfigResource resource : configResources) {
        Integer broker = nodeFor(resource);
        brokerFutures.compute(broker, (key, value) -> {
            if (value == null) {
                value = new HashMap<>();
            }
            value.put(resource, new KafkaFutureImpl<>());
            return value;
        });
    }
    final long now = time.milliseconds();
    for (Map.Entry<Integer, Map<ConfigResource, KafkaFutureImpl<Config>>> entry : brokerFutures.entrySet()) {
        Integer broker = entry.getKey();
        Map<ConfigResource, KafkaFutureImpl<Config>> unified = entry.getValue();
        runnable.call(new Call("describeConfigs", calcDeadlineMs(now, options.timeoutMs()), broker != null ? new ConstantNodeIdProvider(broker) : new LeastLoadedNodeProvider()) {

            @Override
            DescribeConfigsRequest.Builder createRequest(int timeoutMs) {
                return new DescribeConfigsRequest.Builder(new DescribeConfigsRequestData().setResources(unified.keySet().stream().map(config -> new DescribeConfigsRequestData.DescribeConfigsResource().setResourceName(config.name()).setResourceType(config.type().id()).setConfigurationKeys(null)).collect(Collectors.toList())).setIncludeSynonyms(options.includeSynonyms()).setIncludeDocumentation(options.includeDocumentation()));
            }

            @Override
            void handleResponse(AbstractResponse abstractResponse) {
                DescribeConfigsResponse response = (DescribeConfigsResponse) abstractResponse;
                for (Map.Entry<ConfigResource, DescribeConfigsResponseData.DescribeConfigsResult> entry : response.resultMap().entrySet()) {
                    ConfigResource configResource = entry.getKey();
                    DescribeConfigsResponseData.DescribeConfigsResult describeConfigsResult = entry.getValue();
                    KafkaFutureImpl<Config> future = unified.get(configResource);
                    if (future == null) {
                        if (broker != null) {
                            log.warn("The config {} in the response from broker {} is not in the request", configResource, broker);
                        } else {
                            log.warn("The config {} in the response from the least loaded broker is not in the request", configResource);
                        }
                    } else {
                        if (describeConfigsResult.errorCode() != Errors.NONE.code()) {
                            future.completeExceptionally(Errors.forCode(describeConfigsResult.errorCode()).exception(describeConfigsResult.errorMessage()));
                        } else {
                            future.complete(describeConfigResult(describeConfigsResult));
                        }
                    }
                }
                completeUnrealizedFutures(unified.entrySet().stream(), configResource -> "The broker response did not contain a result for config resource " + configResource);
            }

            @Override
            void handleFailure(Throwable throwable) {
                completeAllExceptionally(unified.values(), throwable);
            }
        }, now);
    }
    return new DescribeConfigsResult(new HashMap<>(brokerFutures.entrySet().stream().flatMap(x -> x.getValue().entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))));
}
Also used : ListGroupsResponse(org.apache.kafka.common.requests.ListGroupsResponse) ThrottlingQuotaExceededException(org.apache.kafka.common.errors.ThrottlingQuotaExceededException) ListOffsetsRequest(org.apache.kafka.common.requests.ListOffsetsRequest) UserName(org.apache.kafka.common.message.DescribeUserScramCredentialsRequestData.UserName) ListPartitionReassignmentsTopics(org.apache.kafka.common.message.ListPartitionReassignmentsRequestData.ListPartitionReassignmentsTopics) ClientQuotaFilter(org.apache.kafka.common.quota.ClientQuotaFilter) KafkaException(org.apache.kafka.common.KafkaException) AppInfoParser(org.apache.kafka.common.utils.AppInfoParser) ClientUtils(org.apache.kafka.clients.ClientUtils) DescribeClientQuotasRequest(org.apache.kafka.common.requests.DescribeClientQuotasRequest) ListGroupsRequestData(org.apache.kafka.common.message.ListGroupsRequestData) AclCreationResult(org.apache.kafka.common.message.CreateAclsResponseData.AclCreationResult) Duration(java.time.Duration) Map(java.util.Map) TopicNameCollection(org.apache.kafka.common.TopicCollection.TopicNameCollection) UpdateFeaturesRequestData(org.apache.kafka.common.message.UpdateFeaturesRequestData) Utils.closeQuietly(org.apache.kafka.common.utils.Utils.closeQuietly) DeleteAclsFilter(org.apache.kafka.common.message.DeleteAclsRequestData.DeleteAclsFilter) CreateAclsRequest(org.apache.kafka.common.requests.CreateAclsRequest) DescribeConfigsRequestData(org.apache.kafka.common.message.DescribeConfigsRequestData) DescribableLogDirTopic(org.apache.kafka.common.message.DescribeLogDirsRequestData.DescribableLogDirTopic) CommonClientConfigs(org.apache.kafka.clients.CommonClientConfigs) Sensor(org.apache.kafka.common.metrics.Sensor) DescribeLogDirsResponseData(org.apache.kafka.common.message.DescribeLogDirsResponseData) ClientQuotaAlteration(org.apache.kafka.common.quota.ClientQuotaAlteration) AlterReplicaLogDirTopicResult(org.apache.kafka.common.message.AlterReplicaLogDirsResponseData.AlterReplicaLogDirTopicResult) DeleteTopicsRequestData(org.apache.kafka.common.message.DeleteTopicsRequestData) AlterReplicaLogDirsRequest(org.apache.kafka.common.requests.AlterReplicaLogDirsRequest) ListGroupsRequest(org.apache.kafka.common.requests.ListGroupsRequest) Metrics(org.apache.kafka.common.metrics.Metrics) Stream(java.util.stream.Stream) ListOffsetsTopicResponse(org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsTopicResponse) Errors(org.apache.kafka.common.protocol.Errors) Node(org.apache.kafka.common.Node) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) UnacceptableCredentialException(org.apache.kafka.common.errors.UnacceptableCredentialException) AuthenticationException(org.apache.kafka.common.errors.AuthenticationException) DeleteTopicState(org.apache.kafka.common.message.DeleteTopicsRequestData.DeleteTopicState) SupportedFeatureKey(org.apache.kafka.common.message.ApiVersionsResponseData.SupportedFeatureKey) DeleteRecordsTopic(org.apache.kafka.common.message.DeleteRecordsRequestData.DeleteRecordsTopic) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) AlterUserScramCredentialsResponse(org.apache.kafka.common.requests.AlterUserScramCredentialsResponse) DescribeClusterResponse(org.apache.kafka.common.requests.DescribeClusterResponse) DelegationToken(org.apache.kafka.common.security.token.delegation.DelegationToken) ListOffsetsPartitionResponse(org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsPartitionResponse) Supplier(java.util.function.Supplier) DescribeAclsResponse(org.apache.kafka.common.requests.DescribeAclsResponse) AlterReplicaLogDirsResponse(org.apache.kafka.common.requests.AlterReplicaLogDirsResponse) AlterConsumerGroupOffsetsHandler(org.apache.kafka.clients.admin.internals.AlterConsumerGroupOffsetsHandler) UpdateFeaturesRequest(org.apache.kafka.common.requests.UpdateFeaturesRequest) KafkaStorageException(org.apache.kafka.common.errors.KafkaStorageException) AlterPartitionReassignmentsRequest(org.apache.kafka.common.requests.AlterPartitionReassignmentsRequest) DeleteAclsMatchingAcl(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl) DescribeLogDirsRequestData(org.apache.kafka.common.message.DescribeLogDirsRequestData) ApiVersions(org.apache.kafka.clients.ApiVersions) TopicMetadataAndConfig(org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig) IncrementalAlterConfigsRequest(org.apache.kafka.common.requests.IncrementalAlterConfigsRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) CreatableTopicCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopicCollection) ReassignableTopic(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignableTopic) TreeMap(java.util.TreeMap) IncrementalAlterConfigsResponse(org.apache.kafka.common.requests.IncrementalAlterConfigsResponse) UpdatableFeatureResult(org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult) CreatePartitionsAssignment(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsAssignment) ElectLeadersRequest(org.apache.kafka.common.requests.ElectLeadersRequest) FilterResults(org.apache.kafka.clients.admin.DeleteAclsResult.FilterResults) DescribeUserScramCredentialsResponse(org.apache.kafka.common.requests.DescribeUserScramCredentialsResponse) AdminApiFuture(org.apache.kafka.clients.admin.internals.AdminApiFuture) AbstractRequest(org.apache.kafka.common.requests.AbstractRequest) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) MemberIdentity(org.apache.kafka.common.message.LeaveGroupRequestData.MemberIdentity) TokenInformation(org.apache.kafka.common.security.token.delegation.TokenInformation) CreateDelegationTokenRequestData(org.apache.kafka.common.message.CreateDelegationTokenRequestData) CreateAclsRequestData(org.apache.kafka.common.message.CreateAclsRequestData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KafkaClient(org.apache.kafka.clients.KafkaClient) DescribeLogDirsRequest(org.apache.kafka.common.requests.DescribeLogDirsRequest) DescribeConfigsResponseData(org.apache.kafka.common.message.DescribeConfigsResponseData) TopicIdCollection(org.apache.kafka.common.TopicCollection.TopicIdCollection) ListOffsetsTopic(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsTopic) TopicPartition(org.apache.kafka.common.TopicPartition) Time(org.apache.kafka.common.utils.Time) Collection(java.util.Collection) AlterReplicaLogDir(org.apache.kafka.common.message.AlterReplicaLogDirsRequestData.AlterReplicaLogDir) CreateAclsResponse(org.apache.kafka.common.requests.CreateAclsResponse) DescribeClusterRequest(org.apache.kafka.common.requests.DescribeClusterRequest) DescribeUserScramCredentialsResponseData(org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData) Collectors(java.util.stream.Collectors) DescribeConfigsRequest(org.apache.kafka.common.requests.DescribeConfigsRequest) Objects(java.util.Objects) CreatePartitionsResponse(org.apache.kafka.common.requests.CreatePartitionsResponse) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) UnregisterBrokerRequestData(org.apache.kafka.common.message.UnregisterBrokerRequestData) AlterUserScramCredentialsRequest(org.apache.kafka.common.requests.AlterUserScramCredentialsRequest) RenewDelegationTokenRequestData(org.apache.kafka.common.message.RenewDelegationTokenRequestData) ExpireDelegationTokenRequest(org.apache.kafka.common.requests.ExpireDelegationTokenRequest) Uuid(org.apache.kafka.common.Uuid) DeleteTopicsRequest(org.apache.kafka.common.requests.DeleteTopicsRequest) ReassignablePartitionResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignablePartitionResponse) DeleteRecordsRequestData(org.apache.kafka.common.message.DeleteRecordsRequestData) FinalizedFeatureKey(org.apache.kafka.common.message.ApiVersionsResponseData.FinalizedFeatureKey) DeleteAclsResponse(org.apache.kafka.common.requests.DeleteAclsResponse) DeleteAclsFilterResult(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult) AlterPartitionReassignmentsResponse(org.apache.kafka.common.requests.AlterPartitionReassignmentsResponse) DescribeConfigsResponse(org.apache.kafka.common.requests.DescribeConfigsResponse) Function(java.util.function.Function) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) DeleteRecordsResponseData(org.apache.kafka.common.message.DeleteRecordsResponseData) DescribeUserScramCredentialsRequest(org.apache.kafka.common.requests.DescribeUserScramCredentialsRequest) HashSet(java.util.HashSet) CreatableTopicConfigs(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicConfigs) TopicCollection(org.apache.kafka.common.TopicCollection) OngoingPartitionReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingPartitionReassignment) LinkedList(java.util.LinkedList) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Logger(org.slf4j.Logger) AllBrokersStrategy(org.apache.kafka.clients.admin.internals.AllBrokersStrategy) AlterConfigsResponse(org.apache.kafka.common.requests.AlterConfigsResponse) CreateTopicsResponse(org.apache.kafka.common.requests.CreateTopicsResponse) ConfigException(org.apache.kafka.common.config.ConfigException) DeleteRecordsPartition(org.apache.kafka.common.message.DeleteRecordsRequestData.DeleteRecordsPartition) KafkaThread(org.apache.kafka.common.utils.KafkaThread) AlterConfigsRequest(org.apache.kafka.common.requests.AlterConfigsRequest) RenewDelegationTokenRequest(org.apache.kafka.common.requests.RenewDelegationTokenRequest) DefaultHostResolver(org.apache.kafka.clients.DefaultHostResolver) DisconnectException(org.apache.kafka.common.errors.DisconnectException) InvalidRequestException(org.apache.kafka.common.errors.InvalidRequestException) KafkaPrincipal(org.apache.kafka.common.security.auth.KafkaPrincipal) Comparator(java.util.Comparator) ExpireDelegationTokenResponse(org.apache.kafka.common.requests.ExpireDelegationTokenResponse) ReplicaLogDirInfo(org.apache.kafka.clients.admin.DescribeReplicaLogDirsResult.ReplicaLogDirInfo) Arrays(java.util.Arrays) ApiVersionsRequest(org.apache.kafka.common.requests.ApiVersionsRequest) DescribeClusterRequestData(org.apache.kafka.common.message.DescribeClusterRequestData) CreatePartitionsTopicCollection(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopicCollection) DeleteRecordsTopicResult(org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsTopicResult) Cluster(org.apache.kafka.common.Cluster) AbortTransactionHandler(org.apache.kafka.clients.admin.internals.AbortTransactionHandler) AdminApiHandler(org.apache.kafka.clients.admin.internals.AdminApiHandler) UnregisterBrokerRequest(org.apache.kafka.common.requests.UnregisterBrokerRequest) CreatePartitionsTopic(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic) RemoveMembersFromConsumerGroupHandler(org.apache.kafka.clients.admin.internals.RemoveMembersFromConsumerGroupHandler) ApiVersionsResponse(org.apache.kafka.common.requests.ApiVersionsResponse) ListOffsetsResponse(org.apache.kafka.common.requests.ListOffsetsResponse) LogContext(org.apache.kafka.common.utils.LogContext) ListPartitionReassignmentsRequestData(org.apache.kafka.common.message.ListPartitionReassignmentsRequestData) CreatePartitionsRequestData(org.apache.kafka.common.message.CreatePartitionsRequestData) TimestampSpec(org.apache.kafka.clients.admin.OffsetSpec.TimestampSpec) ListTransactionsHandler(org.apache.kafka.clients.admin.internals.ListTransactionsHandler) DeleteAclsRequest(org.apache.kafka.common.requests.DeleteAclsRequest) InvalidTopicException(org.apache.kafka.common.errors.InvalidTopicException) Set(java.util.Set) PartitionInfo(org.apache.kafka.common.PartitionInfo) DeleteRecordsRequest(org.apache.kafka.common.requests.DeleteRecordsRequest) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CoordinatorKey(org.apache.kafka.clients.admin.internals.CoordinatorKey) MetricsReporter(org.apache.kafka.common.metrics.MetricsReporter) ConsumerGroupState(org.apache.kafka.common.ConsumerGroupState) InvalidKeyException(java.security.InvalidKeyException) CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) MetadataResponse(org.apache.kafka.common.requests.MetadataResponse) AlterUserScramCredentialsRequestData(org.apache.kafka.common.message.AlterUserScramCredentialsRequestData) CreatableRenewers(org.apache.kafka.common.message.CreateDelegationTokenRequestData.CreatableRenewers) Selector(org.apache.kafka.common.network.Selector) KafkaMetricsContext(org.apache.kafka.common.metrics.KafkaMetricsContext) RenewDelegationTokenResponse(org.apache.kafka.common.requests.RenewDelegationTokenResponse) RetriableException(org.apache.kafka.common.errors.RetriableException) ExpireDelegationTokenRequestData(org.apache.kafka.common.message.ExpireDelegationTokenRequestData) ArrayList(java.util.ArrayList) MetricsContext(org.apache.kafka.common.metrics.MetricsContext) ElectionType(org.apache.kafka.common.ElectionType) NetworkClient(org.apache.kafka.clients.NetworkClient) InterfaceStability(org.apache.kafka.common.annotation.InterfaceStability) AlterPartitionReassignmentsRequestData(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) MetadataOperationContext(org.apache.kafka.clients.admin.internals.MetadataOperationContext) ListGroupsResponseData(org.apache.kafka.common.message.ListGroupsResponseData) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) ScramFormatter(org.apache.kafka.common.security.scram.internals.ScramFormatter) AlterClientQuotasResponse(org.apache.kafka.common.requests.AlterClientQuotasResponse) AclCreation(org.apache.kafka.common.message.CreateAclsRequestData.AclCreation) TopicPartitionReplica(org.apache.kafka.common.TopicPartitionReplica) DeleteRecordsResponse(org.apache.kafka.common.requests.DeleteRecordsResponse) ReassignablePartition(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignablePartition) AclOperation(org.apache.kafka.common.acl.AclOperation) AlterReplicaLogDirsRequestData(org.apache.kafka.common.message.AlterReplicaLogDirsRequestData) UnsupportedSaslMechanismException(org.apache.kafka.common.errors.UnsupportedSaslMechanismException) CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) DescribeUserScramCredentialsRequestData(org.apache.kafka.common.message.DescribeUserScramCredentialsRequestData) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) MetadataRequestData(org.apache.kafka.common.message.MetadataRequestData) DescribeDelegationTokenResponse(org.apache.kafka.common.requests.DescribeDelegationTokenResponse) AdminApiDriver(org.apache.kafka.clients.admin.internals.AdminApiDriver) AlterClientQuotasRequest(org.apache.kafka.common.requests.AlterClientQuotasRequest) CreatePartitionsTopicResult(org.apache.kafka.common.message.CreatePartitionsResponseData.CreatePartitionsTopicResult) SimpleAdminApiFuture(org.apache.kafka.clients.admin.internals.AdminApiFuture.SimpleAdminApiFuture) AlterReplicaLogDirPartitionResult(org.apache.kafka.common.message.AlterReplicaLogDirsResponseData.AlterReplicaLogDirPartitionResult) ListPartitionReassignmentsResponse(org.apache.kafka.common.requests.ListPartitionReassignmentsResponse) ClientRequest(org.apache.kafka.clients.ClientRequest) DescribeClientQuotasResponse(org.apache.kafka.common.requests.DescribeClientQuotasResponse) UpdateFeaturesResponse(org.apache.kafka.common.requests.UpdateFeaturesResponse) ReassignableTopicResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignableTopicResponse) DeleteAclsRequestData(org.apache.kafka.common.message.DeleteAclsRequestData) UnregisterBrokerResponse(org.apache.kafka.common.requests.UnregisterBrokerResponse) CreatePartitionsRequest(org.apache.kafka.common.requests.CreatePartitionsRequest) MetadataRequest.convertToMetadataRequestTopic(org.apache.kafka.common.requests.MetadataRequest.convertToMetadataRequestTopic) Metric(org.apache.kafka.common.Metric) MetricName(org.apache.kafka.common.MetricName) AdminMetadataManager(org.apache.kafka.clients.admin.internals.AdminMetadataManager) DescribeAclsRequest(org.apache.kafka.common.requests.DescribeAclsRequest) Predicate(java.util.function.Predicate) MetricConfig(org.apache.kafka.common.metrics.MetricConfig) KafkaFuture(org.apache.kafka.common.KafkaFuture) InetSocketAddress(java.net.InetSocketAddress) ListOffsetsResultInfo(org.apache.kafka.clients.admin.ListOffsetsResult.ListOffsetsResultInfo) List(java.util.List) DeletableTopicResult(org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult) Optional(java.util.Optional) ClientResponse(org.apache.kafka.clients.ClientResponse) ConsumerProtocol(org.apache.kafka.clients.consumer.internals.ConsumerProtocol) ListConsumerGroupOffsetsHandler(org.apache.kafka.clients.admin.internals.ListConsumerGroupOffsetsHandler) MetadataRequest.convertTopicIdsToMetadataRequestTopic(org.apache.kafka.common.requests.MetadataRequest.convertTopicIdsToMetadataRequestTopic) CreateTopicsRequest(org.apache.kafka.common.requests.CreateTopicsRequest) ElectLeadersResponse(org.apache.kafka.common.requests.ElectLeadersResponse) StaleMetadataException(org.apache.kafka.clients.StaleMetadataException) AclBindingFilter(org.apache.kafka.common.acl.AclBindingFilter) HashMap(java.util.HashMap) DescribeConsumerGroupsHandler(org.apache.kafka.clients.admin.internals.DescribeConsumerGroupsHandler) ApiError(org.apache.kafka.common.requests.ApiError) ConfigResource(org.apache.kafka.common.config.ConfigResource) CreateDelegationTokenResponse(org.apache.kafka.common.requests.CreateDelegationTokenResponse) CreateDelegationTokenResponseData(org.apache.kafka.common.message.CreateDelegationTokenResponseData) DeleteConsumerGroupsHandler(org.apache.kafka.clients.admin.internals.DeleteConsumerGroupsHandler) MetadataRequest(org.apache.kafka.common.requests.MetadataRequest) AclBinding(org.apache.kafka.common.acl.AclBinding) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity) DescribeProducersHandler(org.apache.kafka.clients.admin.internals.DescribeProducersHandler) OngoingTopicReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingTopicReassignment) ListPartitionReassignmentsRequest(org.apache.kafka.common.requests.ListPartitionReassignmentsRequest) DeleteConsumerGroupOffsetsHandler(org.apache.kafka.clients.admin.internals.DeleteConsumerGroupOffsetsHandler) AlterReplicaLogDirTopic(org.apache.kafka.common.message.AlterReplicaLogDirsRequestData.AlterReplicaLogDirTopic) JmxReporter(org.apache.kafka.common.metrics.JmxReporter) Utils(org.apache.kafka.common.utils.Utils) DescribeTransactionsHandler(org.apache.kafka.clients.admin.internals.DescribeTransactionsHandler) ListOffsetsPartition(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition) Iterator(java.util.Iterator) FilterResult(org.apache.kafka.clients.admin.DeleteAclsResult.FilterResult) DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) TimeUnit(java.util.concurrent.TimeUnit) DescribeDelegationTokenRequest(org.apache.kafka.common.requests.DescribeDelegationTokenRequest) HostResolver(org.apache.kafka.clients.HostResolver) DeleteTopicsResponse(org.apache.kafka.common.requests.DeleteTopicsResponse) DescribeLogDirsResponse(org.apache.kafka.common.requests.DescribeLogDirsResponse) Collections(java.util.Collections) ApiException(org.apache.kafka.common.errors.ApiException) CreateDelegationTokenRequest(org.apache.kafka.common.requests.CreateDelegationTokenRequest) HashMap(java.util.HashMap) TopicMetadataAndConfig(org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig) MetricConfig(org.apache.kafka.common.metrics.MetricConfig) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) DescribeConfigsRequestData(org.apache.kafka.common.message.DescribeConfigsRequestData) DescribeConfigsRequest(org.apache.kafka.common.requests.DescribeConfigsRequest) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ConfigResource(org.apache.kafka.common.config.ConfigResource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DescribeConfigsResponseData(org.apache.kafka.common.message.DescribeConfigsResponseData) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) DescribeConfigsResponse(org.apache.kafka.common.requests.DescribeConfigsResponse)

Example 3 with DescribeConfigsResponse

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

the class KafkaAdminClientTest method testDescribeConfigsPartialResponse.

@Test
public void testDescribeConfigsPartialResponse() throws Exception {
    ConfigResource topic = new ConfigResource(ConfigResource.Type.TOPIC, "topic");
    ConfigResource topic2 = new ConfigResource(ConfigResource.Type.TOPIC, "topic2");
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        env.kafkaClient().prepareResponse(new DescribeConfigsResponse(new DescribeConfigsResponseData().setResults(asList(new DescribeConfigsResponseData.DescribeConfigsResult().setResourceName(topic.name()).setResourceType(topic.type().id()).setErrorCode(Errors.NONE.code()).setConfigs(emptyList())))));
        Map<ConfigResource, KafkaFuture<Config>> result = env.adminClient().describeConfigs(asList(topic, topic2)).values();
        assertEquals(new HashSet<>(asList(topic, topic2)), result.keySet());
        result.get(topic);
        TestUtils.assertFutureThrows(result.get(topic2), ApiException.class);
    }
}
Also used : DescribeConfigsResponseData(org.apache.kafka.common.message.DescribeConfigsResponseData) KafkaFuture(org.apache.kafka.common.KafkaFuture) ConfigResource(org.apache.kafka.common.config.ConfigResource) DescribeConfigsResponse(org.apache.kafka.common.requests.DescribeConfigsResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with DescribeConfigsResponse

use of org.apache.kafka.common.requests.DescribeConfigsResponse in project apache-kafka-on-k8s by banzaicloud.

the class KafkaAdminClientTest method testHandleTimeout.

/**
 * Test handling timeouts.
 */
// The test is flaky. Should be renabled when this JIRA is fixed: https://issues.apache.org/jira/browse/KAFKA-5792
@Ignore
@Test
public void testHandleTimeout() throws Exception {
    HashMap<Integer, Node> nodes = new HashMap<>();
    MockTime time = new MockTime();
    nodes.put(0, new Node(0, "localhost", 8121));
    Cluster cluster = new Cluster("mockClusterId", nodes.values(), Collections.<PartitionInfo>emptySet(), Collections.<String>emptySet(), Collections.<String>emptySet(), nodes.get(0));
    try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(time, cluster, AdminClientConfig.RECONNECT_BACKOFF_MAX_MS_CONFIG, "1", AdminClientConfig.RECONNECT_BACKOFF_MS_CONFIG, "1")) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        env.kafkaClient().prepareMetadataUpdate(env.cluster(), Collections.<String>emptySet());
        env.kafkaClient().setNode(nodes.get(0));
        assertEquals(time, env.time());
        assertEquals(env.time(), ((KafkaAdminClient) env.adminClient()).time());
        // Make a request with an extremely short timeout.
        // Then wait for it to fail by not supplying any response.
        log.info("Starting AdminClient#listTopics...");
        final ListTopicsResult result = env.adminClient().listTopics(new ListTopicsOptions().timeoutMs(1000));
        TestUtils.waitForCondition(new TestCondition() {

            @Override
            public boolean conditionMet() {
                return env.kafkaClient().hasInFlightRequests();
            }
        }, "Timed out waiting for inFlightRequests");
        time.sleep(5000);
        TestUtils.waitForCondition(new TestCondition() {

            @Override
            public boolean conditionMet() {
                return result.listings().isDone();
            }
        }, "Timed out waiting for listTopics to complete");
        assertFutureError(result.listings(), TimeoutException.class);
        log.info("Verified the error result of AdminClient#listTopics");
        // The next request should succeed.
        time.sleep(5000);
        env.kafkaClient().prepareResponse(new DescribeConfigsResponse(0, Collections.singletonMap(new org.apache.kafka.common.requests.Resource(TOPIC, "foo"), new DescribeConfigsResponse.Config(ApiError.NONE, Collections.<DescribeConfigsResponse.ConfigEntry>emptySet()))));
        DescribeConfigsResult result2 = env.adminClient().describeConfigs(Collections.singleton(new ConfigResource(ConfigResource.Type.TOPIC, "foo")));
        time.sleep(5000);
        result2.values().get(new ConfigResource(ConfigResource.Type.TOPIC, "foo")).get();
    }
}
Also used : HashMap(java.util.HashMap) Node(org.apache.kafka.common.Node) Cluster(org.apache.kafka.common.Cluster) ConfigResource(org.apache.kafka.common.config.ConfigResource) TestCondition(org.apache.kafka.test.TestCondition) MockTime(org.apache.kafka.common.utils.MockTime) DescribeConfigsResponse(org.apache.kafka.common.requests.DescribeConfigsResponse) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with DescribeConfigsResponse

use of org.apache.kafka.common.requests.DescribeConfigsResponse in project apache-kafka-on-k8s by banzaicloud.

the class KafkaAdminClientTest method testDescribeConfigs.

@Test
public void testDescribeConfigs() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        env.kafkaClient().prepareMetadataUpdate(env.cluster(), Collections.<String>emptySet());
        env.kafkaClient().setNode(env.cluster().controller());
        env.kafkaClient().prepareResponse(new DescribeConfigsResponse(0, Collections.singletonMap(new org.apache.kafka.common.requests.Resource(BROKER, "0"), new DescribeConfigsResponse.Config(ApiError.NONE, Collections.<DescribeConfigsResponse.ConfigEntry>emptySet()))));
        DescribeConfigsResult result2 = env.adminClient().describeConfigs(Collections.singleton(new ConfigResource(ConfigResource.Type.BROKER, "0")));
        result2.all().get();
    }
}
Also used : DescribeConfigsResponse(org.apache.kafka.common.requests.DescribeConfigsResponse) ConfigResource(org.apache.kafka.common.config.ConfigResource) Test(org.junit.Test)

Aggregations

ConfigResource (org.apache.kafka.common.config.ConfigResource)8 DescribeConfigsResponse (org.apache.kafka.common.requests.DescribeConfigsResponse)8 KafkaFuture (org.apache.kafka.common.KafkaFuture)6 DescribeConfigsResponseData (org.apache.kafka.common.message.DescribeConfigsResponseData)5 HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)2 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)2 MetricConfig (org.apache.kafka.common.metrics.MetricConfig)2 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)2 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)2 Test (org.junit.Test)2 InetSocketAddress (java.net.InetSocketAddress)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1