|
5 | 5 | import logging
|
6 | 6 | import socket
|
7 | 7 |
|
| 8 | +from . import ConfigResourceType |
8 | 9 | from kafka.vendor import six
|
9 | 10 |
|
10 | 11 | from kafka.client_async import KafkaClient, selectors
|
@@ -763,29 +764,70 @@ def describe_configs(self, config_resources, include_synonyms=False):
|
763 | 764 | supported by all versions. Default: False.
|
764 | 765 | :return: Appropriate version of DescribeConfigsResponse class.
|
765 | 766 | """
|
| 767 | + |
| 768 | + # Break up requests by type - a broker config request must be sent to the specific broker. |
| 769 | + # All other (currently just topic resources) can be sent to any broker. |
| 770 | + broker_resources = [] |
| 771 | + topic_resources = [] |
| 772 | + |
| 773 | + for config_resource in config_resources: |
| 774 | + if config_resource.resource_type == ConfigResourceType.BROKER: |
| 775 | + broker_resources.append(self._convert_describe_config_resource_request(config_resource)) |
| 776 | + else: |
| 777 | + topic_resources.append(self._convert_describe_config_resource_request(config_resource)) |
| 778 | + |
| 779 | + futures = [] |
766 | 780 | version = self._matching_api_version(DescribeConfigsRequest)
|
767 | 781 | if version == 0:
|
768 | 782 | if include_synonyms:
|
769 | 783 | raise IncompatibleBrokerVersion(
|
770 | 784 | "include_synonyms requires DescribeConfigsRequest >= v1, which is not supported by Kafka {}."
|
771 |
| - .format(self.config['api_version'])) |
772 |
| - request = DescribeConfigsRequest[version]( |
773 |
| - resources=[self._convert_describe_config_resource_request(config_resource) for config_resource in config_resources] |
774 |
| - ) |
| 785 | + .format(self.config['api_version'])) |
| 786 | + |
| 787 | + if len(broker_resources) > 0: |
| 788 | + for broker_resource in broker_resources: |
| 789 | + try: |
| 790 | + broker_id = int(broker_resource[1]) |
| 791 | + except ValueError: |
| 792 | + raise ValueError("Broker resource names must be an integer or a string represented integer") |
| 793 | + |
| 794 | + futures.append(self._send_request_to_node( |
| 795 | + broker_id, |
| 796 | + DescribeConfigsRequest[version](resources=[broker_resource]) |
| 797 | + )) |
| 798 | + |
| 799 | + if len(topic_resources) > 0: |
| 800 | + futures.append(self._send_request_to_node( |
| 801 | + self._client.least_loaded_node(), |
| 802 | + DescribeConfigsRequest[version](resources=topic_resources) |
| 803 | + )) |
| 804 | + |
775 | 805 | elif version == 1:
|
776 |
| - request = DescribeConfigsRequest[version]( |
777 |
| - resources=[self._convert_describe_config_resource_request(config_resource) for config_resource in config_resources], |
778 |
| - include_synonyms=include_synonyms |
779 |
| - ) |
| 806 | + if len(broker_resources) > 0: |
| 807 | + for broker_resource in broker_resources: |
| 808 | + try: |
| 809 | + broker_id = int(broker_resource[1]) |
| 810 | + except ValueError: |
| 811 | + raise ValueError("Broker resource names must be an integer or a string represented integer") |
| 812 | + |
| 813 | + futures.append(self._send_request_to_node( |
| 814 | + broker_id, |
| 815 | + DescribeConfigsRequest[version]( |
| 816 | + resources=[broker_resource], |
| 817 | + include_synonyms=include_synonyms) |
| 818 | + )) |
| 819 | + |
| 820 | + if len(topic_resources) > 0: |
| 821 | + futures.append(self._send_request_to_node( |
| 822 | + self._client.least_loaded_node(), |
| 823 | + DescribeConfigsRequest[version](resources=topic_resources, include_synonyms=include_synonyms) |
| 824 | + )) |
780 | 825 | else:
|
781 | 826 | raise NotImplementedError(
|
782 |
| - "Support for DescribeConfigs v{} has not yet been added to KafkaAdminClient." |
783 |
| - .format(version)) |
784 |
| - future = self._send_request_to_node(self._client.least_loaded_node(), request) |
| 827 | + "Support for DescribeConfigs v{} has not yet been added to KafkaAdminClient.".format(version)) |
785 | 828 |
|
786 |
| - self._wait_for_futures([future]) |
787 |
| - response = future.value |
788 |
| - return response |
| 829 | + self._wait_for_futures(futures) |
| 830 | + return [f.value for f in futures] |
789 | 831 |
|
790 | 832 | @staticmethod
|
791 | 833 | def _convert_alter_config_resource_request(config_resource):
|
|
0 commit comments