class Kafkat::Command::ElectLeaders

Public Instance Methods

run() click to toggle source
# File lib/kafkat/command/elect-leaders.rb, line 9
def run
  topic_name = ARGV[0] && ARGV.shift
  topic_names = topic_name && [topic_name]

  topics = zookeeper.get_topics(topic_names)
  partitions = topics.values.map(&:partitions).flatten

  topics_s = topic_name ? "'#{topic_name}'" : "all topics"
  print "This operation elects the preferred replicas for #{topics_s}.\n"
  return unless agree("Proceed (y/n)?")

  result = nil
  begin
    print "\nBeginning.\n"
    result = admin.elect_leaders!(partitions)
    print "Started.\n"
  rescue Interface::Admin::ExecutionFailedError
    print result
  end
end