示例#1
0
    def rename_group_with_storage_zookeeper(cls, old_groupid, new_groupid,
                                            topics_dict, cluster_config):
        with ZK(cluster_config) as zk:
            try:
                topics = zk.get_children(
                    "/consumers/{groupid}/offsets".format(groupid=new_groupid))
            except NoNodeError:
                # Consumer Group ID doesn't exist.
                pass
            else:
                preprocess_topics(
                    old_groupid,
                    list(topics_dict.keys()),
                    new_groupid,
                    topics,
                )

            old_offsets = fetch_offsets(zk, old_groupid, topics_dict)
            create_offsets(zk, new_groupid, old_offsets)
            try:
                old_base_path = "/consumers/{groupid}".format(
                    groupid=old_groupid, )
                zk.delete(old_base_path, recursive=True)
            except:
                print(
                    "Error: Unable to migrate all metadata in Zookeeper. "
                    "Please re-run the command.",
                    file=sys.stderr)
                raise
示例#2
0
    def copy_group_zk(cls, client, topics, source_group, destination_group,
                      cluster_config):
        with ZK(cluster_config) as zk:
            try:
                topics_dest_group = zk.get_children(
                    "/consumers/{groupid}/offsets".format(
                        groupid=destination_group, ))
            except NoNodeError:
                # Consumer Group ID doesn't exist.
                pass
            else:
                preprocess_topics(
                    source_group,
                    topics,
                    destination_group,
                    topics_dest_group,
                )

            # Fetch offsets
            source_offsets = fetch_offsets(zk, source_group, topics)
            create_offsets(zk, destination_group, source_offsets)
示例#3
0
    def run(cls, args, cluster_config):
        if args.source_groupid == args.dest_groupid:
            print(
                "Error: Source group ID and destination group ID are same.",
                file=sys.stderr,
            )
            sys.exit(1)
        # Setup the Kafka client
        client = KafkaToolClient(cluster_config.broker_list)
        client.load_metadata_for_topics()
        source_topics = cls.preprocess_args(
            args.source_groupid,
            args.topic,
            args.partitions,
            cluster_config,
            client,
        )
        with ZK(cluster_config) as zk:
            try:
                topics_dest_group = zk.get_children(
                    "/consumers/{groupid}/offsets".format(
                        groupid=args.dest_groupid,
                    )
                )
            except NoNodeError:
                # Consumer Group ID doesn't exist.
                pass
            else:
                preprocess_topics(
                    args.source_groupid,
                    source_topics.keys(),
                    args.dest_groupid,
                    topics_dest_group,
                )

            # Fetch offsets
            source_offsets = fetch_offsets(zk, args.source_groupid, source_topics)
            create_offsets(zk, args.dest_groupid, source_offsets)
示例#4
0
    def run(cls, args, cluster_config):
        if args.source_groupid == args.dest_groupid:
            print(
                "Error: Source group ID and destination group ID are same.",
                file=sys.stderr,
            )
            sys.exit(1)
        # Setup the Kafka client
        client = KafkaToolClient(cluster_config.broker_list)
        client.load_metadata_for_topics()
        source_topics = cls.preprocess_args(
            args.source_groupid,
            args.topic,
            args.partitions,
            cluster_config,
            client,
        )
        with ZK(cluster_config) as zk:
            try:
                topics_dest_group = zk.get_children(
                    "/consumers/{groupid}/offsets".format(
                        groupid=args.dest_groupid, ))
            except NoNodeError:
                # Consumer Group ID doesn't exist.
                pass
            else:
                preprocess_topics(
                    args.source_groupid,
                    source_topics.keys(),
                    args.dest_groupid,
                    topics_dest_group,
                )

            # Fetch offsets
            source_offsets = fetch_offsets(zk, args.source_groupid,
                                           source_topics)
            create_offsets(zk, args.dest_groupid, source_offsets)