class Souffle::Provisioner::System

The system provisioning statemachine.

Attributes

max_failures[R]
provider[RW]
time_used[RW]

Public Class Methods

new(system, provider, max_failures=3, timeout=600) click to toggle source

Creates a new system using a specific provider.

@param [ Souffle::System ] system The system to provision. @param [ Souffle::Provider::Base ] provider The provider to use. @param [ Fixnum ] max_failures the maximum number of failures. @param [ Fixnum ] timeout The maximum time to wait for node creation.

Calls superclass method
# File lib/souffle/provisioner/system.rb, line 55
def initialize(system, provider, max_failures=3, timeout=600)
  @failures = 0
  @system = system
  @provider = provider
  @time_used = 0
  @timeout = timeout
  @max_failures = max_failures
  @nodes_completed = 0
  super() # NOTE: This is here to initialize state_machine.
end

Public Instance Methods

create() click to toggle source

Creates the system from an api or command.

# File lib/souffle/provisioner/system.rb, line 67
def create
  Souffle::Log.info "[#{system_tag}] Creating a new system..."
  @system.nodes.each do |node|
    node.provisioner = Souffle::Provisioner::Node.new(node)
    node.provisioner.initialized
  end
  wait_until_created
end
error_handler() click to toggle source

Handles the error state and recreates the system.

# File lib/souffle/provisioner/system.rb, line 135
def error_handler
  @failures += 1
  if @failures >= @max_failures
    Souffle::Log.error "[#{system_tag}] Complete failure. Halting Creation."
    creation_halted
  else
    err_msg =  "[#{system_tag}] Error creating system. "
    err_msg << "Killing and recreating..."
    Souffle::Log.error(err_msg)
    kill_system
    reclaimed
  end
end
kill_system() click to toggle source

Kills the system.

# File lib/souffle/provisioner/system.rb, line 130
def kill_system
  # @provider.kill(@system.nodes)
end
node_provisioned() click to toggle source

Updates the number of nodes provisioned for the system provisioner.

# File lib/souffle/provisioner/system.rb, line 124
def node_provisioned
  @nodes_completed += 1
  provisioned if @nodes_completed == @system.nodes.size
end
provision() click to toggle source

Provisioning the system.

@todo We should really have these provisioned with fibers.

# File lib/souffle/provisioner/system.rb, line 79
def provision
  Souffle::Log.info "[#{system_tag}] Provisioning the system..."
  @system.rebalance_nodes
  @system.nodes.each do |node|
    when_parents_are_complete(node) { node.provisioner.begin_provision }
  end
  wait_until_complete
end
system_provisioned() click to toggle source

System has completed provisioning.

# File lib/souffle/provisioner/system.rb, line 119
def system_provisioned
  Souffle::Log.info "[#{system_tag}] System provisioned."
end
when_parents_are_complete(node) { || ... } click to toggle source

Wait until all of the parent nodes are in a completed state and yield.

# File lib/souffle/provisioner/system.rb, line 89
def when_parents_are_complete(node)
  total_nodes = node.parents.size
  if total_nodes == 0
    yield if block_given?
    all_complete = true
  else
    all_complete = false
  end
  timer = EM::PeriodicTimer.new(2) do
    nodes_complete = node.parents.select do |n|
      n.provisioner.state == "complete"
    end.size

    if nodes_complete == total_nodes
      all_complete = true
      timer.cancel
      yield if block_given?
    end
  end

  EM::Timer.new(@timeout) do
    unless all_complete
      Souffle::Log.error "[#{system_tag}] Parent creation timeout reached."
      timer.cancel
      error_occurred
    end
  end
end

Private Instance Methods

system_tag() click to toggle source

Helper function for the system tag.

@param [ String ] The system or global tag.

# File lib/souffle/provisioner/system.rb, line 154
def system_tag
  @system.try_opt(:tag)
end
wait_until_complete() click to toggle source

Wait until all of the nodes are provisioned and then continue.

# File lib/souffle/provisioner/system.rb, line 184
def wait_until_complete
  EM::Timer.new(@timeout) do
    unless @nodes_completed == @system.nodes.size
      Souffle::Log.error "[#{system_tag}] System provision timeout reached."
      error_occurred
    end
  end
end
wait_until_created() click to toggle source

Wait until all of the nodes are ready to be provisioned and then continue.

# File lib/souffle/provisioner/system.rb, line 159
def wait_until_created
  total_nodes = @system.nodes.size
  all_created = false
  timer = EM::PeriodicTimer.new(2) do
    nodes_ready = @system.nodes.select do |n|
      n.provisioner.state == "ready_to_provision"
    end.size

    if nodes_ready == total_nodes
      all_created = true
      timer.cancel
      created
    end
  end

  EM::Timer.new(@timeout) do
    unless all_created
      Souffle::Log.error "[#{system_tag}] System creation timeout reached."
      timer.cancel
      error_occurred
    end
  end
end