Exemplo n.º 1
0
    def is_cluster_even(self, skip_topics=[]):
        for topic_name in self.cluster.topics:
            topic = self.cluster.topics[topic_name]
            if topic_name in skip_topics:
                continue

            # Create broker map for this topic.
            pmap = [dict.fromkeys(self.cluster.brokers.keys(), 0) for pos in range(len(topic.partitions[0].replicas))]
            for partition in topic.partitions:
                for i, replica in enumerate(partition.replicas):
                    pmap[i][replica.id] += 1

            if not pmap_matches_target(pmap, len(topic.partitions) // len(self.cluster.brokers)):
                print("Position map for topic {0}: {1}".format(topic_name, pmap))
                return False
        return True
Exemplo n.º 2
0
    def is_cluster_even(self, skip_topics=[]):
        for topic_name in self.cluster.topics:
            topic = self.cluster.topics[topic_name]
            if topic_name in skip_topics:
                continue

            # Create broker map for this topic.
            pmap = [dict.fromkeys(self.cluster.brokers.keys(), 0) for pos in range(len(topic.partitions[0].replicas))]
            for partition in topic.partitions:
                for i, replica in enumerate(partition.replicas):
                    pmap[i][replica.id] += 1

            if not pmap_matches_target(pmap, len(topic.partitions) / len(self.cluster.brokers)):
                print("Position map for topic {0}: {1}".format(topic_name, pmap))
                return False
        return True
Exemplo n.º 3
0
 def test_pmap_matches_target_fails(self):
     target = 1
     pmap = [{1: 1, 2: 2, 3: 0, 4: 1}, {1: 1, 2: 1, 3: 2, 4: 0}]
     assert not pmap_matches_target(pmap, target)
Exemplo n.º 4
0
 def test_pmap_matches_target(self):
     target = 2
     pmap = [{1: 2, 2: 2, 3: 2, 4: 2}, {1: 2, 2: 2, 3: 2, 4: 2}]
     assert pmap_matches_target(pmap, target)
Exemplo n.º 5
0
 def test_pmap_matches_target_fails(self):
     target = 1
     pmap = [{1: 1, 2: 2, 3: 0, 4: 1}, {1: 1, 2: 1, 3: 2, 4: 0}]
     assert not pmap_matches_target(pmap, target)
Exemplo n.º 6
0
 def test_pmap_matches_target(self):
     target = 2
     pmap = [{1: 2, 2: 2, 3: 2, 4: 2}, {1: 2, 2: 2, 3: 2, 4: 2}]
     assert pmap_matches_target(pmap, target)