def run(cls, args, cluster_config): # Setup the Kafka client client = KafkaToolClient(cluster_config.broker_list) client.load_metadata_for_topics() topics_dict = cls.preprocess_args( args.groupid, args.topic, args.partitions, cluster_config, client ) consumer_offsets_metadata = cls.get_offsets( client, args.groupid, topics_dict, args.storage, ) # Warn the user if a topic being subscribed to does not exist in # Kafka. for topic in topics_dict: if topic not in consumer_offsets_metadata: print( "Warning: Topic {topic} or one or more of it's partitions " "do not exist in Kafka".format(topic=topic), file=sys.stderr, ) client.close() if args.json: print_json(consumer_offsets_metadata) else: cls.print_output(consumer_offsets_metadata, args.watermark)
def run(cls, args, cluster_config): # Setup the Kafka client client = KafkaToolClient(cluster_config.broker_list) client.load_metadata_for_topics() topics_dict = cls.preprocess_args( groupid=args.groupid, topic=args.topic, partitions=args.partitions, cluster_config=cluster_config, client=client, quiet=args.json, storage=args.storage, ) consumer_offsets_metadata = cls.get_offsets( client, args.groupid, topics_dict, args.storage, ) client.close() if args.sort_by_distance: consumer_offsets_metadata = cls.sort_by_distance( consumer_offsets_metadata) elif args.sort_by_distance_percentage: consumer_offsets_metadata = cls.sort_by_distance_percentage( consumer_offsets_metadata) if args.json: partitions_info = [] for partitions in consumer_offsets_metadata.values(): for partition in partitions: partition_info = partition._asdict() partition_info['offset_distance'] = partition_info[ 'highmark'] - partition_info['current'] partition_info[ 'percentage_distance'] = cls.percentage_distance( partition_info['highmark'], partition_info['current']) partitions_info.append(partition_info) print_json(partitions_info) else: # Warn the user if a topic being subscribed to does not exist in # Kafka. for topic in topics_dict: if topic not in consumer_offsets_metadata: print( "Warning: Topic {topic} or one or more of it's partitions " "do not exist in Kafka".format(topic=topic), file=sys.stderr, ) cls.print_output(consumer_offsets_metadata, args.watermark)
def run(cls, args, cluster_config): # Setup the Kafka client client = KafkaToolClient(cluster_config.broker_list) client.load_metadata_for_topics() topics_dict = cls.preprocess_args( groupid=args.groupid, topic=args.topic, partitions=args.partitions, cluster_config=cluster_config, client=client, quiet=args.json, ) consumer_offsets_metadata = cls.get_offsets( client, args.groupid, topics_dict, ) client.close() if args.sort_by_distance: consumer_offsets_metadata = cls.sort_by_distance(consumer_offsets_metadata) elif args.sort_by_distance_percentage: consumer_offsets_metadata = cls.sort_by_distance_percentage(consumer_offsets_metadata) if args.json: partitions_info = [] for partitions in consumer_offsets_metadata.values(): for partition in partitions: partition_info = partition._asdict() partition_info['offset_distance'] = partition_info['highmark'] - partition_info['current'] partition_info['percentage_distance'] = cls.percentage_distance( partition_info['highmark'], partition_info['current'] ) partitions_info.append(partition_info) print_json(partitions_info) else: # Warn the user if a topic being subscribed to does not exist in # Kafka. for topic in topics_dict: if topic not in consumer_offsets_metadata: print( "Warning: Topic {topic} or one or more of it's partitions " "do not exist in Kafka".format(topic=topic), file=sys.stderr, ) cls.print_output(consumer_offsets_metadata, args.watermark)
def terminate(err_code, msg, json): if json: output = { 'status': STATUS_STRING[err_code], 'data': msg['raw'], } print_json(output) else: print('{status}: {msg}'.format( status=STATUS_STRING[err_code], msg=msg['message'], )) if 'verbose' in msg: print(msg['verbose']) sys.exit(err_code)
def terminate(signal, msg, json): if json: output = { 'status': STATUS_STRING[signal], 'data': msg['raw'], } print_json(output) else: print('{status}: {msg}'.format( status=STATUS_STRING[signal], msg=msg['message'], )) if 'verbose' in msg: print(msg['verbose']) sys.exit(signal)
def run(cls, args, cluster_config): # Setup the Kafka client client = KafkaToolClient(cluster_config.broker_list) client.load_metadata_for_topics() topics_dict = cls.preprocess_args(args.groupid, args.topic, args.partitions, cluster_config, client, quiet=args.json) consumer_offsets_metadata = cls.get_offsets( client, args.groupid, topics_dict, args.storage, ) client.close() if args.json: print_json([ p._asdict() for partitions in consumer_offsets_metadata.values() for p in partitions ]) else: # Warn the user if a topic being subscribed to does not exist in # Kafka. for topic in topics_dict: if topic not in consumer_offsets_metadata: print( "Warning: Topic {topic} or one or more of it's partitions " "do not exist in Kafka".format(topic=topic), file=sys.stderr, ) cls.print_output(consumer_offsets_metadata, args.watermark)
def run(cls, args, cluster_config): # Setup the Kafka client client = KafkaToolClient(cluster_config.broker_list) client.load_metadata_for_topics() watermarks = {} if args.exact: watermarks = cls.get_watermarks( client, args.topic, exact=True, ) else: watermarks = cls.get_watermarks( client, args.topic, exact=False, ) client.close() if args.json: print_json(watermarks) else: cls.print_output(watermarks)