Class: Orca::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/orca/runner.rb

Defined Under Namespace

Classes: ValidationFailureError

Instance Method Summary collapse

Constructor Details

#initialize(node, package, skip_dependancies = false) ⇒ Runner

Returns a new instance of Runner.



2
3
4
5
6
7
# File 'lib/orca/runner.rb', line 2

def initialize(node, package, skip_dependancies=false)
  @node = node
  @package = package
  @perform = true
  @skip_dependancies = skip_dependancies
end

Instance Method Details

#demonstrate(command_name) ⇒ Object



60
61
62
63
64
# File 'lib/orca/runner.rb', line 60

def demonstrate(command_name)
  @perform = false
  execute(command_name)
  @perform = true
end

#exec(pkg, command_name) ⇒ Object



66
67
68
69
70
71
# File 'lib/orca/runner.rb', line 66

def exec(pkg, command_name)
  @node.log pkg.name, command_name.to_s.yellow
  context = @perform ? Orca::ExecutionContext.new(@node) : Orca::MockExecutionContext.new(@node)
  cmds = pkg.command(command_name)
  cmds.map {|cmd| context.apply(cmd) }
end

#execute(command_name) ⇒ Object



16
17
18
19
20
21
# File 'lib/orca/runner.rb', line 16

def execute(command_name)
  @node.log command_name, packages.map(&:name).join(', ').yellow
  packages.each do |pkg|
    send(:"execute_#{command_name}", pkg)
  end
end

#execute_apply(pkg) ⇒ Object



23
24
25
26
27
# File 'lib/orca/runner.rb', line 23

def execute_apply(pkg)
  return unless should_run?(pkg, :apply)
  exec(pkg, :apply)
  validate!(pkg)
end

#execute_remove(pkg) ⇒ Object



29
30
31
32
# File 'lib/orca/runner.rb', line 29

def execute_remove(pkg)
  return unless should_run?(pkg, :remove)
  exec(pkg, :remove)
end

#execute_validate(pkg) ⇒ Object



34
35
36
# File 'lib/orca/runner.rb', line 34

def execute_validate(pkg)
  validate!(pkg)
end

#is_valid?(pkg) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/orca/runner.rb', line 55

def is_valid?(pkg)
  results = exec(pkg, :validate)
  results.all?
end

#packagesObject



9
10
11
12
13
14
# File 'lib/orca/runner.rb', line 9

def packages
  return [@package] if @skip_dependancies
  resolver = Orca::Resolver.new(@package)
  resolver.resolve
  resolver.packages
end

#should_run?(pkg, command_name) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
# File 'lib/orca/runner.rb', line 38

def should_run?(pkg, command_name)
  return false unless pkg.provides_command?(command_name)
  return true unless @perform
  return true unless command_name == :apply || command_name == :remove
  return true unless pkg.provides_command?(:validate)
  is_present = is_valid?(pkg)
  return !is_present if command_name == :apply
  return is_present
end

#validate!(pkg) ⇒ Object



48
49
50
51
52
53
# File 'lib/orca/runner.rb', line 48

def validate!(pkg)
  return true unless @perform
  return unless pkg.provides_command?(:validate)
  return if is_valid?(pkg)
  raise ValidationFailureError.new(@node, pkg)
end