class MotherBrain::Bootstrap::Routine

Attributes

plugin[R]

@return [MB::Plugin]

task_procs[R]

@return [Array<Proc>]

Public Class Methods

map_instructions(tasks, manifest) click to toggle source

Takes a task, or array of tasks, and a Bootstrap::Manifest and returns a Hash containing instructions for how to bootstrap each node found in the manifest based on the set of tasks, or task, given.

@param [Bootstrap::Routine::Task, Array<Bootstrap::Routine::Task>] tasks @param [Bootstrap::Manifest] manifest

@return [Hash]

A hash containing an entry for every host to bootstrap and the groups it belongs to, the
run list it should be bootstrapped with, and the chef attributes to be applied to the node
for it's first run.

{
  "euca-10-20-37-171.eucalyptus.cloud.riotgames.com" => {
    groups: [ "app_server::default" ],
    options: {
      run_list: Array.new,
      chef_attributes: Hashie::Hash.new
    }
  },
  "euca-10-20-37-172.eucalyptus.cloud.riotgames.com" => {
    groups: [ "app_server::default", "database_slave::default" ],
    options: {
      run_list: Array.new,
      chef_attributes: Hashie::Hash.new
    }
  },
  "euca-10-20-37-168.eucalyptus.cloud.riotgames.com" => {
    groups: [ "database_master::default" ],
    options: {
      run_list: Array.new,
      chef_attributes: Hashie::Hash.new
    }
  }
}
# File lib/mb/bootstrap/routine.rb, line 87
def map_instructions(tasks, manifest)
  {}.tap do |nodes|
    Array(tasks).each do |task|
      manifest.hosts_for_group(task.group_name).each do |host|
        nodes[host] ||= {
          groups: Array.new,
          options: {
            run_list: Array.new,
            chef_attributes: Hashie::Mash.new
          }
        }

        nodes[host][:groups] << task.group_name unless nodes[host][:groups].include?(task.group_name)
        nodes[host][:options][:run_list]        = nodes[host][:options][:run_list] | task.run_list
        nodes[host][:options][:chef_attributes] =
          nodes[host][:options][:chef_attributes].deep_merge(task.chef_attributes)
      end
    end
  end
end
new(plugin, &block) click to toggle source

@param [MB::Plugin] plugin

# File lib/mb/bootstrap/routine.rb, line 113
def initialize(plugin, &block)
  @plugin     = plugin
  @task_procs = Array.new

  if block_given?
    dsl_eval(&block)
  end
end

Public Instance Methods

has_task?(node_group, task_queue = self.task_queue) click to toggle source

Checks if the routine contains a boot task for the given node group

@param [String] node_group

name for a bootstrap task to check for

@return [Boolean]

# File lib/mb/bootstrap/routine.rb, line 138
def has_task?(node_group, task_queue = self.task_queue)
  task_queue.find do |task|
    if task.is_a?(Array)
      has_task?(node_group, task)
    else
      task.group_name == node_group
    end
  end
end
task_queue() click to toggle source

Returns an array of groups or an array of an array groups representing the order in which the cluster should be bootstrapped in. Groups which can be bootstrapped together are contained within an array. Groups should be bootstrapped starting from index 0 of the returned array.

@return [Array<Bootstrap::Routine::Task>, Array<Array<Bootstrap::Routine::Task>>]

# File lib/mb/bootstrap/routine.rb, line 128
def task_queue
  @task_queue ||= MB.expand_procs(task_procs)
end

Private Instance Methods

dsl_eval(&block) click to toggle source
# File lib/mb/bootstrap/routine.rb, line 153
def dsl_eval(&block)
  room = CleanRoom.new(self)
  room.instance_eval(&block)
  @task_procs = room.send(:task_procs)
end