Class: MotherBrain::Bootstrap::Manager
- Inherits:
-
Object
- Object
- MotherBrain::Bootstrap::Manager
- Includes:
- Celluloid, MB::Mixin::AttributeSetting, MB::Mixin::Locks, MB::Mixin::Services, Logging
- Defined in:
- lib/mb/bootstrap/manager.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#async_bootstrap(environment, manifest, plugin, options = {}) ⇒ MB::JobRecord
Asynchronously bootstrap a collection of nodes described in the given manifest in the proper order.
-
#bootstrap(job, environment, manifest, plugin, options = {}) ⇒ Object
Bootstrap a collection of nodes described in the given manifest in the proper order.
-
#concurrent_bootstrap(job, manifest, instructions, options = {}) ⇒ Hash
Concurrently bootstrap a grouped collection of nodes from a manifest and return their results.
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
Methods included from Logging
add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup
Constructor Details
Class Method Details
.instance ⇒ Celluloid::Actor(Bootstrap::Manager)
8 9 10 |
# File 'lib/mb/bootstrap/manager.rb', line 8 def instance MB::Application[:bootstrap_manager] or raise Celluloid::DeadActorError, "bootstrap manager not running" end |
Instance Method Details
#async_bootstrap(environment, manifest, plugin, options = {}) ⇒ MB::JobRecord
Asynchronously bootstrap a collection of nodes described in the given manifest in the proper order
58 59 60 61 62 63 |
# File 'lib/mb/bootstrap/manager.rb', line 58 def async_bootstrap(environment, manifest, plugin, = {}) job = Job.new(:bootstrap) async(:bootstrap, job, environment, manifest, plugin, ) job.ticket end |
#bootstrap(job, environment, manifest, plugin, options = {}) ⇒ Object
Bootstrap a collection of nodes described in the given manifest in the proper order
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 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/mb/bootstrap/manager.rb', line 77 def bootstrap(job, environment, manifest, plugin, = {}) = .reverse_merge( component_versions: Hash.new, environment_attributes: Hash.new, hints: Hash.new, bootstrap_proxy: Application.config[:chef][:bootstrap_proxy], sudo: Application.config[:ssh][:sudo], force: false ) [:environment] = environment job.report_running validate_bootstrap_configuration!(manifest, plugin) job.set_status("Searching for environment") unless chef_connection.environment.find(environment) return job.report_failure("Environment '#{environment}' not found") end job.set_status("Starting bootstrap of nodes on: #{environment}") task_queue = plugin.bootstrap_routine.task_queue.dup chef_synchronize(chef_environment: environment, force: [:force], job: job) do if [:component_versions].any? job.set_status("Setting component versions") set_component_versions(environment, plugin, [:component_versions]) end cookbook_versions = [:cookbook_versions] || plugin.cookbook_versions if cookbook_versions.any? job.set_status("Setting cookbook versions") set_cookbook_versions(environment, cookbook_versions) end if [:environment_attributes].any? job.set_status("Setting environment attributes") set_environment_attributes(environment, [:environment_attributes]) end unless [:environment_attributes_file].nil? job.set_status("Setting environment attributes from file") set_environment_attributes_from_file(environment, [:environment_attributes_file]) end while tasks = task_queue.shift host_errors = Hash.new group_names = Array(tasks).collect(&:group_name).join(', ') instructions = Bootstrap::Routine.map_instructions(tasks, manifest) if instructions.empty? log.info "Skipping bootstrap of group(s): #{group_names}. No hosts defined in manifest to bootstrap for " + "these groups." next end job.set_status("Bootstrapping group(s): #{group_names}") concurrent_bootstrap(job, manifest, instructions, ).each do |host, host_info| if host_info[:result][:status] == :error host_errors[host] = host_info end end unless host_errors.empty? abort GroupBootstrapError.new(host_errors) end job.set_status("Finished bootstrapping group(s): #{group_names}") end end job.report_success rescue => ex job.report_failure(ex) ensure job.terminate if job && job.alive? end |
#concurrent_bootstrap(job, manifest, instructions, options = {}) ⇒ Hash
Concurrently bootstrap a grouped collection of nodes from a manifest and return their results. This function will block until all nodes have finished bootstrapping.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/mb/bootstrap/manager.rb', line 212 def concurrent_bootstrap(job, manifest, instructions, = {}) response = Hash.new instructions.each do |host, host_info| = .merge(host_info[:options]) .merge!(manifest[:options]) if manifest[:options] job.set_status("Bootstrapping #{host} with group(s): #{host_info[:groups]}") response[host] = { groups: host_info[:groups], result: worker_pool.future(:run, host, ) } end response.each { |host, host_info| host_info[:result] = host_info[:result].value } end |