Class: Kafkat::ClusterRestart::Subcommands::Next

Inherits:
Kafkat::Command::Base show all
Defined in:
lib/kafkat/command/cluster_restart.rb

Instance Attribute Summary collapse

Attributes inherited from Kafkat::Command::Base

#config

Instance Method Summary collapse

Methods inherited from Kafkat::Command::Base

#admin, #initialize, #kafka_logs, register_as, usage, usages, #zookeeper

Methods included from Logging

#print_err

Methods included from Kafkat::CommandIO

#prompt_and_execute_assignments

Methods included from Formatting

#justify, #print_assignment, #print_assignment_header, #print_broker, #print_broker_header, #print_partition, #print_partition_header, #print_topic, #print_topic_header, #print_topic_name

Constructor Details

This class inherits a constructor from Kafkat::Command::Base

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



92
93
94
# File 'lib/kafkat/command/cluster_restart.rb', line 92

def session
  @session
end

#topicsObject (readonly)

Returns the value of attribute topics.



92
93
94
# File 'lib/kafkat/command/cluster_restart.rb', line 92

def topics
  @topics
end

Instance Method Details

#runObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/kafkat/command/cluster_restart.rb', line 94

def run
  unless Session.exists?
    puts "ERROR: no session in progress"
    puts "\n[Action] Please run 'start' command"
    exit 1
  end

  @session = Session.load!
  if @session.all_restarted?
    puts "All the brokers have been restarted"
  else
    pendings = @session.pending_brokers
    if pendings.size > 1
      puts "ERROR Illegal state: multiple brokers are in Pending state"
      exit 1
    elsif pendings.size == 1
      next_broker = pendings[0]
      puts "Broker #{next_broker} is in Pending state"
    else
      @topics = zookeeper.get_topics
      next_broker, cost = ClusterRestartHelper.select_broker_with_min_cost(session, topics)
      @session.update_states!(Session::STATE_PENDING, [next_broker])
      @session.save!
      puts "The next broker is: #{next_broker}"
    end
    puts "\n[Action-1] Restart broker #{next_broker} aka #{zookeeper.get_broker(next_broker).host}"
    puts "\n[Action-2] Run 'good #{next_broker}' to mark it as restarted."
  end
end