|
6 | 6 | import socket |
7 | 7 |
|
8 | 8 | from . import ConfigResourceType |
9 | | -from kafka.vendor import six |
10 | 9 |
|
| 10 | +from kafka.admin.acl_resource import ACLOperation, ACLPermissionType, ACLFilter, ACL, ResourcePattern, ResourceType, \ |
| 11 | + ACLResourcePatternType |
11 | 12 | from kafka.client_async import KafkaClient, selectors |
| 13 | +from kafka.coordinator.protocol import ConsumerProtocolMemberMetadata, ConsumerProtocolMemberAssignment, ConsumerProtocol |
12 | 14 | import kafka.errors as Errors |
13 | 15 | from kafka.errors import ( |
14 | 16 | IncompatibleBrokerVersion, KafkaConfigurationError, NotControllerError, |
|
17 | 19 | from kafka.protocol.admin import ( |
18 | 20 | CreateTopicsRequest, DeleteTopicsRequest, DescribeConfigsRequest, AlterConfigsRequest, CreatePartitionsRequest, |
19 | 21 | ListGroupsRequest, DescribeGroupsRequest, DescribeAclsRequest, CreateAclsRequest, DeleteAclsRequest) |
20 | | -from kafka.protocol.types import Array |
21 | | -from kafka.coordinator.protocol import ConsumerProtocolMemberMetadata, ConsumerProtocolMemberAssignment, ConsumerProtocol |
22 | 22 | from kafka.protocol.commit import GroupCoordinatorRequest, OffsetFetchRequest |
23 | 23 | from kafka.protocol.metadata import MetadataRequest |
| 24 | +from kafka.protocol.types import Array |
24 | 25 | from kafka.structs import TopicPartition, OffsetAndMetadata, MemberInformation, GroupInformation |
25 | | -from kafka.admin.acl_resource import ACLOperation, ACLPermissionType, ACLFilter, ACL, ResourcePattern, ResourceType, \ |
26 | | - ACLResourcePatternType |
| 26 | +from kafka.vendor import six |
27 | 27 | from kafka.version import __version__ |
28 | 28 |
|
29 | 29 |
|
@@ -1003,39 +1003,39 @@ def _describe_consumer_groups_process_response(self, response): |
1003 | 1003 | if response.API_VERSION <= 3: |
1004 | 1004 | assert len(response.groups) == 1 |
1005 | 1005 | for response_field, response_name in zip(response.SCHEMA.fields, response.SCHEMA.names): |
1006 | | - if type(response_field) == Array: |
| 1006 | + if isinstance(response_field, Array): |
1007 | 1007 | described_groups = response.__dict__[response_name] |
1008 | 1008 | described_groups_field_schema = response_field.array_of |
1009 | | - for described_group in described_groups: |
1010 | | - described_group_information_list = [] |
1011 | | - is_consumer_protocol_type = False |
1012 | | - for (described_group_information, group_information_name, group_information_field) in zip(described_group, described_groups_field_schema.names, described_groups_field_schema.fields): |
1013 | | - if group_information_name == 'protocol_type': |
1014 | | - protocol_type = described_group_information |
1015 | | - is_consumer_protocol_type = (protocol_type == ConsumerProtocol.PROTOCOL_TYPE or not protocol_type) |
1016 | | - if type(group_information_field) == Array: |
1017 | | - member_information_list = [] |
1018 | | - member_schema = group_information_field.array_of |
1019 | | - for members in described_group_information: |
1020 | | - member_information = [] |
1021 | | - for (member, member_field, member_name) in zip(members, member_schema.fields, member_schema.names): |
1022 | | - if member_name == 'member_metadata' and is_consumer_protocol_type: |
| 1009 | + described_group = response.__dict__[response_name][0] |
| 1010 | + described_group_information_list = [] |
| 1011 | + protocol_type_is_consumer = False |
| 1012 | + for (described_group_information, group_information_name, group_information_field) in zip(described_group, described_groups_field_schema.names, described_groups_field_schema.fields): |
| 1013 | + if group_information_name == 'protocol_type': |
| 1014 | + protocol_type = described_group_information |
| 1015 | + protocol_type_is_consumer = (protocol_type == ConsumerProtocol.PROTOCOL_TYPE or not protocol_type) |
| 1016 | + if type(group_information_field) == Array: |
| 1017 | + member_information_list = [] |
| 1018 | + member_schema = group_information_field.array_of |
| 1019 | + for members in described_group_information: |
| 1020 | + member_information = [] |
| 1021 | + for (member, member_field, member_name) in zip(members, member_schema.fields, member_schema.names): |
| 1022 | + if protocol_type_is_consumer: |
| 1023 | + if member_name == 'member_metadata' and member: |
1023 | 1024 | member_information.append(ConsumerProtocolMemberMetadata.decode(member)) |
1024 | | - elif member_name == 'member_assignment' and is_consumer_protocol_type: |
| 1025 | + elif member_name == 'member_assignment' and member: |
1025 | 1026 | member_information.append(ConsumerProtocolMemberAssignment.decode(member)) |
1026 | 1027 | else: |
1027 | 1028 | member_information.append(member) |
1028 | | - else: |
1029 | | - member_info_tuple = MemberInformation._make(member_information) |
1030 | | - member_information_list.append(member_info_tuple) |
1031 | | - else: |
1032 | | - described_group_information_list.append(member_information_list) |
1033 | | - else: |
1034 | | - described_group_information_list.append(described_group_information) |
| 1029 | + member_info_tuple = MemberInformation._make(member_information) |
| 1030 | + member_information_list.append(member_info_tuple) |
| 1031 | + described_group_information_list.append(member_information_list) |
1035 | 1032 | else: |
1036 | | - if response.API_VERSION <=2: |
1037 | | - described_group_information_list.append([]) |
1038 | | - group_description = GroupInformation._make(described_group_information_list) |
| 1033 | + described_group_information_list.append(described_group_information) |
| 1034 | + # Version 3 of the DescribeGroups API introduced the "authorized_operations" field. This will cause the namedtuple to fail |
| 1035 | + # Therefore, appending a placeholder of None in it. |
| 1036 | + if response.API_VERSION <=2: |
| 1037 | + described_group_information_list.append(None) |
| 1038 | + group_description = GroupInformation._make(described_group_information_list) |
1039 | 1039 | error_code = group_description.error_code |
1040 | 1040 | error_type = Errors.for_code(error_code) |
1041 | 1041 | # Java has the note: KAFKA-6789, we can retry based on the error code |
|
0 commit comments