Beispiel #1
0
def describe_topic(state: State, topic_name: str, consumers: bool, output_format: str):
    """Describe a topic.

    Returns information on a given topic and its partitions, with the option of including
    all consumer groups that read from the topic.
    """
    topic = state.cluster.topic_controller.get_cluster_topic(topic_name)

    output_dict = {
        "topic": topic_name,
        "partitions": [partition.as_dict() for partition in topic.partitions],
        "config": topic.config,
    }

    if consumers:
        consumergroup_controller = ConsumerGroupController(state.cluster)
        groups = consumergroup_controller.list_consumer_groups()

        consumergroups = [
            group_name
            for group_name in groups
            if topic_name in consumergroup_controller.get_consumergroup(group_name).topics
        ]

        output_dict["consumergroups"] = consumergroups
    click.echo(format_output(output_dict, output_format))
def test_get_consumer_group(partly_read_consumer_group: str,
                            consumergroup_controller: ConsumerGroupController):
    instance = consumergroup_controller.get_consumergroup(
        partly_read_consumer_group)
    assert isinstance(instance, ConsumerGroup)