class Flare::Tools::Cli::Down

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/flare/tools/cli/down.rb, line 36
def initialize
  super
end

Public Instance Methods

execute(config, args) click to toggle source
# File lib/flare/tools/cli/down.rb, line 40
def execute(config, args)
  parse_index_server(config, args)
  return S_NG if args.size < 1

  hosts = args.map {|x| x.split(':')}
  hosts.each do |x|
    if x.size != 2
      puts "invalid argument '#{x.join(':')}'."
      return S_NG
    end
  end

  Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s|
    cluster = Flare::Tools::Cluster.new(s.host, s.port, s.stats_nodes)

    hosts.each do |hostname,port|
      down = 'down'
      nodekey = nodekey_of hostname, port
      ipaddr = address_of_hostname(hostname)

      unless cluster.has_nodekey? nodekey
        error "invalid 'hostname:port' pair: #{nodekey}"
        return S_NG
      end

      node = cluster.node_stat(nodekey)

      exec = @force
      if exec
      elsif node['state'] == down
        puts "#{ipaddr}:#{port} is already down."
      else
        STDERR.print "turning node down (node=#{ipaddr}:#{port}, state=#{node['state']} -> #{down}) (y/n): "
        exec = interruptible {(gets.chomp.upcase == "Y")}
      end
      if exec
        s.set_state(hostname, port, down) unless @dry_run
      end
    end

    puts string_of_nodelist(s.stats_nodes, hosts.map {|x| "#{x[0]}:#{x[1]}"})
  end

  S_OK
end
setup() click to toggle source
Calls superclass method
# File lib/flare/tools/cli/down.rb, line 29
def setup
  super
  set_option_index_server
  set_option_dry_run
  set_option_force
end