@@ -201,3 +201,105 @@ def alter_configs(self, resources, **kwargs):
201
201
if not f .set_running_or_notify_cancel ():
202
202
raise RuntimeError ("Future was cancelled prematurely" )
203
203
return super (AdminClient , self ).alter_configs (resources , f , ** kwargs )
204
+
205
+
206
+ class ClusterMetadata (object ):
207
+ """
208
+ ClusterMetadata as returned by list_topics() contains information
209
+ about the Kafka cluster, brokers, and topics.
210
+
211
+ :ivar cluster_id: Cluster id string, if supported by broker, else None.
212
+ :ivar controller_id: Current controller broker id, or -1.
213
+ :ivar brokers: Map of brokers indexed by the int broker id. Value is BrokerMetadata object.
214
+ :ivar topics: Map of topics indexed by the topic name. Value is TopicMetadata object.
215
+ :ivar orig_broker_id: The broker this metadata originated from.
216
+ :ivar orig_broker_name: Broker name/address this metadata originated from.
217
+ """
218
+ def __init__ (self ):
219
+ self .cluster_id = None
220
+ self .controller_id = - 1
221
+ self .brokers = {}
222
+ self .topics = {}
223
+ self .orig_broker_id = - 1
224
+ self .orig_broker_name = None
225
+
226
+ def __repr__ (self ):
227
+ return "ClusterMetadata({})" .format (self .cluster_id )
228
+
229
+ def __str__ (self ):
230
+ return str (self .cluster_id )
231
+
232
+
233
+ class BrokerMetadata (object ):
234
+ """
235
+ BrokerMetadata contains information about a Kafka broker.
236
+
237
+ :ivar id: Broker id.
238
+ :ivar host: Broker hostname.
239
+ :ivar port: Broker port.
240
+ """
241
+ def __init__ (self ):
242
+ self .id = - 1
243
+ self .host = None
244
+ self .port = - 1
245
+
246
+ def __repr__ (self ):
247
+ return "BrokerMetadata({}, {}:{})" .format (self .id , self .host , self .port )
248
+
249
+ def __str__ (self ):
250
+ return "{}:{}/{}" .format (self .host , self .port , self .id )
251
+
252
+
253
+ class TopicMetadata (object ):
254
+ """
255
+ TopicMetadata contains information about a Kafka topic.
256
+
257
+ :ivar topic: Topic name.
258
+ :ivar partitions: Map of partitions indexed by partition id. Value is PartitionMetadata object.
259
+ :ivar error: Topic error, or None. Value is a KafkaError object.
260
+ """
261
+ def __init__ (self ):
262
+ self .topic = None
263
+ self .partitions = {}
264
+ self .error = None
265
+
266
+ def __repr__ (self ):
267
+ if self .error is not None :
268
+ return "TopicMetadata({}, {} partitions, {})" .format (self .topic , len (self .partitions ), self .error )
269
+ else :
270
+ return "TopicMetadata({}, {} partitions)" .format (self .topic , len (self .partitions ))
271
+
272
+ def __str__ (self ):
273
+ return self .topic
274
+
275
+
276
+ class PartitionMetadata (object ):
277
+ """
278
+ PartitionsMetadata contains information about a Kafka partition.
279
+
280
+ :ivar id: Partition id.
281
+ :ivar leader: Current leader broker for this partition, or -1.
282
+ :ivar replicas: List of replica broker ids for this partition.
283
+ :ivar isrs: List of in-sync-replica broker ids for this partition.
284
+ :ivar error: Partition error, or None. Value is a KafkaError object.
285
+
286
+ :warning: Depending on cluster state the broker ids referenced in
287
+ leader, replicas and isrs may temporarily not be reported
288
+ in ClusterMetadata.brokers. Always check the availability
289
+ of a broker id in the brokers dict.
290
+ """
291
+ def __init__ (self ):
292
+ self .partition = - 1
293
+ self .leader = - 1
294
+ self .replicas = []
295
+ self .isrs = []
296
+ self .error = None
297
+
298
+ def __repr__ (self ):
299
+ if self .error is not None :
300
+ return "PartitionMetadata({}, {})" .format (self .partition , self .error )
301
+ else :
302
+ return "PartitionMetadata({})" .format (self .partition )
303
+
304
+ def __str__ (self ):
305
+ return "{}" .format (self .partition )
0 commit comments