def build_metadata(topics, member_assignment_partitions, generation=-1): partitions_by_topic = defaultdict(list) for topic_partition in member_assignment_partitions: partitions_by_topic[topic_partition.topic].append( topic_partition.partition) data = StickyAssignorUserDataV1(six.viewitems(partitions_by_topic), generation) user_data = data.encode() return ConsumerProtocolMemberMetadata(StickyPartitionAssignor.version, list(topics), user_data)
def metadata(cls, topics): if cls.member_assignment is None: log.debug("No member assignment available") user_data = b'' else: log.debug( "Member assignment is available, generating the metadata: generation {}" .format(cls.generation)) partitions_by_topic = defaultdict(list) for topic_partition in cls.member_assignment: # pylint: disable=not-an-iterable partitions_by_topic[topic_partition.topic].append( topic_partition.partition) data = StickyAssignorUserDataV1(six.viewitems(partitions_by_topic), cls.generation) user_data = data.encode() return ConsumerProtocolMemberMetadata(cls.version, list(topics), user_data)
def get_final_assignment(self, member_id): assignment = defaultdict(list) for topic_partition in self.current_assignment[member_id]: assignment[topic_partition.topic].append(topic_partition.partition) assignment = {k: sorted(v) for k, v in six.iteritems(assignment)} return six.viewitems(assignment)