Class: StellarCoreCommander::Commander
- Inherits:
-
Object
- Object
- StellarCoreCommander::Commander
- Includes:
- Contracts
- Defined in:
- lib/stellar_core_commander/commander.rb
Overview
Commander is the object that manages running stellar-core processes. It is responsible for creating and cleaning Process objects
Instance Attribute Summary collapse
-
#process_options ⇒ Object
readonly
Returns the value of attribute process_options.
Instance Method Summary collapse
- #check_no_process_error_metrics ⇒ Object
- #cleanup ⇒ Object
- #cleanup_at_exit!(clean_up_destination) ⇒ Object
- #get_root_process(transactor) ⇒ Object
-
#initialize(process_type, destination, process_options = {}) ⇒ Commander
constructor
A new instance of Commander.
-
#make_process(transactor, name, quorum, options = {}) ⇒ Object
make_process returns a new, unlaunched Process object, bound to a new tmpdir.
- #require_processes_in_sync ⇒ Object
- #start_all_processes ⇒ Object
Constructor Details
#initialize(process_type, destination, process_options = {}) ⇒ Commander
Returns a new instance of Commander.
18 19 20 21 22 23 |
# File 'lib/stellar_core_commander/commander.rb', line 18 def initialize(process_type, destination, ={}) @process_type = process_type @destination = destination @process_options = @processes = [] end |
Instance Attribute Details
#process_options ⇒ Object (readonly)
Returns the value of attribute process_options.
12 13 14 |
# File 'lib/stellar_core_commander/commander.rb', line 12 def @process_options end |
Instance Method Details
#check_no_process_error_metrics ⇒ Object
99 100 101 102 103 104 |
# File 'lib/stellar_core_commander/commander.rb', line 99 def check_no_process_error_metrics @processes.each do |p| p.check_no_error_metrics end true end |
#cleanup ⇒ Object
106 107 108 |
# File 'lib/stellar_core_commander/commander.rb', line 106 def cleanup @processes.each(&:cleanup) end |
#cleanup_at_exit!(clean_up_destination) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/stellar_core_commander/commander.rb', line 110 def cleanup_at_exit!(clean_up_destination) at_exit do $stderr.puts "cleaning up #{@processes.length} processes" cleanup FileUtils.rm_rf @destination if clean_up_destination end end |
#get_root_process(transactor) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/stellar_core_commander/commander.rb', line 58 def get_root_process(transactor) if @processes.size == 0 make_process transactor, :node0, [:node0] end @processes[0] end |
#make_process(transactor, name, quorum, options = {}) ⇒ Object
make_process returns a new, unlaunched Process object, bound to a new tmpdir
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 |
# File 'lib/stellar_core_commander/commander.rb', line 29 def make_process(transactor, name, quorum, ={}) working_dir = File.join(@destination, name.to_s) FileUtils.mkpath(working_dir) = @process_options.merge({ transactor: transactor, working_dir: working_dir, name: name, base_port: 11625 + @processes.map(&:required_ports).sum, identity: Stellar::KeyPair.random, quorum: quorum, manual_close: transactor.manual_close }).merge() process_class = case @process_type when 'local' LocalProcess when 'docker' DockerProcess else raise "Unknown process type: #{@process_type}" end process_class.new().tap do |p| @processes << p end end |
#require_processes_in_sync ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/stellar_core_commander/commander.rb', line 82 def require_processes_in_sync @processes.each do |p| next unless p.await_sync? begin p.wait_for_ready unless p.synced? rescue Timeout::Error @processes.each do |p2| p2.dump_scp_state p2.dump_info p2.dump_metrics raise "process #{p.name} lost sync" end end end end |
#start_all_processes ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/stellar_core_commander/commander.rb', line 66 def start_all_processes stopped = @processes.select(&:stopped?) stopped.each(&:prepare) stopped.each do |p| next if p.running? $stderr.puts "running #{p.idname} (dir:#{p.working_dir})" p.run p.wait_for_ready if p.await_sync? end end |