Class: Exec::ClusterAllocate
- Inherits:
-
ExecutableCommand
- Object
- ExecutableCommand
- Exec::ClusterAllocate
- Defined in:
- lib/exec/cluster_allocate.rb
Overview
Allows user to allocate node on a cluster
Defined Under Namespace
Classes: CustomCommandOption
Instance Attribute Summary
Attributes inherited from ExecutableCommand
#argv, #command_name, #logger, #options, #stderr, #stdin, #stdout, #values
Instance Method Summary collapse
- #exec ⇒ Object private
-
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ClusterAllocate
constructor
Default constructor of the class.
-
#set_options ⇒ Object
private
Parse and check the parameters of the function.
Methods inherited from ExecutableCommand
#check_parameters, #create_logger, #run
Constructor Details
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ClusterAllocate
Note:
Overrides default constructor by passing CustomCommandOption to super().
Default constructor of the class.
26 27 28 |
# File 'lib/exec/cluster_allocate.rb', line 26 def initialize(argv, stdin, stdout, stderr, command_name) super(argv, stdin, stdout, stderr, command_name, CustomCommandOption) end |
Instance Method Details
#exec ⇒ Object (private)
39 40 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 84 85 86 87 88 89 90 91 92 93 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/exec/cluster_allocate.rb', line 39 def exec @logger.info("Exec::ClusterAllocate Executing ClusterAllocate") @logger.info("Exec::ClusterAllocate Allocate node on the vcluster '#{@values['cluster']}'...") Color::print_log("NONE", "Allocate node on the vcluster '#{@values['cluster']}'...", @stdout) output = "" if @values['all'] ###### Allocate all nodes ###### @logger.info("executing CrowbarNodeList") cmd = Command::.new(@logger, "Ready") list_nodes = cmd.exec list_nodes_filter = Array.new list_nodes.each { |node| list_nodes_filter << node.split(" ").at(0).strip.to_s } cmd = Command::.new(@logger, @values['cluster_name'], true, list_nodes_filter) output += cmd.exec() Color::echo_ok(@stdout) output.each{|out| Color::print_log("NONE", "#{out}", @stdout) Color::echo_ok(@stdout) } elsif @values['list_nodes'] != nil ###### Allocate a list of nodes ###### cmd = Command::.new(@logger, "Ready") list_nodes_ready = cmd.exec() list_nodes = Hash.new @values['list_nodes'].split(" ").each{|node| list_nodes[node] = node } list_nodes_filter = Array.new list_nodes.each {|key, value| node_exists = false list_nodes_ready.each{|node| if node == key node_exists = true end } if !node_exists raise NodeNotExistsError.new("The node '#{key}' is not exists.") end list_nodes_filter << key.strip.to_s } cmd = Command::.new(@logger, @values['cluster_name'], false, list_nodes_filter) output += cmd.exec() Color::echo_ok(@stdout) output.each{|out| Color::print_log("NONE", "#{out}", @stdout) Color::echo_ok(@stdout) } end @logger.info("Exec::ClusterAllocate Allocate node on the ambari cluster '#{@values['cluster']}'...") Color::print_log("NONE", "Allocate node on the vcluster '#{@values['cluster']}'...", @stdout) output = "" ###### Allocate nodes on the ambari cluster ###### cmd = Command::.new(@values['cluster_name']) list_hosts = cmd.exec() list_nodes_filter.each do |node| host_exists = false attempts = 0 node = "#{@values['cluster_name']}-#{node.gsub(/\s+/, "").strip}" list_hosts.each{|host| if host.strip == node.strip host_exists = true end } if !host_exists begin cmd = Command::.new(@values['cluster_name'], node) cmd.exec() rescue => e attempts += 1 sleep 5 retry unless attempts > 10 raise ClusterAllocateError.new("Allocate the host '#{node}' to the ambari cluster '#{@values['cluster_name']}'.") end output += "Add the host #{node} into the cluster #{@values['cluster_name']}.\n" else output += "The host #{node} into the cluster #{@values['cluster_name']} is already exists...\n" end Color::echo_ok(@stdout) output.each{|out| Color::print_log("NONE", "#{out}", @stdout) Color::echo_ok(@stdout) } end end |
#set_options ⇒ Object (private)
Parse and check the parameters of the function.
33 34 35 36 37 |
# File 'lib/exec/cluster_allocate.rb', line 33 def .add_option("a", "all", "All nodes which are ready.", false) .add_option("C", "cluster_name", "The name of the vcluster .", true, true, method(:check_cluster_name)) .add_option("n", "list_nodes", "The list of nodes.", false, true, method(:check_crowbar_node_name)) end |