Class: Flare::Tools::Cli::Remove

Inherits:
SubCommand show all
Includes:
Cli::AskNodeRemove, Cli::ParseHostPortPairs, Operation::NodeRemove, IndexServerConfig, Flare::Tools::Common
Defined in:
lib/flare/tools/cli/remove.rb

Constant Summary

Constants included from Cli::ParseHostPortPairs

Cli::ParseHostPortPairs::Entity

Constants included from IndexServerConfig

IndexServerConfig::Entity, IndexServerConfig::FLARE_INDEX_SERVER, IndexServerConfig::FLARE_INDEX_SERVERS

Constants included from Util::Constant

Util::Constant::DefalutBwlimit, Util::Constant::DefaultIndexServerName, Util::Constant::DefaultIndexServerPort, Util::Constant::DefaultNodePort, Util::Constant::DefaultTimeout, Util::Constant::STATUS_NG, Util::Constant::STATUS_OK

Constants included from Flare::Tools::Common

Flare::Tools::Common::NodeListFormat, Flare::Tools::Common::NodeListHeader

Constants inherited from SubCommand

SubCommand::S_NG, SubCommand::S_OK

Constants included from Util::Interruption

Util::Interruption::InterruptionTargets

Instance Attribute Summary

Attributes included from Option

#optp

Instance Method Summary collapse

Methods included from Operation::NodeRemove

#node_can_remove_safely?, #node_remove

Methods included from Cli::AskNodeRemove

#ask_node_remove

Methods included from Cli::ParseHostPortPairs

#parse_host_port_pairs

Methods included from Util::Logging

#debug, #error, #fatal, #info, logger, #puts, set_logger, #trace, #warn

Methods included from Flare::Tools::Common

#address_of_hostname, #fetch_cluster, #hostname_of_address, #nodekey_of, #string_of_nodelist, #user_confirmed, #wait_for_master_construction, #wait_for_servers, #wait_for_slave_construction

Methods inherited from SubCommand

desc, #execute_subcommand, myname, #myname, to_s, to_sym, usage

Methods included from Util::Interruption

included, #initialize_interruption, #interrupt, #interrupt_, interrupt_all, #interrupted?, #interruptible, #interruptible?

Methods included from Option

#option_init, #parse_options, #set_option_dry_run, #set_option_force, #set_option_global, #set_option_index_server

Constructor Details

#initializeRemove

Returns a new instance of Remove.



36
37
38
39
# File 'lib/flare/tools/cli/remove.rb', line 36

def initialize
  super
  @retry = 0
end

Instance Method Details

#execute(config, args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/flare/tools/cli/remove.rb', line 41

def execute(config, args)
  parse_index_server(config, args)
  nodes = parse_host_port_pairs(args)
  unless nodes
    return S_NG
  end

  Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s|
    cluster = fetch_cluster(s)

    nodes.each do |node|
      node_stat = cluster.node_stat(node.nodekey)

      unless node_stat
        error "node not found in cluster. (node=#{node})"
        next
      end

      # check status downed & proxy
      unless node_can_remove_safely?(node_stat)
        error "node should role=proxy and state=down. (node=#{node} role=#{node_stat.role} state=#{node_stat.state})"
        return S_NG
      end

      # ask really remove or not
      unless @force || ask_node_remove(node, node_stat)
        return S_NG
      end

      succeeded = node_remove(s, node, @retry, @dry_run)
      unless succeeded
        error "node remove failed. (node=#{node})"
        return S_NG
      end
    end

    # puts node list after nodes removed
    puts ""
    puts string_of_nodelist(s.stats_nodes)

    return S_OK
  end
end

#setupObject



28
29
30
31
32
33
34
# File 'lib/flare/tools/cli/remove.rb', line 28

def setup
  super
  set_option_index_server
  set_option_dry_run
  set_option_force
  @optp.on('--retry=COUNT', "retry count(default:#{@retry})") {|v| @retry = v.to_i }
end