|
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
|
@@ -484,28 +485,74 @@ def describe_configs(self, config_resources, include_synonyms=False):
|
484 | 485 | supported by all versions. Default: False.
|
485 | 486 | :return: Appropriate version of DescribeConfigsResponse class.
|
486 | 487 | """
|
| 488 | + |
| 489 | + # Break up requests by type - a broker config request must be sent to the specific broker. |
| 490 | + # All other (currently just topic resources) can be sent to any broker. |
| 491 | + broker_resources = [] |
| 492 | + topic_resources = [] |
| 493 | + |
| 494 | + for config_resource in config_resources: |
| 495 | + if config_resource.resource_type == ConfigResourceType.BROKER: |
| 496 | + broker_resources.append(self._convert_describe_config_resource_request(config_resource)) |
| 497 | + else: |
| 498 | + topic_resources.append(self._convert_describe_config_resource_request(config_resource)) |
| 499 | + |
| 500 | + futures = [] |
487 | 501 | version = self._matching_api_version(DescribeConfigsRequest)
|
488 | 502 | if version == 0:
|
489 | 503 | if include_synonyms:
|
490 | 504 | raise IncompatibleBrokerVersion(
|
491 | 505 | "include_synonyms requires DescribeConfigsRequest >= v1, which is not supported by Kafka {}."
|
492 |
| - .format(self.config['api_version'])) |
493 |
| - request = DescribeConfigsRequest[version]( |
494 |
| - resources=[self._convert_describe_config_resource_request(config_resource) for config_resource in config_resources] |
495 |
| - ) |
| 506 | + .format(self.config['api_version'])) |
| 507 | + |
| 508 | + if len(broker_resources) > 0: |
| 509 | + for broker_resource in broker_resources: |
| 510 | + try: |
| 511 | + futures.append(self._send_request_to_node( |
| 512 | + int(broker_resource[1]), |
| 513 | + DescribeConfigsRequest[version](resources=[broker_resource]) |
| 514 | + )) |
| 515 | + except ValueError: |
| 516 | + raise ValueError("Broker resource names must be an integer or a string represented integer") |
| 517 | + |
| 518 | + if len(topic_resources) > 0: |
| 519 | + futures.append(self._send_request_to_node( |
| 520 | + self._client.least_loaded_node(), |
| 521 | + DescribeConfigsRequest[version](resources=topic_resources) |
| 522 | + )) |
| 523 | + |
496 | 524 | elif version == 1:
|
497 |
| - request = DescribeConfigsRequest[version]( |
498 |
| - resources=[self._convert_describe_config_resource_request(config_resource) for config_resource in config_resources], |
499 |
| - include_synonyms=include_synonyms |
500 |
| - ) |
| 525 | + if len(broker_resources) > 0: |
| 526 | + for broker_resource in broker_resources: |
| 527 | + try: |
| 528 | + futures.append(self._send_request_to_node( |
| 529 | + int(broker_resource[1]), |
| 530 | + DescribeConfigsRequest[version]( |
| 531 | + resources=[broker_resource], |
| 532 | + include_synonyms=include_synonyms) |
| 533 | + )) |
| 534 | + except ValueError: |
| 535 | + raise ValueError("Broker resource names must be an integer or a string represented integer") |
| 536 | + |
| 537 | + if len(topic_resources) > 0: |
| 538 | + futures.append(self._send_request_to_node( |
| 539 | + self._client.least_loaded_node(), |
| 540 | + DescribeConfigsRequest[version](resources=topic_resources, include_synonyms=include_synonyms) |
| 541 | + )) |
501 | 542 | else:
|
502 | 543 | raise NotImplementedError(
|
503 | 544 | "Support for DescribeConfigs v{} has not yet been added to KafkaAdminClient."
|
504 |
| - .format(version)) |
505 |
| - future = self._send_request_to_node(self._client.least_loaded_node(), request) |
| 545 | + .format(version)) |
| 546 | + |
| 547 | + self._wait_for_futures(futures) |
| 548 | + |
| 549 | + # Use one of the results as the general response and add all other resources to it |
| 550 | + response = copy.copy(futures[0]) |
| 551 | + response.resources = [] |
| 552 | + |
| 553 | + for future in futures: |
| 554 | + response.resources.extend(future.value.resources) |
506 | 555 |
|
507 |
| - self._wait_for_futures([future]) |
508 |
| - response = future.value |
509 | 556 | return response
|
510 | 557 |
|
511 | 558 | @staticmethod
|
|
0 commit comments