Exemplo n.º 1
0
 def list_topics(self, topic: str) -> ClusterMetadata:
     meta = ClusterMetadata()
     topic_meta = TopicMetadata()
     topic_meta.topic = topic
     topic_meta.partitions = {0: PartitionMetadata()}
     meta.topics = {topic: topic_meta}
     return meta
Exemplo n.º 2
0
def create_cluster_metadata(topic_partitions):
    """Create ClusterMetada out of a dict structure for easier mocking.

    topic_partitions should be in the format of {'topic1': [partition1, partition2], 'topic2': [partition3]...}
    """
    cluster_metadata = ClusterMetadata()
    topics_dict = {}
    for topic in topic_partitions.keys():
        topic_metadata = TopicMetadata()
        partitions = topic_partitions[topic]
        partitions_dict = {}
        for partition in partitions:
            partition_metadata = PartitionMetadata()
            partition_metadata.id = partition
            partitions_dict.update({partition: partition_metadata})
        topic_metadata.partitions = partitions_dict
        topic_metadata.topic = topic
        topics_dict.update({topic: topic_metadata})
    cluster_metadata.topics = topics_dict
    return cluster_metadata
def topic(name, partitions=[]):
    tm = TopicMetadata()
    tm.topic = name
    tm.partitions = {p.partition: p for p in partitions}
    return tm