class CfDeployer::Component

Attributes

children[R]
dependencies[R]
name[R]

Public Class Methods

new(application_name, environment_name, component_name, context) click to toggle source
# File lib/cf_deployer/component.rb, line 7
def initialize(application_name, environment_name, component_name, context)
  @application_name = application_name
  @environment_name = environment_name
  @name = component_name
  @context = context
  @dependencies = []
  @children = []
  Log.debug "initializing #{name}.."
  Log.debug @context
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/cf_deployer/component.rb, line 68
def <=>(other)
  i_am_depednent = depends_on? other
  it_is_dependent = other.depends_on? self

  if i_am_depednent
    1
  elsif it_is_dependent
    -1
  else
    0
  end
end
depends_on?(component, source=self) click to toggle source
# File lib/cf_deployer/component.rb, line 85
def depends_on?(component, source=self)
  raise ApplicationError.new("Cyclic dependency") if @dependencies.include?(source)
  @dependencies.include?(component) || @dependencies.any? { |d| d.depends_on?(component, source) }
end
deploy() click to toggle source
# File lib/cf_deployer/component.rb, line 26
def deploy
  Log.debug "deploying #{name}..."
  @dependencies.each do |parent|
    parent.deploy unless(parent.exists?)
  end
  resolve_settings
  strategy.deploy
end
destroy() click to toggle source
# File lib/cf_deployer/component.rb, line 54
def destroy
  raise ApplicationError.new("Unable to destroy #{name}, it is depended on by other components") if any_children_exist?
  strategy.destroy
end
diff() click to toggle source
# File lib/cf_deployer/component.rb, line 41
def diff
  resolve_settings
  current_json = strategy.active_template
  if current_json
    puts "#{name} json template diff:"
    new_json = ConfigLoader.erb_to_json(name, @context)
    Diffy::Diff.default_format = :color
    puts Diffy::Diff.new( current_json, new_json )
  else
    puts "No current json for component #{name}"
  end
end
exists?() click to toggle source
# File lib/cf_deployer/component.rb, line 18
def exists?
   strategy.exists?
end
inspect() click to toggle source
# File lib/cf_deployer/component.rb, line 81
def inspect
  "component: #{name}"
end
json() click to toggle source
# File lib/cf_deployer/component.rb, line 35
def json
  resolve_settings
  puts "#{name} json template:"
  puts ConfigLoader.erb_to_json(name, @context)
end
kill_inactive() click to toggle source
# File lib/cf_deployer/component.rb, line 22
def kill_inactive
  strategy.kill_inactive
end
output_value(key) click to toggle source
# File lib/cf_deployer/component.rb, line 64
def output_value(key)
  strategy.output_value(key)
end
run_hook(hook_name) click to toggle source
# File lib/cf_deployer/component.rb, line 94
def run_hook hook_name
  resolve_settings
  strategy.run_hook hook_name
end
status(get_resource_statuses) click to toggle source
# File lib/cf_deployer/component.rb, line 90
def status get_resource_statuses
  strategy.status get_resource_statuses
end
switch() click to toggle source
# File lib/cf_deployer/component.rb, line 59
def switch
  exists? ? strategy.switch : (raise ApplicationError.new("No stack exists for component: #{name}"))
end

Private Instance Methods

any_children_exist?() click to toggle source
# File lib/cf_deployer/component.rb, line 112
def any_children_exist?
  children.any?(&:exists?)
end
inputs() click to toggle source
# File lib/cf_deployer/component.rb, line 116
def inputs
  @context[:inputs]
end
resolve_settings() click to toggle source
# File lib/cf_deployer/component.rb, line 101
def resolve_settings
  inputs.each do |key, value|
    if(value.is_a?(Hash) && value.key?(:component))
      dependency = @dependencies.find { |d| d.name == value[:component] }
      raise "No component '#{value[:component]}' found when attempting to derive input '#{key}'" unless dependency
      output_key = value[:'output-key']
      inputs[key] = dependency.output_value(output_key)
    end
  end
end
strategy() click to toggle source
# File lib/cf_deployer/component.rb, line 120
def strategy
  @strategy ||= DeploymentStrategy.create(@application_name, @environment_name, name, @context)
end