Class: CM::Plugin::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/core/plugin/batch.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_idsObject



6
7
8
# File 'lib/core/plugin/batch.rb', line 6

def self.register_ids
  [ :id ]
end

Instance Method Details

#execute(operation) ⇒ Object


Operations



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/core/plugin/batch.rb', line 82

def execute(operation)
  if initialized?
    myself.status = code.success

    if Nucleon.parallel?
      success = execute_parallel(operation)
    else
      success = execute_sequence(operation)
    end
  else
    success = false
  end
  myself.status = code.batch_failed unless success
  success
end

#execute_parallel(operation) ⇒ Object


Utilities



101
102
103
# File 'lib/core/plugin/batch.rb', line 101

def execute_parallel(operation)
  false # Override me!!
end

#execute_sequence(operation) ⇒ Object




107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/core/plugin/batch.rb', line 107

def execute_sequence(operation)
  success = true
  resources.each do |resource|
    resource.execute(operation)
    success = false unless resource.status == code.success

    myself.quit = resource.quit ||
      ((resource.plugin_type != :sequence || resource.plugin_provider != :variables) &&
      plan.trap && plan.step)
    break if quit
  end
  success
end

#idObject




65
66
67
# File 'lib/core/plugin/batch.rb', line 65

def id
  get(:id).to_sym
end

#init_resourcesObject




26
27
28
29
30
31
32
33
34
35
36
# File 'lib/core/plugin/batch.rb', line 26

def init_resources
  @resources = []
  get_array(:resources).each do |resource_config|
    if resource_config.has_key?(:sequence) # Array
      @resources << plan.create_sequence(resource_config[:sequence])
    else # Atomic
      @resources << plan.create_resource(resource_config)
    end
  end
  @resources
end

#initialized?(options = {}) ⇒ Boolean


Checks

Returns:

  • (Boolean)


41
42
43
# File 'lib/core/plugin/batch.rb', line 41

def initialized?(options = {})
  true
end

#normalize(reload) ⇒ Object


Plugin interface



13
14
15
16
17
18
19
20
21
22
# File 'lib/core/plugin/batch.rb', line 13

def normalize(reload)
  super

  codes :batch_failed

  @plan = delete(:plan, nil) unless reload

  init_resources
  yield if block_given?
end

#planObject


Property accessors / modifiers



48
49
50
# File 'lib/core/plugin/batch.rb', line 48

def plan
  @plan
end

#quitObject




71
72
73
# File 'lib/core/plugin/batch.rb', line 71

def quit
  @quit
end

#quit=(quit) ⇒ Object



75
76
77
# File 'lib/core/plugin/batch.rb', line 75

def quit=quit
  @quit = quit
end

#resourcesObject




54
55
56
# File 'lib/core/plugin/batch.rb', line 54

def resources
  @resources
end

#resources=(resources) ⇒ Object



58
59
60
61
# File 'lib/core/plugin/batch.rb', line 58

def resources=resources
  set(:resources, array(resources))
  init_resources
end