5
5
import socket
6
6
from kafka .client_async import KafkaClient , selectors
7
7
from kafka .errors import (
8
- KafkaConfigurationError , UnsupportedVersionError , NodeNotReadyError , NotControllerError , KafkaConnectionError )
8
+ IncompatibleBrokerVersion , KafkaConfigurationError , KafkaConnectionError ,
9
+ NodeNotReadyError , NotControllerError )
9
10
from kafka .metrics import MetricConfig , Metrics
10
11
from kafka .protocol .admin import (
11
12
CreateTopicsRequest , DeleteTopicsRequest , DescribeConfigsRequest , AlterConfigsRequest , CreatePartitionsRequest ,
@@ -25,9 +26,11 @@ class KafkaAdmin(object):
25
26
nicer, more pythonic objects. Unfortunately, this will likely break
26
27
those interfaces.
27
28
28
- The KafkaAdmin class will negotiate for the latest version of each message protocol format supported
29
- by both the kafka-python client library and the kafka broker. Usage of optional fields from protocol
30
- versions that are not supported by the broker will result in UnsupportedVersionError exceptions.
29
+ The KafkaAdmin class will negotiate for the latest version of each message
30
+ protocol format supported by both the kafka-python client library and the
31
+ kafka broker. Usage of optional fields from protocol versions that are not
32
+ supported by the broker will result in IncompatibleBrokerVersion exceptions.
33
+
31
34
32
35
Use of this class requires a minimum broker version >= 0.10.0.0.
33
36
@@ -223,8 +226,8 @@ def _matching_api_version(self, operation):
223
226
if version < self ._client .get_api_versions ()[operation [0 ].API_KEY ][0 ]:
224
227
# max library version is less than min broker version. Not sure any brokers
225
228
# actually set a min version greater than 0 right now, tho. But maybe in the future?
226
- raise UnsupportedVersionError (
227
- "Could not find matching protocol version for {} "
229
+ raise IncompatibleBrokerVersion (
230
+ "No version of the '{}' kafka protocol is supported by both the client and broker. "
228
231
.format (operation .__name__ ))
229
232
return version
230
233
@@ -246,9 +249,9 @@ def _refresh_controller_id(self):
246
249
self ._controller_id = response .controller_id
247
250
version = self ._client .check_version (self ._controller_id )
248
251
if version < (0 , 10 , 0 ):
249
- raise UnsupportedVersionError (
250
- "Kafka Admin interface not supported for cluster controller version {} < 0.10.0.0"
251
- .format (version ))
252
+ raise IncompatibleBrokerVersion (
253
+ "The controller appears to be running Kafka {}. KafkaAdmin requires brokers >= 0.10.0.0. "
254
+ .format (version ))
252
255
253
256
def _send_request_to_node (self , node , request ):
254
257
"""Send a kafka protocol message to a specific broker. Will block until the message result is received.
@@ -311,9 +314,9 @@ def create_topics(self, new_topics, timeout_ms=None, validate_only=None):
311
314
timeout_ms = self ._validate_timeout (timeout_ms )
312
315
if version == 0 :
313
316
if validate_only :
314
- raise UnsupportedVersionError (
315
- "validate_only not supported on cluster version {} "
316
- .format (self .config ['api_version' ]))
317
+ raise IncompatibleBrokerVersion (
318
+ "validate_only requires CreateTopicsRequest >= v1, which is not supported by Kafka {}. "
319
+ .format (self .config ['api_version' ]))
317
320
request = CreateTopicsRequest [version ](
318
321
create_topic_requests = [self ._convert_new_topic_request (new_topic ) for new_topic in new_topics ],
319
322
timeout = timeout_ms
@@ -326,10 +329,9 @@ def create_topics(self, new_topics, timeout_ms=None, validate_only=None):
326
329
validate_only = validate_only
327
330
)
328
331
else :
329
- raise UnsupportedVersionError (
330
- "missing implementation of CreateTopics for library supported version {}"
331
- .format (version )
332
- )
332
+ raise NotImplementedError (
333
+ "Support for CreateTopics v{} has not yet been added to KafkaAdmin."
334
+ .format (version ))
333
335
return self ._send (request )
334
336
335
337
def delete_topics (self , topics , timeout_ms = None ):
@@ -347,9 +349,9 @@ def delete_topics(self, topics, timeout_ms=None):
347
349
timeout = timeout_ms
348
350
)
349
351
else :
350
- raise UnsupportedVersionError (
351
- "missing implementation of DeleteTopics for library supported version {} "
352
- .format (version ))
352
+ raise NotImplementedError (
353
+ "Support for DeleteTopics v{} has not yet been added to KafkaAdmin. "
354
+ .format (version ))
353
355
return self ._send (request )
354
356
355
357
# list topics functionality is in ClusterMetadata
@@ -386,9 +388,9 @@ def describe_configs(self, config_resources, include_synonyms=None):
386
388
version = self ._matching_api_version (DescribeConfigsRequest )
387
389
if version == 0 :
388
390
if include_synonyms :
389
- raise UnsupportedVersionError (
390
- "include_synonyms not supported on cluster version {} "
391
- .format (self .config ['api_version' ]))
391
+ raise IncompatibleBrokerVersion (
392
+ "include_synonyms requires DescribeConfigsRequest >= v1, which is not supported by Kafka {}. "
393
+ .format (self .config ['api_version' ]))
392
394
request = DescribeConfigsRequest [version ](
393
395
resources = [self ._convert_describe_config_resource_request (config_resource ) for config_resource in config_resources ]
394
396
)
@@ -399,9 +401,9 @@ def describe_configs(self, config_resources, include_synonyms=None):
399
401
include_synonyms = include_synonyms
400
402
)
401
403
else :
402
- raise UnsupportedVersionError (
403
- "missing implementation of DescribeConfigs for library supported version {} "
404
- .format (version ))
404
+ raise NotImplementedError (
405
+ "Support for DescribeConfigs v{} has not yet been added to KafkaAdmin. "
406
+ .format (version ))
405
407
return self ._send (request )
406
408
407
409
@staticmethod
@@ -426,9 +428,9 @@ def alter_configs(self, config_resources):
426
428
resources = [self ._convert_alter_config_resource_request (config_resource ) for config_resource in config_resources ]
427
429
)
428
430
else :
429
- raise UnsupportedVersionError (
430
- "missing implementation of AlterConfigs for library supported version {} "
431
- .format (version ))
431
+ raise NotImplementedError (
432
+ "Support for AlterConfigs v{} has not yet been added to KafkaAdmin. "
433
+ .format (version ))
432
434
return self ._send (request )
433
435
434
436
# alter replica logs dir protocol not implemented
@@ -463,9 +465,9 @@ def create_partitions(self, topic_partitions, timeout_ms=None, validate_only=Non
463
465
validate_only = validate_only
464
466
)
465
467
else :
466
- raise UnsupportedVersionError (
467
- "missing implementation of CreatePartitions for library supported version {} "
468
- .format (version ))
468
+ raise NotImplementedError (
469
+ "Support for CreatePartitions v{} has not yet been added to KafkaAdmin. "
470
+ .format (version ))
469
471
return self ._send (request )
470
472
471
473
# delete records protocol not implemented
@@ -490,9 +492,9 @@ def describe_consumer_groups(self, group_ids):
490
492
groups = group_ids
491
493
)
492
494
else :
493
- raise UnsupportedVersionError (
494
- "missing implementation of DescribeGroups for library supported version {} "
495
- .format (version ))
495
+ raise NotImplementedError (
496
+ "Support for DescribeGroups v{} has not yet been added to KafkaAdmin. "
497
+ .format (version ))
496
498
return self ._send (request )
497
499
498
500
def list_consumer_groups (self ):
@@ -504,9 +506,9 @@ def list_consumer_groups(self):
504
506
if version <= 1 :
505
507
request = ListGroupsRequest [version ]()
506
508
else :
507
- raise UnsupportedVersionError (
508
- "missing implementation of ListGroups for library supported version {} "
509
- .format (version ))
509
+ raise NotImplementedError (
510
+ "Support for ListGroups v{} has not yet been added to KafkaAdmin. "
511
+ .format (version ))
510
512
return self ._send (request )
511
513
512
514
# delete groups protocol not implemented
0 commit comments