@@ -435,7 +435,7 @@ def create_topics(self, new_topics, timeout_ms=None, validate_only=False):
435
435
create_topic_requests = [self ._convert_new_topic_request (new_topic ) for new_topic in new_topics ],
436
436
timeout = timeout_ms
437
437
)
438
- elif version <= 2 :
438
+ elif version <= 3 :
439
439
request = CreateTopicsRequest [version ](
440
440
create_topic_requests = [self ._convert_new_topic_request (new_topic ) for new_topic in new_topics ],
441
441
timeout = timeout_ms ,
@@ -459,7 +459,7 @@ def delete_topics(self, topics, timeout_ms=None):
459
459
"""
460
460
version = self ._matching_api_version (DeleteTopicsRequest )
461
461
timeout_ms = self ._validate_timeout (timeout_ms )
462
- if version <= 1 :
462
+ if version <= 3 :
463
463
request = DeleteTopicsRequest [version ](
464
464
topics = topics ,
465
465
timeout = timeout_ms
@@ -803,7 +803,7 @@ def describe_configs(self, config_resources, include_synonyms=False):
803
803
DescribeConfigsRequest [version ](resources = topic_resources )
804
804
))
805
805
806
- elif version == 1 :
806
+ elif version <= 2 :
807
807
if len (broker_resources ) > 0 :
808
808
for broker_resource in broker_resources :
809
809
try :
@@ -853,7 +853,7 @@ def alter_configs(self, config_resources):
853
853
:return: Appropriate version of AlterConfigsResponse class.
854
854
"""
855
855
version = self ._matching_api_version (AlterConfigsRequest )
856
- if version == 0 :
856
+ if version <= 1 :
857
857
request = AlterConfigsRequest [version ](
858
858
resources = [self ._convert_alter_config_resource_request (config_resource ) for config_resource in config_resources ]
859
859
)
@@ -901,7 +901,7 @@ def create_partitions(self, topic_partitions, timeout_ms=None, validate_only=Fal
901
901
"""
902
902
version = self ._matching_api_version (CreatePartitionsRequest )
903
903
timeout_ms = self ._validate_timeout (timeout_ms )
904
- if version == 0 :
904
+ if version <= 1 :
905
905
request = CreatePartitionsRequest [version ](
906
906
topic_partitions = [self ._convert_create_partitions_request (topic_name , new_partitions ) for topic_name , new_partitions in topic_partitions .items ()],
907
907
timeout = timeout_ms ,
@@ -928,7 +928,7 @@ def create_partitions(self, topic_partitions, timeout_ms=None, validate_only=Fal
928
928
# describe delegation_token protocol not yet implemented
929
929
# Note: send the request to the least_loaded_node()
930
930
931
- def _describe_consumer_groups_send_request (self , group_id , group_coordinator_id ):
931
+ def _describe_consumer_groups_send_request (self , group_id , group_coordinator_id , include_authorized_operations = False ):
932
932
"""Send a DescribeGroupsRequest to the group's coordinator.
933
933
934
934
:param group_id: The group name as a string
@@ -937,13 +937,24 @@ def _describe_consumer_groups_send_request(self, group_id, group_coordinator_id)
937
937
:return: A message future.
938
938
"""
939
939
version = self ._matching_api_version (DescribeGroupsRequest )
940
- if version <= 1 :
940
+ if version <= 2 :
941
+ if include_authorized_operations :
942
+ raise IncompatibleBrokerVersion (
943
+ "include_authorized_operations requests "
944
+ "DescribeGroupsRequest >= v3, which is not "
945
+ "supported by Kafka {}" .format (version )
946
+ )
941
947
# Note: KAFKA-6788 A potential optimization is to group the
942
948
# request per coordinator and send one request with a list of
943
949
# all consumer groups. Java still hasn't implemented this
944
950
# because the error checking is hard to get right when some
945
951
# groups error and others don't.
946
952
request = DescribeGroupsRequest [version ](groups = (group_id ,))
953
+ elif version <= 3 :
954
+ request = DescribeGroupsRequest [version ](
955
+ groups = (group_id ,),
956
+ include_authorized_operations = include_authorized_operations
957
+ )
947
958
else :
948
959
raise NotImplementedError (
949
960
"Support for DescribeGroupsRequest_v{} has not yet been added to KafkaAdminClient."
@@ -952,7 +963,7 @@ def _describe_consumer_groups_send_request(self, group_id, group_coordinator_id)
952
963
953
964
def _describe_consumer_groups_process_response (self , response ):
954
965
"""Process a DescribeGroupsResponse into a group description."""
955
- if response .API_VERSION <= 1 :
966
+ if response .API_VERSION <= 3 :
956
967
assert len (response .groups ) == 1
957
968
# TODO need to implement converting the response tuple into
958
969
# a more accessible interface like a namedtuple and then stop
@@ -976,7 +987,7 @@ def _describe_consumer_groups_process_response(self, response):
976
987
.format (response .API_VERSION ))
977
988
return group_description
978
989
979
- def describe_consumer_groups (self , group_ids , group_coordinator_id = None ):
990
+ def describe_consumer_groups (self , group_ids , group_coordinator_id = None , include_authorized_operations = False ):
980
991
"""Describe a set of consumer groups.
981
992
982
993
Any errors are immediately raised.
@@ -989,6 +1000,9 @@ def describe_consumer_groups(self, group_ids, group_coordinator_id=None):
989
1000
useful for avoiding extra network round trips if you already know
990
1001
the group coordinator. This is only useful when all the group_ids
991
1002
have the same coordinator, otherwise it will error. Default: None.
1003
+ :param include_authorized_operatoins: Whether or not to include
1004
+ information about the operations a group is allowed to perform.
1005
+ Only supported on API version >= v3. Default: False.
992
1006
:return: A list of group descriptions. For now the group descriptions
993
1007
are the raw results from the DescribeGroupsResponse. Long-term, we
994
1008
plan to change this to return namedtuples as well as decoding the
@@ -1001,7 +1015,10 @@ def describe_consumer_groups(self, group_ids, group_coordinator_id=None):
1001
1015
this_groups_coordinator_id = group_coordinator_id
1002
1016
else :
1003
1017
this_groups_coordinator_id = self ._find_coordinator_id (group_id )
1004
- f = self ._describe_consumer_groups_send_request (group_id , this_groups_coordinator_id )
1018
+ f = self ._describe_consumer_groups_send_request (
1019
+ group_id ,
1020
+ this_groups_coordinator_id ,
1021
+ include_authorized_operations )
1005
1022
futures .append (f )
1006
1023
1007
1024
self ._wait_for_futures (futures )
0 commit comments