Exemplo n.º 1
0
    def join_partitioned_group(
            self, group_id,
            weight=1,
            partitions=partitioner.Partitioner.DEFAULT_PARTITION_NUMBER):
        """Join a group and get a partitioner.

        A partitioner allows to distribute a bunch of objects across several
        members using a consistent hash ring. Each object gets assigned (at
        least) one member responsible for it. It's then possible to check which
        object is owned by any member of the group.

        This method also creates if necessary, and joins the group with the
        selected weight.

        :param group_id: The group to create a partitioner for.
        :param weight: The weight to use in the hashring for this node.
        :param partitions: The number of partitions to create.
        :return: A :py:class:`~tooz.partitioner.Partitioner` object.

        """
        self.join_group_create(
            group_id, capabilities=utils.dumps({'weight': weight}))
        return partitioner.Partitioner(self, group_id, partitions=partitions)
Exemplo n.º 2
0
 def get_task_executor(self, task_id):
     part = partitioner.Partitioner(self.coordinator, self.GROUP_NAME)
     members = part.members_for_object(task_id)
     for member in members:
         LOG.info('For task id %s, host should be %s' % (task_id, member))
         return member.decode('utf-8')