Skip to content

Commit 22403f6

Browse files
authored
V2.3.0 (#47)
* Update version to 2.3.0 * describe_topics and describe_cluster added * Set avro-python3 as legacy package and install new one with [avro] tag
1 parent 0add858 commit 22403f6

File tree

5 files changed

+71
-6
lines changed

5 files changed

+71
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ pip install robotframework-confluentkafkalibrary
2323
```
2424

2525
Extra packages:
26-
* [avro] = ['fastavro >= 1.3.2', 'avro-python3 >= 1.10.1']
26+
* [avro] = ['fastavro >= 1.3.2', 'avro >= 1.11.1']
27+
* [legacyavro] = ['fastavro >= 1.3.2', 'avro-python3 >= 1.10.1']
2728
* [json] = ['jsonschema >= 3.2.0']
2829
* [protobuf] = ['protobuf >= 4.22.0']
2930

examples/test_adminclient.robot

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,30 @@ AdminClient Alter Configs
147147
${config}= Describe Configs ${admin_client_id} ${resource}
148148
Should Be Equal As Integers ${54321} ${config["${resource.name}"]['log.retention.ms'].value}
149149

150+
AdminClient Describe Topics
151+
${topic_names}= Create List admintesting1 admintesting2 admintesting3
152+
${topics}= Create List
153+
FOR ${topic} IN @{topic_names}
154+
${topic}= New Topic ${topic} num_partitions=${1} replication_factor=${1}
155+
Append To List ${topics} ${topic}
156+
END
157+
158+
${admin_client_id}= Create Admin Client
159+
${results}= Create Topics group_id=${admin_client_id} new_topics=${topics}
160+
Log ${results}
161+
162+
${results}= Describe Topics ${admin_client_id} ${topic_names}
163+
Log ${results}
164+
FOR ${topic} IN @{topic_names}
165+
${status}= Evaluate len("${results["${topic}"].topic_id}") > 0
166+
Should Be True ${status}
167+
END
168+
[Teardown] Delete Topics ${admin_client_id} ${topic_names}
169+
170+
AdminClient Describe Cluster
171+
${admin_client_id}= Create Admin Client
172+
${cluster}= Describe Cluster ${admin_client_id}
173+
Should Not Be Empty ${cluster.cluster_id}
150174

151175
*** Keywords ***
152176
All Messages Are Delivered

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
Confluent Kafka wrapped in Robot Framework.
1111
"""[1:-1]
1212

13-
AVRO_REQUIRES = ['fastavro >= 1.3.2', 'avro-python3 >= 1.10.1']
13+
AVRO_REQUIRES = ['fastavro >= 1.3.2', 'avro >= 1.11.1']
14+
LEGACYAVRO_REQUIRES = ['fastavro >= 1.3.2', 'avro-python3 >= 1.10.1']
1415
JSON_REQUIRES = ['jsonschema >= 3.2.0']
1516
PROTO_REQUIRES = ['protobuf >= 4.22.0']
16-
ALL = AVRO_REQUIRES + JSON_REQUIRES + PROTO_REQUIRES
17+
ALL = AVRO_REQUIRES + LEGACYAVRO_REQUIRES + JSON_REQUIRES + PROTO_REQUIRES
1718
setup(name = 'robotframework-confluentkafkalibrary',
1819
version = VERSION,
1920
description = 'Confluent Kafka library for Robot Framework',
@@ -32,12 +33,13 @@
3233
],
3334
install_requires = [
3435
'robotframework >= 3.2.1',
35-
'confluent-kafka == 2.2.0',
36+
'confluent-kafka == 2.3.0',
3637
'requests >= 2.25.1',
3738
],
3839
extras_require={
3940
'all': ALL,
4041
'avro': AVRO_REQUIRES,
42+
'legacyavro': LEGACYAVRO_REQUIRES,
4143
'json': JSON_REQUIRES,
4244
'protobuf': PROTO_REQUIRES,
4345
},

src/ConfluentKafkaLibrary/admin_client.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import uuid
22
from confluent_kafka.admin import AdminClient
3-
from confluent_kafka import KafkaException
3+
from confluent_kafka import KafkaException, TopicCollection
44

55

66
class KafkaAdminClient():
@@ -170,6 +170,44 @@ def describe_configs(self, group_id, resources, **kwargs):
170170
return f"Invalid input: {e}"
171171
return config_results
172172

173+
def describe_topics(self, group_id, topics, **kwargs):
174+
"""Describe topics.
175+
- ``topics`` (list(str) or str): List of topic names or only topic name to describe.
176+
"""
177+
if isinstance(topics, list):
178+
topics = TopicCollection(topics)
179+
else:
180+
topics = TopicCollection([topics])
181+
182+
topics = self.admin_clients[group_id].describe_topics(topics, **kwargs)
183+
topics_results={}
184+
for topic, f in topics.items():
185+
try:
186+
if f.exception() is None:
187+
topics_results[topic] = f.result()
188+
else:
189+
topics_results[topic] = f.exception()
190+
except KafkaException as e:
191+
return f"Failed to describe topic {topic.name}: {e}"
192+
except (TypeError, ValueError ) as e:
193+
return f"Invalid input: {e}"
194+
return topics_results
195+
196+
def describe_cluster(self, group_id, **kwargs):
197+
"""Describe cluster.
198+
"""
199+
cluster = self.admin_clients[group_id].describe_cluster(**kwargs)
200+
try:
201+
if cluster.exception() is None:
202+
cluster = cluster.result()
203+
else:
204+
cluster = cluster.exception()
205+
except KafkaException as e:
206+
return f"Failed to describe cluster: {e}"
207+
except (TypeError, ValueError ) as e:
208+
return f"Invalid input: {e}"
209+
return cluster
210+
173211
def alter_configs(self, group_id, resources, **kwargs):
174212
"""Update configuration properties for the specified resources.
175213
- ``resources`` (list(ConfigResource) or ConfigResource): Resources to update configuration of.

src/ConfluentKafkaLibrary/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '2.2.0-1'
1+
VERSION = '2.3.0-1'

0 commit comments

Comments
 (0)