motherbrain 0.0.0.placeholder → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +196 -0
- data/COMMANDS.md +9 -0
- data/CONTRIBUTING.md +24 -0
- data/Dockerfile +26 -0
- data/Gemfile +60 -2
- data/Guardfile +30 -0
- data/LICENSE +10 -0
- data/MANIFESTS.md +90 -0
- data/OPERATORS_GUIDE.md +195 -0
- data/PLUGINS.md +268 -0
- data/README.md +304 -16
- data/Thorfile +123 -0
- data/VAGRANT.md +116 -0
- data/bin/boot +9 -0
- data/bin/mb +5 -0
- data/bin/mbsrv +5 -0
- data/config.json +32 -0
- data/features/cli/bootstrap_command/configurable_scripts.feature +32 -0
- data/features/cli/configure_command.feature +57 -0
- data/features/cli/environment_command/create_command.feature +22 -0
- data/features/cli/environment_command/destroy_command.feature +33 -0
- data/features/cli/environment_command/from_command.feature +29 -0
- data/features/cli/environment_command/list_command.feature +0 -0
- data/features/cli/node_limiting.feature +47 -0
- data/features/cli/plugin_command/list_command.feature +46 -0
- data/features/cli/service_command/service_command.feature +21 -0
- data/features/cli/template_command.feature +10 -0
- data/features/cli/validate_config.feature +46 -0
- data/features/step_definitions/bootstrap_steps.rb +57 -0
- data/features/step_definitions/chef_server_steps.rb +3 -0
- data/features/step_definitions/configuration_steps.rb +18 -0
- data/features/step_definitions/core_cli_steps.rb +33 -0
- data/features/step_definitions/environment_steps.rb +43 -0
- data/features/step_definitions/node_steps.rb +3 -0
- data/features/step_definitions/plugin_steps.rb +15 -0
- data/features/step_definitions/template_steps.rb +7 -0
- data/features/support/env.rb +68 -0
- data/lib/mb/api.rb +8 -0
- data/lib/mb/api/application.rb +7 -0
- data/lib/mb/api/endpoint.rb +5 -0
- data/lib/mb/api/helpers.rb +38 -0
- data/lib/mb/api/v1.rb +56 -0
- data/lib/mb/api/v1/config_endpoint.rb +12 -0
- data/lib/mb/api/v1/environments_endpoint.rb +174 -0
- data/lib/mb/api/v1/jobs_endpoint.rb +31 -0
- data/lib/mb/api/v1/plugins_endpoint.rb +90 -0
- data/lib/mb/api/validators.rb +5 -0
- data/lib/mb/api/validators/sem_ver.rb +18 -0
- data/lib/mb/application.rb +148 -0
- data/lib/mb/berkshelf.rb +50 -0
- data/lib/mb/bootstrap.rb +9 -0
- data/lib/mb/bootstrap/manager.rb +250 -0
- data/lib/mb/bootstrap/manifest.rb +131 -0
- data/lib/mb/bootstrap/routine.rb +199 -0
- data/lib/mb/bootstrap/template.rb +73 -0
- data/lib/mb/bootstrap/worker.rb +227 -0
- data/lib/mb/chef.rb +6 -0
- data/lib/mb/chef/config.rb +69 -0
- data/lib/mb/chef/run_list_item.rb +115 -0
- data/lib/mb/chef_mutex.rb +304 -0
- data/lib/mb/clean_room_base.rb +39 -0
- data/lib/mb/cli.rb +50 -0
- data/lib/mb/cli/base.rb +51 -0
- data/lib/mb/cli/shell.rb +29 -0
- data/lib/mb/cli/shell/basic.rb +11 -0
- data/lib/mb/cli/shell/color.rb +11 -0
- data/lib/mb/cli/shell/ext.rb +41 -0
- data/lib/mb/cli/sub_command.rb +95 -0
- data/lib/mb/cli/sub_command/component.rb +56 -0
- data/lib/mb/cli/sub_command/plugin.rb +232 -0
- data/lib/mb/cli_client.rb +178 -0
- data/lib/mb/cli_gateway.rb +426 -0
- data/lib/mb/cli_gateway/sub_commands.rb +3 -0
- data/lib/mb/cli_gateway/sub_commands/environment.rb +124 -0
- data/lib/mb/cli_gateway/sub_commands/plugin.rb +148 -0
- data/lib/mb/command.rb +88 -0
- data/lib/mb/command_invoker.rb +235 -0
- data/lib/mb/command_invoker/worker.rb +40 -0
- data/lib/mb/command_runner.rb +233 -0
- data/lib/mb/component.rb +245 -0
- data/lib/mb/config.rb +275 -0
- data/lib/mb/config_manager.rb +75 -0
- data/lib/mb/console.rb +35 -0
- data/lib/mb/cookbook_metadata.rb +73 -0
- data/lib/mb/core_ext.rb +3 -0
- data/lib/mb/core_ext/dir.rb +37 -0
- data/lib/mb/core_ext/enumerable.rb +48 -0
- data/lib/mb/core_ext/file.rb +24 -0
- data/lib/mb/core_ext/signal.rb +11 -0
- data/lib/mb/environment_manager.rb +195 -0
- data/lib/mb/error_handler.rb +212 -0
- data/lib/mb/errors.rb +693 -0
- data/lib/mb/file_system.rb +60 -0
- data/lib/mb/file_system/tempfile.rb +25 -0
- data/lib/mb/gear.rb +154 -0
- data/lib/mb/gears.rb +8 -0
- data/lib/mb/gears/dynamic_service.rb +218 -0
- data/lib/mb/gears/jmx.rb +24 -0
- data/lib/mb/gears/jmx/action.rb +46 -0
- data/lib/mb/gears/mysql.rb +20 -0
- data/lib/mb/gears/mysql/action.rb +190 -0
- data/lib/mb/gears/service.rb +163 -0
- data/lib/mb/gears/service/action.rb +58 -0
- data/lib/mb/gears/service/action_runner.rb +161 -0
- data/lib/mb/grape_ext.rb +3 -0
- data/lib/mb/grape_ext/endpoint.rb +13 -0
- data/lib/mb/group.rb +143 -0
- data/lib/mb/job.rb +183 -0
- data/lib/mb/job/state_machine.rb +34 -0
- data/lib/mb/job/states.rb +46 -0
- data/lib/mb/job_manager.rb +96 -0
- data/lib/mb/job_record.rb +67 -0
- data/lib/mb/job_ticket.rb +25 -0
- data/lib/mb/lock_manager.rb +116 -0
- data/lib/mb/logging.rb +134 -0
- data/lib/mb/logging/basic_format.rb +31 -0
- data/lib/mb/manifest.rb +128 -0
- data/lib/mb/mixin.rb +3 -0
- data/lib/mb/mixin/attribute_setting.rb +265 -0
- data/lib/mb/mixin/coded_exit.rb +49 -0
- data/lib/mb/mixin/locks.rb +54 -0
- data/lib/mb/mixin/services.rb +100 -0
- data/lib/mb/node_filter.rb +97 -0
- data/lib/mb/node_querier.rb +527 -0
- data/lib/mb/plugin.rb +300 -0
- data/lib/mb/plugin_manager.rb +589 -0
- data/lib/mb/provisioner.rb +186 -0
- data/lib/mb/provisioner/manager.rb +213 -0
- data/lib/mb/provisioner/manifest.rb +125 -0
- data/lib/mb/provisioner/provision_data.rb +96 -0
- data/lib/mb/provisioners.rb +5 -0
- data/lib/mb/provisioners/aws.rb +395 -0
- data/lib/mb/rest_gateway.rb +72 -0
- data/lib/mb/ridley_ext.rb +5 -0
- data/lib/mb/ridley_ext/cookbook_object.rb +15 -0
- data/lib/mb/srv_ctl.rb +183 -0
- data/lib/mb/test.rb +104 -0
- data/lib/mb/thor_ext.rb +49 -0
- data/lib/mb/upgrade.rb +6 -0
- data/lib/mb/upgrade/manager.rb +85 -0
- data/lib/mb/upgrade/worker.rb +149 -0
- data/lib/mb/version.rb +1 -1
- data/lib/motherbrain.rb +166 -2
- data/man/man_helper.rb +81 -0
- data/man/mb.1 +494 -0
- data/man/mb.1.html +300 -0
- data/man/mb.1.ronn.erb +62 -0
- data/motherbrain.gemspec +56 -20
- data/scripts/node_name.rb +14 -0
- data/spec/fixtures/cb_metadata.json +7 -0
- data/spec/fixtures/cb_metadata.rb +14 -0
- data/spec/fixtures/fake_id_rsa +27 -0
- data/spec/fixtures/fake_key.pem +27 -0
- data/spec/fixtures/myface-0.1.0/metadata.rb +14 -0
- data/spec/fixtures/myface-0.1.0/motherbrain.rb +0 -0
- data/spec/fixtures/test_env.json +15 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/actor_mocking.rb +7 -0
- data/spec/support/berkshelf.rb +24 -0
- data/spec/support/chef_server.rb +102 -0
- data/spec/support/doubles.rb +11 -0
- data/spec/support/klass.rb +10 -0
- data/spec/support/matchers/each.rb +12 -0
- data/spec/support/matchers/error_codes.rb +5 -0
- data/spec/support/matchers/exit_codes.rb +57 -0
- data/spec/support/matchers/jobs.rb +11 -0
- data/spec/support/spec_helpers.rb +145 -0
- data/spec/unit/mb/api/application_spec.rb +11 -0
- data/spec/unit/mb/api/helpers_spec.rb +5 -0
- data/spec/unit/mb/api/v1/config_endpoint_spec.rb +19 -0
- data/spec/unit/mb/api/v1/environments_endpoint_spec.rb +71 -0
- data/spec/unit/mb/api/v1/jobs_endpoint_spec.rb +24 -0
- data/spec/unit/mb/api/v1/plugins_endpoint_spec.rb +298 -0
- data/spec/unit/mb/api/v1_spec.rb +37 -0
- data/spec/unit/mb/api/validators/sem_ver_spec.rb +5 -0
- data/spec/unit/mb/application_spec.rb +19 -0
- data/spec/unit/mb/berkshelf_spec.rb +38 -0
- data/spec/unit/mb/bootstrap/manager_spec.rb +347 -0
- data/spec/unit/mb/bootstrap/manifest_spec.rb +333 -0
- data/spec/unit/mb/bootstrap/routine_spec.rb +393 -0
- data/spec/unit/mb/bootstrap/template_spec.rb +100 -0
- data/spec/unit/mb/bootstrap/worker_spec.rb +194 -0
- data/spec/unit/mb/chef/config_spec.rb +33 -0
- data/spec/unit/mb/chef/run_list_item_spec.rb +34 -0
- data/spec/unit/mb/chef_mutex_spec.rb +314 -0
- data/spec/unit/mb/clean_room_base_spec.rb +31 -0
- data/spec/unit/mb/cli/base_spec.rb +43 -0
- data/spec/unit/mb/cli/shell/basic_spec.rb +5 -0
- data/spec/unit/mb/cli/shell/color_spec.rb +5 -0
- data/spec/unit/mb/cli/shell/ext_spec.rb +11 -0
- data/spec/unit/mb/cli/shell_spec.rb +38 -0
- data/spec/unit/mb/cli/sub_command/base_spec.rb +102 -0
- data/spec/unit/mb/cli/sub_command/component_spec.rb +5 -0
- data/spec/unit/mb/cli/sub_command/plugin_spec.rb +91 -0
- data/spec/unit/mb/cli/sub_command_spec.rb +43 -0
- data/spec/unit/mb/cli/ui.rb +0 -0
- data/spec/unit/mb/cli_client_spec.rb +51 -0
- data/spec/unit/mb/cli_gateway_spec.rb +386 -0
- data/spec/unit/mb/command_invoker/worker_spec.rb +43 -0
- data/spec/unit/mb/command_invoker_spec.rb +230 -0
- data/spec/unit/mb/command_runner_spec.rb +299 -0
- data/spec/unit/mb/command_spec.rb +76 -0
- data/spec/unit/mb/component_spec.rb +185 -0
- data/spec/unit/mb/config_manager_spec.rb +31 -0
- data/spec/unit/mb/config_spec.rb +408 -0
- data/spec/unit/mb/cookbook_metadata_spec.rb +89 -0
- data/spec/unit/mb/core_ext/dir_spec.rb +92 -0
- data/spec/unit/mb/core_ext/enumerable_spec.rb +104 -0
- data/spec/unit/mb/core_ext/file_spec.rb +58 -0
- data/spec/unit/mb/core_ext/signal_spec.rb +24 -0
- data/spec/unit/mb/environment_manager_spec.rb +166 -0
- data/spec/unit/mb/error_handler_spec.rb +173 -0
- data/spec/unit/mb/errors_spec.rb +132 -0
- data/spec/unit/mb/file_system/tempfile_spec.rb +14 -0
- data/spec/unit/mb/file_system_spec.rb +69 -0
- data/spec/unit/mb/gear_spec.rb +125 -0
- data/spec/unit/mb/gears/dynamic_service_spec.rb +187 -0
- data/spec/unit/mb/gears/jmx/action_spec.rb +34 -0
- data/spec/unit/mb/gears/jmx_spec.rb +32 -0
- data/spec/unit/mb/gears/mysql/action_spec.rb +118 -0
- data/spec/unit/mb/gears/mysql_spec.rb +21 -0
- data/spec/unit/mb/gears/service/action_runner_spec.rb +182 -0
- data/spec/unit/mb/gears/service/action_spec.rb +44 -0
- data/spec/unit/mb/gears/service_spec.rb +124 -0
- data/spec/unit/mb/group_spec.rb +280 -0
- data/spec/unit/mb/job_manager_spec.rb +56 -0
- data/spec/unit/mb/job_record_spec.rb +60 -0
- data/spec/unit/mb/job_spec.rb +201 -0
- data/spec/unit/mb/locks_manager_spec.rb +88 -0
- data/spec/unit/mb/logging_spec.rb +133 -0
- data/spec/unit/mb/manifest_spec.rb +105 -0
- data/spec/unit/mb/mixin/attribute_setting_spec.rb +180 -0
- data/spec/unit/mb/mixin/coded_exit_spec.rb +25 -0
- data/spec/unit/mb/mixin/locks_spec.rb +32 -0
- data/spec/unit/mb/mixin/services_spec.rb +75 -0
- data/spec/unit/mb/node_filter_spec.rb +86 -0
- data/spec/unit/mb/node_querier_spec.rb +532 -0
- data/spec/unit/mb/plugin_manager_spec.rb +724 -0
- data/spec/unit/mb/plugin_spec.rb +247 -0
- data/spec/unit/mb/provisioner/manager_spec.rb +141 -0
- data/spec/unit/mb/provisioner/manifest_spec.rb +182 -0
- data/spec/unit/mb/provisioner/provision_data_spec.rb +113 -0
- data/spec/unit/mb/provisioner_spec.rb +251 -0
- data/spec/unit/mb/provisioners/aws_spec.rb +392 -0
- data/spec/unit/mb/provisioners/environment_factory_spec.rb +108 -0
- data/spec/unit/mb/rest_gateway_spec.rb +13 -0
- data/spec/unit/mb/ridley_ext/cookbook_object_spec.rb +105 -0
- data/spec/unit/mb/srv_ctl_spec.rb +142 -0
- data/spec/unit/mb/upgrade/manager_spec.rb +37 -0
- data/spec/unit/mb/upgrade/worker_spec.rb +219 -0
- data/spec/unit/motherbrain_spec.rb +58 -0
- data/templates/bootstrap.json +8 -0
- data/templates/motherbrain.rb +44 -0
- metadata +694 -15
- data/Rakefile +0 -1
data/lib/mb/berkshelf.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module MotherBrain
|
2
|
+
# This module contains integration code for Berkshelf into motherbrain
|
3
|
+
module Berkshelf
|
4
|
+
class << self
|
5
|
+
# An array of Pathnames representing cookbooks in the Berkshelf
|
6
|
+
#
|
7
|
+
# @option options [Boolean] :with_plugin
|
8
|
+
# only return cookbooks that contain a plugin
|
9
|
+
#
|
10
|
+
# @return [Array<Pathname>]
|
11
|
+
def cookbooks(options = {})
|
12
|
+
cookbooks = cookbooks_path.children
|
13
|
+
|
14
|
+
if options[:with_plugin]
|
15
|
+
cookbooks.select! { |cb_path| Dir.has_mb_plugin?(cb_path) }
|
16
|
+
end
|
17
|
+
|
18
|
+
cookbooks
|
19
|
+
end
|
20
|
+
|
21
|
+
# Location of the cookbooks directory in the Berkshelf
|
22
|
+
#
|
23
|
+
# @return [Pathname]
|
24
|
+
def cookbooks_path
|
25
|
+
path.join('cookbooks')
|
26
|
+
end
|
27
|
+
|
28
|
+
# The default location of the Berkshelf. This is in your user directory
|
29
|
+
# unless explicitly specified by the environment variable 'BERKSHELF_PATH'
|
30
|
+
#
|
31
|
+
# @return [String]
|
32
|
+
def default_path
|
33
|
+
ENV["BERKSHELF_PATH"] || File.expand_path("~/.berkshelf")
|
34
|
+
end
|
35
|
+
|
36
|
+
# Create the directory structure for the Berkshelf
|
37
|
+
def init
|
38
|
+
FileUtils.mkdir_p(path)
|
39
|
+
FileUtils.mkdir_p(cookbooks_path)
|
40
|
+
end
|
41
|
+
|
42
|
+
# The location of the Berkshelf
|
43
|
+
#
|
44
|
+
# @return [Pathname]
|
45
|
+
def path
|
46
|
+
Pathname.new(Application.config.berkshelf.path || default_path)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/mb/bootstrap.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
module MotherBrain
|
2
|
+
module Bootstrap
|
3
|
+
autoload :Manager, 'mb/bootstrap/manager'
|
4
|
+
autoload :Manifest, 'mb/bootstrap/manifest'
|
5
|
+
autoload :Routine, 'mb/bootstrap/routine'
|
6
|
+
autoload :Worker, 'mb/bootstrap/worker'
|
7
|
+
autoload :Template, 'mb/bootstrap/template'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,250 @@
|
|
1
|
+
module MotherBrain
|
2
|
+
module Bootstrap
|
3
|
+
class Manager
|
4
|
+
class << self
|
5
|
+
# @raise [Celluloid::DeadActorError] if Bootstrap Manager has not been started
|
6
|
+
#
|
7
|
+
# @return [Celluloid::Actor(Bootstrap::Manager)]
|
8
|
+
def instance
|
9
|
+
MB::Application[:bootstrap_manager] or raise Celluloid::DeadActorError, "bootstrap manager not running"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
include Celluloid
|
14
|
+
include MB::Logging
|
15
|
+
include MB::Mixin::Locks
|
16
|
+
include MB::Mixin::AttributeSetting
|
17
|
+
include MB::Mixin::Services
|
18
|
+
|
19
|
+
finalizer :finalize_callback
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
log.debug { "Bootstrap Manager starting..." }
|
23
|
+
@worker_pool = Bootstrap::Worker.pool(size: 50)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Asynchronously bootstrap a collection of nodes described in the given manifest in the proper order
|
27
|
+
#
|
28
|
+
# @param [String] environment
|
29
|
+
# name of the environment to bootstrap nodes to
|
30
|
+
# @param [Bootstrap::Manifest] manifest
|
31
|
+
# manifest of nodes and what they should become
|
32
|
+
# @param [Plugin] plugin
|
33
|
+
# a motherbrain plugin with a bootstrap routine to follow
|
34
|
+
#
|
35
|
+
# @option options [Hash] :component_versions (Hash.new)
|
36
|
+
# Hash of components and the versions to set them to
|
37
|
+
# @option options [Hash] :cookbook_versions (Hash.new)
|
38
|
+
# Hash of cookbooks and the versions to set them to
|
39
|
+
# @option options [Hash] :environment_attributes (Hash.new)
|
40
|
+
# Hash of additional attributes to set on the environment
|
41
|
+
# @option options [Boolean] :force
|
42
|
+
# ignore and bypass any existing locks on an environment
|
43
|
+
# @option options [Hash] :attributes (Hash.new)
|
44
|
+
# a hash of node level attributes to set on the bootstrapped nodes
|
45
|
+
# @option options [Array] :run_list (Array.new)
|
46
|
+
# an initial run list to bootstrap with
|
47
|
+
# @option options [String] :chef_version
|
48
|
+
# version of Chef to install on the node
|
49
|
+
# @option options [Hash] :hints (Hash.new)
|
50
|
+
# a hash of Ohai hints to place on the bootstrapped node
|
51
|
+
# @option options [Boolean] :sudo (true)
|
52
|
+
# bootstrap with sudo
|
53
|
+
# @option options [String] :bootstrap_proxy (nil)
|
54
|
+
# URL to a proxy server to bootstrap through
|
55
|
+
#
|
56
|
+
# @return [MB::JobRecord]
|
57
|
+
# a reference to the executing job
|
58
|
+
def async_bootstrap(environment, manifest, plugin, options = {})
|
59
|
+
job = Job.new(:bootstrap)
|
60
|
+
async(:bootstrap, job, environment, manifest, plugin, options)
|
61
|
+
|
62
|
+
job.ticket
|
63
|
+
end
|
64
|
+
|
65
|
+
# Bootstrap a collection of nodes described in the given manifest in the proper order
|
66
|
+
#
|
67
|
+
# @param [MB::Job] job
|
68
|
+
# a job to send progress updates to
|
69
|
+
# @param [String] environment
|
70
|
+
# name of the environment to bootstrap nodes to
|
71
|
+
# @param [MB::Bootstrap::Manifest] manifest
|
72
|
+
# manifest of nodes and what they should become
|
73
|
+
# @param [MB::Plugin] plugin
|
74
|
+
# a motherbrain plugin with a bootstrap routine to follow
|
75
|
+
#
|
76
|
+
# @see {#async_bootstrap} for options
|
77
|
+
def bootstrap(job, environment, manifest, plugin, options = {})
|
78
|
+
options = options.reverse_merge(
|
79
|
+
cookbook_versions: Hash.new,
|
80
|
+
component_versions: Hash.new,
|
81
|
+
environment_attributes: Hash.new,
|
82
|
+
hints: Hash.new,
|
83
|
+
bootstrap_proxy: Application.config[:chef][:bootstrap_proxy],
|
84
|
+
sudo: Application.config[:ssh][:sudo],
|
85
|
+
force: false
|
86
|
+
)
|
87
|
+
options[:environment] = environment
|
88
|
+
|
89
|
+
job.report_running
|
90
|
+
|
91
|
+
validate_bootstrap_configuration!(manifest, plugin)
|
92
|
+
|
93
|
+
job.set_status("Searching for environment")
|
94
|
+
unless chef_connection.environment.find(environment)
|
95
|
+
return job.report_failure("Environment '#{environment}' not found")
|
96
|
+
end
|
97
|
+
|
98
|
+
job.set_status("Starting bootstrap of nodes on: #{environment}")
|
99
|
+
task_queue = plugin.bootstrap_routine.task_queue.dup
|
100
|
+
|
101
|
+
chef_synchronize(chef_environment: environment, force: options[:force], job: job) do
|
102
|
+
if options[:component_versions].any?
|
103
|
+
job.set_status("Setting component versions")
|
104
|
+
set_component_versions(environment, plugin, options[:component_versions])
|
105
|
+
end
|
106
|
+
|
107
|
+
if options[:cookbook_versions].any?
|
108
|
+
job.set_status("Setting cookbook versions")
|
109
|
+
set_cookbook_versions(environment, options[:cookbook_versions])
|
110
|
+
end
|
111
|
+
|
112
|
+
if options[:environment_attributes].any?
|
113
|
+
job.set_status("Setting environment attributes")
|
114
|
+
set_environment_attributes(environment, options[:environment_attributes])
|
115
|
+
end
|
116
|
+
|
117
|
+
unless options[:environment_attributes_file].nil?
|
118
|
+
job.set_status("Setting environment attributes from file")
|
119
|
+
set_environment_attributes_from_file(environment, options[:environment_attributes_file])
|
120
|
+
end
|
121
|
+
|
122
|
+
while tasks = task_queue.shift
|
123
|
+
host_errors = Hash.new
|
124
|
+
group_names = Array(tasks).collect(&:group_name).join(', ')
|
125
|
+
|
126
|
+
instructions = Bootstrap::Routine.map_instructions(tasks, manifest)
|
127
|
+
if instructions.empty?
|
128
|
+
log.info "Skipping bootstrap of group(s): #{group_names}. No hosts defined in manifest to bootstrap for " +
|
129
|
+
"these groups."
|
130
|
+
next
|
131
|
+
end
|
132
|
+
|
133
|
+
job.set_status("Bootstrapping group(s): #{group_names}")
|
134
|
+
|
135
|
+
concurrent_bootstrap(job, manifest, instructions, options).each do |host, host_info|
|
136
|
+
if host_info[:result][:status] == :error
|
137
|
+
host_errors[host] = host_info
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
unless host_errors.empty?
|
142
|
+
abort GroupBootstrapError.new(host_errors)
|
143
|
+
end
|
144
|
+
|
145
|
+
job.set_status("Finished bootstrapping group(s): #{group_names}")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
job.report_success
|
150
|
+
rescue => ex
|
151
|
+
job.report_failure(ex)
|
152
|
+
ensure
|
153
|
+
job.terminate if job && job.alive?
|
154
|
+
end
|
155
|
+
|
156
|
+
# Concurrently bootstrap a grouped collection of nodes from a manifest and return
|
157
|
+
# their results. This function will block until all nodes have finished
|
158
|
+
# bootstrapping.
|
159
|
+
#
|
160
|
+
# @param [MB::Job] job
|
161
|
+
# a job to send progress updates to
|
162
|
+
# @param [Bootstrap::Manifest] manifest
|
163
|
+
# a hash where the keys are node group names and the values are arrays of hostnames
|
164
|
+
# @param [Hash] instructions
|
165
|
+
# a hash containing an entry for every host to bootstrap and the groups it belongs to, the
|
166
|
+
# run list it should be bootstrapped with, and the chef attributes to be applied to the node
|
167
|
+
# for it's first run.
|
168
|
+
#
|
169
|
+
# @option options [Hash] :attributes (Hash.new)
|
170
|
+
# a hash of attributes to use in the first Chef run
|
171
|
+
# @option options [Array] :run_list (Array.new)
|
172
|
+
# an initial run list to bootstrap with
|
173
|
+
# @option options [String] :chef_version
|
174
|
+
# version of Chef to install on the node
|
175
|
+
# @option options [Hash] :hints (Hash.new)
|
176
|
+
# a hash of Ohai hints to place on the bootstrapped node
|
177
|
+
# @option options [Boolean] :sudo (true)
|
178
|
+
# bootstrap with sudo
|
179
|
+
# @option options [String] :bootstrap_proxy (nil)
|
180
|
+
# URL to a proxy server to bootstrap through
|
181
|
+
#
|
182
|
+
# @return [Hash]
|
183
|
+
# a hash where keys are group names and their values are the results of {Bootstrap::Worker#run}
|
184
|
+
#
|
185
|
+
# @example
|
186
|
+
# {
|
187
|
+
# "cloud-1.riotgames.com" => {
|
188
|
+
# groups: ["proxy_server::default", "app_server::default"],
|
189
|
+
# result: {
|
190
|
+
# status: :ok,
|
191
|
+
# message: "",
|
192
|
+
# bootstrap_type: :full
|
193
|
+
# }
|
194
|
+
# },
|
195
|
+
# "cloud-2.riotgames.com" => {
|
196
|
+
# groups: ["database_master::default"],
|
197
|
+
# result: {
|
198
|
+
# status: :error,
|
199
|
+
# message: "client verification error"
|
200
|
+
# bootstrap_type: :partial
|
201
|
+
# }
|
202
|
+
# },
|
203
|
+
# "cloud-3.riotgames.com" => {
|
204
|
+
# groups: ["database_slave::default"],
|
205
|
+
# result: {
|
206
|
+
# status: :ok
|
207
|
+
# message: ""
|
208
|
+
# bootstrap_type: :partial
|
209
|
+
# }
|
210
|
+
# }
|
211
|
+
# }
|
212
|
+
def concurrent_bootstrap(job, manifest, instructions, options = {})
|
213
|
+
response = Hash.new
|
214
|
+
|
215
|
+
instructions.each do |host, host_info|
|
216
|
+
boot_options = options.merge(host_info[:options])
|
217
|
+
boot_options.merge!(manifest[:options]) if manifest[:options]
|
218
|
+
|
219
|
+
job.set_status("Bootstrapping #{host} with group(s): #{host_info[:groups]}")
|
220
|
+
|
221
|
+
response[host] = {
|
222
|
+
groups: host_info[:groups],
|
223
|
+
result: worker_pool.future(:run, host, boot_options)
|
224
|
+
}
|
225
|
+
end
|
226
|
+
|
227
|
+
response.each { |host, host_info| host_info[:result] = host_info[:result].value }
|
228
|
+
end
|
229
|
+
|
230
|
+
private
|
231
|
+
|
232
|
+
attr_reader :worker_pool
|
233
|
+
|
234
|
+
def finalize_callback
|
235
|
+
log.debug { "Bootstrap Manager stopping..." }
|
236
|
+
worker_pool.terminate if worker_pool && worker_pool.alive?
|
237
|
+
end
|
238
|
+
|
239
|
+
def validate_bootstrap_configuration!(manifest, plugin)
|
240
|
+
manifest.validate!(plugin)
|
241
|
+
|
242
|
+
validator_path = File.expand_path(config_manager.config.chef[:validator_path])
|
243
|
+
|
244
|
+
unless File.exists?(validator_path)
|
245
|
+
raise ValidatorPemNotFound.new(validator_path)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module MotherBrain
|
2
|
+
module Bootstrap
|
3
|
+
# Manifest for bootstrapping a collection of nodes as a specified node group
|
4
|
+
#
|
5
|
+
# @example valid manifest structure
|
6
|
+
# {
|
7
|
+
# "nodes": [
|
8
|
+
# {
|
9
|
+
# "groups": ["activemq::master"],
|
10
|
+
# "hosts": [
|
11
|
+
# "euca-10-20-37-171.eucalyptus.cloud.riotgames.com",
|
12
|
+
# "euca-10-20-37-172.eucalyptus.cloud.riotgames.com"
|
13
|
+
# ]
|
14
|
+
# },
|
15
|
+
# {
|
16
|
+
# "groups": ["activemq::slave"],
|
17
|
+
# "hosts": [
|
18
|
+
# "euca-10-20-37-168.eucalyptus.cloud.riotgames.com"
|
19
|
+
# ]
|
20
|
+
# }
|
21
|
+
# ]
|
22
|
+
# }
|
23
|
+
#
|
24
|
+
class Manifest < MotherBrain::Manifest
|
25
|
+
class << self
|
26
|
+
# Create a new instance of {Bootstrap::Manifest} from the returning
|
27
|
+
# value from calling {MotherBrain::Provisioner#up} on a provisioner and
|
28
|
+
# the provision manifest sent to {MotherBrain::Provisioner#up}.
|
29
|
+
#
|
30
|
+
# @param [Hash] nodes
|
31
|
+
# the result from calling {MotherBrain::Provisioner#up}
|
32
|
+
# @param [Provisioner::Manifest] provisioner_manifest
|
33
|
+
# the manifest sent to the provisioner performing
|
34
|
+
# {MotherBrain::Provisioner#up}
|
35
|
+
#
|
36
|
+
# @return [Bootstrap::Manifest]
|
37
|
+
def from_provisioner(nodes, provisioner_manifest, path = nil)
|
38
|
+
nodes = nodes.dup
|
39
|
+
attributes = provisioner_manifest.dup
|
40
|
+
|
41
|
+
new.tap do |boot_manifest|
|
42
|
+
boot_manifest.path = path
|
43
|
+
boot_manifest[:nodes] = Array.new
|
44
|
+
boot_manifest[:options] = provisioner_manifest[:options]
|
45
|
+
|
46
|
+
attributes.node_groups.each do |node_group|
|
47
|
+
instance_type = node_group[:type]
|
48
|
+
count = node_group[:count] || 1
|
49
|
+
groups = node_group[:groups]
|
50
|
+
hosts = Set.new
|
51
|
+
|
52
|
+
used_instances = nodes.select { |node|
|
53
|
+
node[:instance_type] == instance_type
|
54
|
+
}.take(count)
|
55
|
+
|
56
|
+
used_instances.each do |used_instance|
|
57
|
+
hosts.add(used_instance[:public_hostname])
|
58
|
+
nodes.delete(used_instance)
|
59
|
+
end
|
60
|
+
|
61
|
+
boot_manifest[:nodes] << {
|
62
|
+
groups: groups,
|
63
|
+
hosts: hosts.to_a
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Validates that the instance of manifest describes a layout for the given routine
|
70
|
+
#
|
71
|
+
# @param [Bootstrap::Manifest] manifest
|
72
|
+
# @param [Plugin] plugin
|
73
|
+
#
|
74
|
+
# @raise [InvalidBootstrapManifest]
|
75
|
+
# @raise [NoBootstrapRoutine]
|
76
|
+
def validate!(manifest, plugin)
|
77
|
+
unless plugin.bootstrap_routine
|
78
|
+
raise NoBootstrapRoutine,
|
79
|
+
"Plugin '#{plugin.name}' (#{plugin.version}) does not contain a bootstrap routine"
|
80
|
+
end
|
81
|
+
|
82
|
+
unless manifest[:nodes].is_a?(Array)
|
83
|
+
msg = "Manifest should contain an array of nodes"
|
84
|
+
raise InvalidBootstrapManifest, msg
|
85
|
+
end
|
86
|
+
|
87
|
+
manifest.node_groups.each do |node_group|
|
88
|
+
groups = node_group[:groups]
|
89
|
+
|
90
|
+
groups.each do |group|
|
91
|
+
match = group.match(Plugin::NODE_GROUP_ID_REGX)
|
92
|
+
|
93
|
+
unless match
|
94
|
+
msg = "Manifest contained the entry: '#{group}' which is not"
|
95
|
+
msg << " in the proper node group format: 'component::group'"
|
96
|
+
raise InvalidBootstrapManifest, msg
|
97
|
+
end
|
98
|
+
|
99
|
+
unless plugin.bootstrap_routine.has_task?(group)
|
100
|
+
msg = "Manifest describes the node group '#{group}' which is not found"
|
101
|
+
msg << " in the given routine for '#{plugin}'"
|
102
|
+
raise InvalidBootstrapManifest, msg
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Finds all hosts to be bootstrapped with a set of groups
|
110
|
+
#
|
111
|
+
# @return [Array] of hosts
|
112
|
+
def hosts_for_group(group)
|
113
|
+
hosts = node_groups.select do |node_group|
|
114
|
+
node_group[:groups].include?(group)
|
115
|
+
end.collect { |node_group| node_group[:hosts] }.flatten
|
116
|
+
|
117
|
+
MB::NodeFilter.expand_ipranges(hosts)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Validates that the instance of manifest describes a layout for the given routine
|
121
|
+
#
|
122
|
+
# @param [Plugin] plugin
|
123
|
+
#
|
124
|
+
# @raise [InvalidBootstrapManifest]
|
125
|
+
# @raise [NoBootstrapRoutine]
|
126
|
+
def validate!(plugin)
|
127
|
+
self.class.validate!(self, plugin)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
module MotherBrain
|
2
|
+
module Bootstrap
|
3
|
+
class Routine
|
4
|
+
# Container for a bootstrap task defined in a bootstrap routine
|
5
|
+
#
|
6
|
+
# @api private
|
7
|
+
class Task
|
8
|
+
class << self
|
9
|
+
# Create a new bootstrap routine task from a group path
|
10
|
+
#
|
11
|
+
# @param [MB::Plugin] plugin
|
12
|
+
# the plugin to find the group in
|
13
|
+
# @param [#to_s] group_path
|
14
|
+
# a string representing the path to a group in a component ("nginx::master")
|
15
|
+
#
|
16
|
+
# @raise [MB::PluginSyntaxError] if the group or component is not found on the plugin
|
17
|
+
#
|
18
|
+
# @return [Routine::Task]
|
19
|
+
def from_group_path(plugin, group_path)
|
20
|
+
component_id, group_id = group_path.to_s.split('::')
|
21
|
+
group = plugin.component!(component_id).group!(group_id)
|
22
|
+
from_group(group_path, group)
|
23
|
+
rescue ComponentNotFound, GroupNotFound => ex
|
24
|
+
raise PluginSyntaxError, ex
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param [#to_s] group_path
|
28
|
+
# a string representing the path to a group in a component ("nginx::master")
|
29
|
+
# @param [MB::Group] group
|
30
|
+
#
|
31
|
+
# @return [Routine::Task]
|
32
|
+
def from_group(group_path, group)
|
33
|
+
new(group_path, run_list: group.run_list, chef_attributes: group.chef_attributes)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [String]
|
38
|
+
attr_reader :group_name
|
39
|
+
# @return [Array]
|
40
|
+
attr_reader :run_list
|
41
|
+
# @return [Hashie::Mash]
|
42
|
+
attr_reader :chef_attributes
|
43
|
+
|
44
|
+
# @param [String] group_name
|
45
|
+
def initialize(group_name, options = {})
|
46
|
+
@group_name = group_name
|
47
|
+
@run_list = options[:run_list] || Array.new
|
48
|
+
@chef_attributes = options[:chef_attributes] || Hashie::Mash.new
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class << self
|
53
|
+
# Takes a task, or array of tasks, and a Bootstrap::Manifest and returns a Hash containing instructions
|
54
|
+
# for how to bootstrap each node found in the manifest based on the set of tasks, or task, given.
|
55
|
+
#
|
56
|
+
# @param [Bootstrap::Routine::Task, Array<Bootstrap::Routine::Task>] tasks
|
57
|
+
# @param [Bootstrap::Manifest] manifest
|
58
|
+
#
|
59
|
+
# @return [Hash]
|
60
|
+
# A hash containing an entry for every host to bootstrap and the groups it belongs to, the
|
61
|
+
# run list it should be bootstrapped with, and the chef attributes to be applied to the node
|
62
|
+
# for it's first run.
|
63
|
+
#
|
64
|
+
# {
|
65
|
+
# "euca-10-20-37-171.eucalyptus.cloud.riotgames.com" => {
|
66
|
+
# groups: [ "app_server::default" ],
|
67
|
+
# options: {
|
68
|
+
# run_list: Array.new,
|
69
|
+
# chef_attributes: Hashie::Hash.new
|
70
|
+
# }
|
71
|
+
# },
|
72
|
+
# "euca-10-20-37-172.eucalyptus.cloud.riotgames.com" => {
|
73
|
+
# groups: [ "app_server::default", "database_slave::default" ],
|
74
|
+
# options: {
|
75
|
+
# run_list: Array.new,
|
76
|
+
# chef_attributes: Hashie::Hash.new
|
77
|
+
# }
|
78
|
+
# },
|
79
|
+
# "euca-10-20-37-168.eucalyptus.cloud.riotgames.com" => {
|
80
|
+
# groups: [ "database_master::default" ],
|
81
|
+
# options: {
|
82
|
+
# run_list: Array.new,
|
83
|
+
# chef_attributes: Hashie::Hash.new
|
84
|
+
# }
|
85
|
+
# }
|
86
|
+
# }
|
87
|
+
def map_instructions(tasks, manifest)
|
88
|
+
{}.tap do |nodes|
|
89
|
+
Array(tasks).each do |task|
|
90
|
+
manifest.hosts_for_group(task.group_name).each do |host|
|
91
|
+
nodes[host] ||= {
|
92
|
+
groups: Array.new,
|
93
|
+
options: {
|
94
|
+
run_list: Array.new,
|
95
|
+
chef_attributes: Hashie::Mash.new
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
nodes[host][:groups] << task.group_name unless nodes[host][:groups].include?(task.group_name)
|
100
|
+
nodes[host][:options][:run_list] = nodes[host][:options][:run_list] | task.run_list
|
101
|
+
nodes[host][:options][:chef_attributes] =
|
102
|
+
nodes[host][:options][:chef_attributes].deep_merge(task.chef_attributes)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# @return [MB::Plugin]
|
110
|
+
attr_reader :plugin
|
111
|
+
|
112
|
+
# @param [MB::Plugin] plugin
|
113
|
+
def initialize(plugin, &block)
|
114
|
+
@plugin = plugin
|
115
|
+
@task_procs = Array.new
|
116
|
+
|
117
|
+
if block_given?
|
118
|
+
dsl_eval(&block)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Returns an array of groups or an array of an array groups representing the order in
|
123
|
+
# which the cluster should be bootstrapped in. Groups which can be bootstrapped together
|
124
|
+
# are contained within an array. Groups should be bootstrapped starting from index 0 of
|
125
|
+
# the returned array.
|
126
|
+
#
|
127
|
+
# @return [Array<Bootstrap::Routine::Task>, Array<Array<Bootstrap::Routine::Task>>]
|
128
|
+
def task_queue
|
129
|
+
@task_queue ||= MB.expand_procs(task_procs)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Checks if the routine contains a boot task for the given node group
|
133
|
+
#
|
134
|
+
# @param [String] node_group
|
135
|
+
# name for a bootstrap task to check for
|
136
|
+
#
|
137
|
+
# @return [Boolean]
|
138
|
+
def has_task?(node_group, task_queue = self.task_queue)
|
139
|
+
task_queue.find do |task|
|
140
|
+
if task.is_a?(Array)
|
141
|
+
has_task?(node_group, task)
|
142
|
+
else
|
143
|
+
task.group_name == node_group
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
# @return [Array<Proc>]
|
151
|
+
attr_reader :task_procs
|
152
|
+
|
153
|
+
def dsl_eval(&block)
|
154
|
+
room = CleanRoom.new(self)
|
155
|
+
room.instance_eval(&block)
|
156
|
+
@task_procs = room.send(:task_procs)
|
157
|
+
end
|
158
|
+
|
159
|
+
# @api private
|
160
|
+
class CleanRoom < CleanRoomBase
|
161
|
+
# Add a Bootstrap::Routine::Task for bootstrapping nodes in the given node group to the {Routine}
|
162
|
+
#
|
163
|
+
# @example
|
164
|
+
# Routine.new(...) do
|
165
|
+
# bootstrap("mysql::master")
|
166
|
+
# end
|
167
|
+
#
|
168
|
+
# @param [String] group_path
|
169
|
+
# a group path
|
170
|
+
def bootstrap(group_path)
|
171
|
+
self.task_procs.push -> { Task.from_group_path(real_model.plugin, group_path) }
|
172
|
+
end
|
173
|
+
|
174
|
+
# Add an array of Bootstrap::Routine::Task(s) to be executed asyncronously to the {Routine}
|
175
|
+
#
|
176
|
+
# @example
|
177
|
+
# Routine.new(...) do
|
178
|
+
# async do
|
179
|
+
# bootstrap("mysql::master")
|
180
|
+
# bootstrap("myapp::webserver")
|
181
|
+
# end
|
182
|
+
# end
|
183
|
+
def async(&block)
|
184
|
+
room = self.class.new(real_model)
|
185
|
+
room.instance_eval(&block)
|
186
|
+
|
187
|
+
self.task_procs.push room.task_procs
|
188
|
+
end
|
189
|
+
|
190
|
+
protected
|
191
|
+
|
192
|
+
# @return [Array<Proc>]
|
193
|
+
def task_procs
|
194
|
+
@task_procs ||= Array.new
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|