Class: Kontena::Cli::Grids::HealthCommand
- Inherits:
-
Kontena::Command
- Object
- Clamp::Command
- Kontena::Command
- Kontena::Cli::Grids::HealthCommand
- Includes:
- Common, Common, Helpers::HealthHelper
- Defined in:
- lib/kontena/cli/grids/health_command.rb
Instance Attribute Summary
Attributes inherited from Kontena::Command
#arguments, #exit_code, #result
Instance Method Summary collapse
- #execute ⇒ Object
-
#show_grid_health(grid, nodes) ⇒ Boolean
Validate grid/nodes configuration for grid operation.
Methods included from Common
#calculate_filesystem_stats, #calculate_loads, #calculate_mem_used, #find_grid_by_name, #get_grid, #grids, #print_grid, #to_gigabytes
Methods included from Helpers::HealthHelper
#grid_health, #health_icon, #node_etcd_health, #node_health
Methods included from Common
#access_token=, #add_master, #any_key_to_continue, #any_key_to_continue_with_timeout, #api_url, #api_url=, #caret, #clear_current_grid, #client, #cloud_auth?, #cloud_client, #config, #confirm, #confirm_command, #current_grid, #current_master_index, #debug?, #display_account_login_info, #display_login_info, display_logo, #display_master_login_info, #error, exit_with_error, #kontena_account, #logger, #pastel, #print, #prompt, #puts, #require_api_url, #require_token, #reset_client, #reset_cloud_client, #running_quiet?, #running_silent?, #running_verbose?, #spin_if, #spinner, #sprint, #sputs, #stdin_input, #use_refresh_token, #vfakespinner, #vputs, #vspinner, #warning
Methods inherited from Kontena::Command
banner, callback_matcher, #help_requested?, inherited, #instance, load_subcommand, requires_current_account_token, requires_current_account_token?, requires_current_grid, requires_current_grid?, requires_current_master, requires_current_master?, requires_current_master_token, requires_current_master_token?, #run, #run_callbacks, #verify_current_account_token, #verify_current_grid, #verify_current_master, #verify_current_master_token
Instance Method Details
#execute ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/kontena/cli/grids/health_command.rb', line 12 def execute require_api_url grid = get_grid(name) grid_nodes = client(require_token).get("grids/#{grid['name']}/nodes") return show_grid_health(grid, grid_nodes['nodes']) end |
#show_grid_health(grid, nodes) ⇒ Boolean
Validate grid/nodes configuration for grid operation
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 |
# File 'lib/kontena/cli/grids/health_command.rb', line 24 def show_grid_health(grid, nodes) initial_size = grid['initial_size'] minimum_size = grid['initial_size'] / 2 + 1 # a majority is required for etcd quorum grid_health = grid_health(grid, nodes) initial_nodes = nodes.select{|node| node['initial_member']} online_nodes = initial_nodes.select{|node| node['connected']} # configuration and status if initial_nodes.length == 0 puts "#{health_icon :error} Grid does not have any initial nodes, and requires at least #{minimum_size} of #{initial_size} initial nodes for operation" elsif online_nodes.empty? puts "#{health_icon :error} Grid does not have any initial nodes online, and requires at least #{minimum_size} of #{initial_size} initial nodes for operation" elsif initial_nodes.length < minimum_size puts "#{health_icon :error} Grid only has #{initial_nodes.length} initial nodes, and requires at least #{minimum_size} of #{initial_size} initial nodes for operation" elsif online_nodes.length < minimum_size puts "#{health_icon :error} Grid only has #{online_nodes.length} initial nodes online, and requires at least #{minimum_size} of #{initial_size} initial nodes for operation" elsif initial_nodes.length < initial_size puts "#{health_icon :warning} Grid only has #{initial_nodes.length} initial nodes of #{initial_size} required for high-availability" elsif online_nodes.length < initial_size puts "#{health_icon :warning} Grid only has #{online_nodes.length} initial nodes online of #{initial_size} required for high-availability" elsif initial_nodes.length == 2 puts "#{health_icon :warning} Grid only has #{initial_nodes.length} initial nodes, and is not high-availability" elsif initial_nodes.length == 1 puts "#{health_icon :warning} Grid only has #{initial_nodes.length} initial node, and is not high-availability" else puts "#{health_icon :ok} Grid has all #{online_nodes.length} of #{initial_size} initial nodes online" end nodes.each do |node| node_health = node_health(node, grid_health) if node['connected'] elsif node['initial_member'] puts "#{health_icon grid_health} Initial node #{node['name']} is offline" else puts "#{health_icon node_health} Grid node #{node['name']} is offline" end end # operational if we have etcd quorum return online_nodes.length >= minimum_size end |