class Flare::Tools::Cli::Part

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/flare/tools/cli/part.rb, line 35
def initialize
  super
  @force = false
  @retry = nil
end

Public Instance Methods

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

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

  masters = []
  slaves = []

  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)

    partitions = {}
    hosts.each do |hostname,port,balance,partition|
      partitions[partition] = [] unless partitions.has_key? partition
      partitions[partition] << "#{hostname}:#{port}:#{balance}:#{partition}"
    end

    partitions.sort_by {|p,nodes| p.to_i }.each do |p,nodes|
      masters << nodes.shift
    end

    partitions.each do |p,nodes|
      slaves.concat nodes
    end
  end

  puts "master:"
  begin
    opt = OptionParser.new
    subc = Flare::Tools::Cli::Master.new
    args = masters
    args << "--force" if @force
    args << "--activate"
    subc.execute_subcommand(config, args)
  end

  puts "slaves:"
  begin
    opt = OptionParser.new
    subc = Flare::Tools::Cli::Slave.new
    args = slaves
    args << "--force" if @force
    args << "--retry=#{@retry}" unless @retry.nil?
    subc.execute_subcommand(config, args)
  end

  S_OK
end
setup() click to toggle source
Calls superclass method
# File lib/flare/tools/cli/part.rb, line 28
def setup
  super
  set_option_index_server
  set_option_force
  @optp.on('--retry=COUNT',    "retry count"                         ) {|v| @retry = v.to_i}
end