def get_scores(self, *assignments): """Get a list of scores for a given list of assignments""" balancer = self.create_balancer() return [ balancer._score(_State(self.create_cluster_topology(assignment))) for assignment in assignments ]
def move_leadership_valid(self, partition, dest, cluster_topology=None, **kwargs): """Check whether or not a leader movement is allowed.""" if cluster_topology is None: cluster_topology = self.create_cluster_topology() balancer = self.create_balancer(cluster_topology, **kwargs) state = _State(cluster_topology) with mock.patch('kafka_utils.kafka_cluster_manager.cluster_info' '.genetic_balancer.random') as random: random.randint.side_effect = [partition, dest] return balancer._move_leadership(state) is not None
def move_partition_valid(self, partition, source, dest, cluster_topology=None, **kwargs): """Check whether or not a partition movement is allowed.""" if cluster_topology is None: cluster_topology = self.create_cluster_topology() balancer = self.create_balancer(cluster_topology, **kwargs) state = _State(cluster_topology) with mock.patch('kafka_utils.kafka_cluster_manager.cluster_info' '.genetic_balancer.random') as random: random.randint.side_effect = [partition, dest] random.choice.side_effect = [source] # balancer._move_partition returns None on failure. return balancer._move_partition(state) is not None
def _state(self): """Make the default state available as self.state""" self.state = _State(self.ct)