@@ -215,11 +215,7 @@ def __init__(self, **configs):
215
215
)
216
216
217
217
# Get auto-discovered version from client if necessary
218
- if self .config ['api_version' ] is None :
219
- self .config ['api_version' ] = self ._client .config ['api_version' ]
220
- else :
221
- # need to run check_version for get_api_versions()
222
- self ._client .check_version (timeout = (self .config ['api_version_auto_timeout_ms' ] / 1000 ))
218
+ self .config ['api_version' ] = self ._client .config ['api_version' ]
223
219
224
220
self ._closed = False
225
221
self ._refresh_controller_id ()
@@ -236,35 +232,6 @@ def close(self):
236
232
self ._closed = True
237
233
log .debug ("KafkaAdminClient is now closed." )
238
234
239
- def _matching_api_version (self , operation ):
240
- """Find the latest version of the protocol operation supported by both
241
- this library and the broker.
242
-
243
- This resolves to the lesser of either the latest api version this
244
- library supports, or the max version supported by the broker.
245
-
246
- Arguments:
247
- operation: A list of protocol operation versions from kafka.protocol.
248
-
249
- Returns:
250
- int: The max matching version number between client and broker.
251
- """
252
- broker_api_versions = self ._client .get_api_versions ()
253
- api_key = operation [0 ].API_KEY
254
- if broker_api_versions is None or api_key not in broker_api_versions :
255
- raise IncompatibleBrokerVersion (
256
- "Kafka broker does not support the '{}' Kafka protocol."
257
- .format (operation [0 ].__name__ ))
258
- min_version , max_version = broker_api_versions [api_key ]
259
- version = min (len (operation ) - 1 , max_version )
260
- if version < min_version :
261
- # max library version is less than min broker version. Currently,
262
- # no Kafka versions specify a min msg version. Maybe in the future?
263
- raise IncompatibleBrokerVersion (
264
- "No version of the '{}' Kafka protocol is supported by both the client and broker."
265
- .format (operation [0 ].__name__ ))
266
- return version
267
-
268
235
def _validate_timeout (self , timeout_ms ):
269
236
"""Validate the timeout is set or use the configuration default.
270
237
@@ -278,7 +245,7 @@ def _validate_timeout(self, timeout_ms):
278
245
279
246
def _refresh_controller_id (self , timeout_ms = 30000 ):
280
247
"""Determine the Kafka cluster controller."""
281
- version = self ._matching_api_version (MetadataRequest )
248
+ version = self ._client . api_version (MetadataRequest , max_version = 6 )
282
249
if 1 <= version <= 6 :
283
250
timeout_at = time .time () + timeout_ms / 1000
284
251
while time .time () < timeout_at :
@@ -323,8 +290,7 @@ def _find_coordinator_id_send_request(self, group_id):
323
290
# When I experimented with this, the coordinator value returned in
324
291
# GroupCoordinatorResponse_v1 didn't match the value returned by
325
292
# GroupCoordinatorResponse_v0 and I couldn't figure out why.
326
- version = 0
327
- # version = self._matching_api_version(GroupCoordinatorRequest)
293
+ version = self ._client .api_version (GroupCoordinatorRequest , max_version = 0 )
328
294
if version <= 0 :
329
295
request = GroupCoordinatorRequest [version ](group_id )
330
296
else :
@@ -493,7 +459,7 @@ def create_topics(self, new_topics, timeout_ms=None, validate_only=False):
493
459
Returns:
494
460
Appropriate version of CreateTopicResponse class.
495
461
"""
496
- version = self ._matching_api_version (CreateTopicsRequest )
462
+ version = self ._client . api_version (CreateTopicsRequest , max_version = 3 )
497
463
timeout_ms = self ._validate_timeout (timeout_ms )
498
464
if version == 0 :
499
465
if validate_only :
@@ -531,7 +497,7 @@ def delete_topics(self, topics, timeout_ms=None):
531
497
Returns:
532
498
Appropriate version of DeleteTopicsResponse class.
533
499
"""
534
- version = self ._matching_api_version (DeleteTopicsRequest )
500
+ version = self ._client . api_version (DeleteTopicsRequest , max_version = 3 )
535
501
timeout_ms = self ._validate_timeout (timeout_ms )
536
502
if version <= 3 :
537
503
request = DeleteTopicsRequest [version ](
@@ -550,7 +516,7 @@ def _get_cluster_metadata(self, topics=None, auto_topic_creation=False):
550
516
"""
551
517
topics == None means "get all topics"
552
518
"""
553
- version = self ._matching_api_version (MetadataRequest )
519
+ version = self ._client . api_version (MetadataRequest , max_version = 5 )
554
520
if version <= 3 :
555
521
if auto_topic_creation :
556
522
raise IncompatibleBrokerVersion (
@@ -667,7 +633,7 @@ def describe_acls(self, acl_filter):
667
633
tuple of a list of matching ACL objects and a KafkaError (NoError if successful)
668
634
"""
669
635
670
- version = self ._matching_api_version (DescribeAclsRequest )
636
+ version = self ._client . api_version (DescribeAclsRequest , max_version = 1 )
671
637
if version == 0 :
672
638
request = DescribeAclsRequest [version ](
673
639
resource_type = acl_filter .resource_pattern .resource_type ,
@@ -801,7 +767,7 @@ def create_acls(self, acls):
801
767
if not isinstance (acl , ACL ):
802
768
raise IllegalArgumentError ("acls must contain ACL objects" )
803
769
804
- version = self ._matching_api_version (CreateAclsRequest )
770
+ version = self ._client . api_version (CreateAclsRequest , max_version = 1 )
805
771
if version == 0 :
806
772
request = CreateAclsRequest [version ](
807
773
creations = [self ._convert_create_acls_resource_request_v0 (acl ) for acl in acls ]
@@ -923,7 +889,7 @@ def delete_acls(self, acl_filters):
923
889
if not isinstance (acl , ACLFilter ):
924
890
raise IllegalArgumentError ("acl_filters must contain ACLFilter type objects" )
925
891
926
- version = self ._matching_api_version (DeleteAclsRequest )
892
+ version = self ._client . api_version (DeleteAclsRequest , max_version = 1 )
927
893
928
894
if version == 0 :
929
895
request = DeleteAclsRequest [version ](
@@ -992,7 +958,7 @@ def describe_configs(self, config_resources, include_synonyms=False):
992
958
topic_resources .append (self ._convert_describe_config_resource_request (config_resource ))
993
959
994
960
futures = []
995
- version = self ._matching_api_version (DescribeConfigsRequest )
961
+ version = self ._client . api_version (DescribeConfigsRequest , max_version = 2 )
996
962
if version == 0 :
997
963
if include_synonyms :
998
964
raise IncompatibleBrokerVersion (
@@ -1077,7 +1043,7 @@ def alter_configs(self, config_resources):
1077
1043
Returns:
1078
1044
Appropriate version of AlterConfigsResponse class.
1079
1045
"""
1080
- version = self ._matching_api_version (AlterConfigsRequest )
1046
+ version = self ._client . api_version (AlterConfigsRequest , max_version = 1 )
1081
1047
if version <= 1 :
1082
1048
request = AlterConfigsRequest [version ](
1083
1049
resources = [self ._convert_alter_config_resource_request (config_resource ) for config_resource in config_resources ]
@@ -1138,7 +1104,7 @@ def create_partitions(self, topic_partitions, timeout_ms=None, validate_only=Fal
1138
1104
Returns:
1139
1105
Appropriate version of CreatePartitionsResponse class.
1140
1106
"""
1141
- version = self ._matching_api_version (CreatePartitionsRequest )
1107
+ version = self ._client . api_version (CreatePartitionsRequest , max_version = 1 )
1142
1108
timeout_ms = self ._validate_timeout (timeout_ms )
1143
1109
if version <= 1 :
1144
1110
request = CreatePartitionsRequest [version ](
@@ -1177,7 +1143,7 @@ def _describe_consumer_groups_send_request(self, group_id, group_coordinator_id,
1177
1143
Returns:
1178
1144
A message future.
1179
1145
"""
1180
- version = self ._matching_api_version (DescribeGroupsRequest )
1146
+ version = self ._client . api_version (DescribeGroupsRequest , max_version = 3 )
1181
1147
if version <= 2 :
1182
1148
if include_authorized_operations :
1183
1149
raise IncompatibleBrokerVersion (
@@ -1311,7 +1277,7 @@ def _list_consumer_groups_send_request(self, broker_id):
1311
1277
Returns:
1312
1278
A message future
1313
1279
"""
1314
- version = self ._matching_api_version (ListGroupsRequest )
1280
+ version = self ._client . api_version (ListGroupsRequest , max_version = 2 )
1315
1281
if version <= 2 :
1316
1282
request = ListGroupsRequest [version ]()
1317
1283
else :
@@ -1394,7 +1360,7 @@ def _list_consumer_group_offsets_send_request(self, group_id,
1394
1360
Returns:
1395
1361
A message future
1396
1362
"""
1397
- version = self ._matching_api_version (OffsetFetchRequest )
1363
+ version = self ._client . api_version (OffsetFetchRequest , max_version = 3 )
1398
1364
if version <= 3 :
1399
1365
if partitions is None :
1400
1366
if version <= 1 :
@@ -1564,7 +1530,7 @@ def _delete_consumer_groups_send_request(self, group_ids, group_coordinator_id):
1564
1530
Returns:
1565
1531
A future representing the in-flight DeleteGroupsRequest.
1566
1532
"""
1567
- version = self ._matching_api_version (DeleteGroupsRequest )
1533
+ version = self ._client . api_version (DeleteGroupsRequest , max_version = 1 )
1568
1534
if version <= 1 :
1569
1535
request = DeleteGroupsRequest [version ](group_ids )
1570
1536
else :
@@ -1595,7 +1561,7 @@ def describe_log_dirs(self):
1595
1561
Returns:
1596
1562
A message future
1597
1563
"""
1598
- version = self ._matching_api_version (DescribeLogDirsRequest )
1564
+ version = self ._client . api_version (DescribeLogDirsRequest , max_version = 0 )
1599
1565
if version <= 0 :
1600
1566
request = DescribeLogDirsRequest [version ]()
1601
1567
future = self ._send_request_to_node (self ._client .least_loaded_node (), request )
0 commit comments