Class: Percheron::Stack
- Inherits:
-
Object
- Object
- Percheron::Stack
- Extended by:
- Forwardable
- Defined in:
- lib/percheron/stack.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build!(unit_names: [], usecache: true, forcerm: false) ⇒ Object
- #create!(unit_names: [], build: true, start: false, deep: false, force: false) ⇒ Object
- #execute!(klass, unit_names, args = nil) ⇒ Object
- #graph!(file) ⇒ Object
-
#initialize(config, stack_name) ⇒ Stack
constructor
A new instance of Stack.
- #logs!(unit_name, follow: false) ⇒ Object
- #metastore_key ⇒ Object
- #purge!(unit_names: [], force: false) ⇒ Object
- #restart!(unit_names: []) ⇒ Object
- #shell!(unit_name, raw_command: Percheron::Actions::Shell::DEFAULT_COMMAND) ⇒ Object
- #start!(unit_names: []) ⇒ Object
- #stop!(unit_names: []) ⇒ Object
- #unit_configs ⇒ Object
- #units(unit_names = []) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(config, stack_name) ⇒ Stack
Returns a new instance of Stack.
9 10 11 12 13 |
# File 'lib/percheron/stack.rb', line 9 def initialize(config, stack_name) @config = config @stack_name = stack_name self end |
Class Method Details
.get(config, name = nil) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/percheron/stack.rb', line 15 def self.get(config, name = nil) stacks = name.nil? ? config.stacks : { name => config.stacks[name] } stacks.each_with_object({}) do |stack_config, all| stack_name = stack_config.shift stack = new(config, stack_name) all[stack.name] = stack end end |
Instance Method Details
#build!(unit_names: [], usecache: true, forcerm: false) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/percheron/stack.rb', line 72 def build!(unit_names: [], usecache: true, forcerm: false) unit_names = stack_units.keys if unit_names.empty? unit_names = needed_units_for(unit_names) exec_on_needed_units_for(unit_names) do |unit| Actions::Build.new(unit, usecache: usecache, forcerm: forcerm).execute! end nil end |
#create!(unit_names: [], build: true, start: false, deep: false, force: false) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/percheron/stack.rb', line 81 def create!(unit_names: [], build: true, start: false, deep: false, force: false) opts = { build: build, start: start, force: force } unit_names = if deep unit_names = stack_units.keys if unit_names.empty? needed_units_for(unit_names) else filter_unit_names(unit_names) end execute!(Actions::Create, unit_names, opts) end |
#execute!(klass, unit_names, args = nil) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/percheron/stack.rb', line 97 def execute!(klass, unit_names, args=nil) exec_on_needed_units_for(unit_names) do |unit| args ? klass.new(unit, args).execute! : klass.new(unit).execute! end nil end |
#graph!(file) ⇒ Object
39 40 41 42 |
# File 'lib/percheron/stack.rb', line 39 def graph!(file) Graph.new(self).save!(file) $logger.info "Saved '%s'" % [ file ] end |
#logs!(unit_name, follow: false) ⇒ Object
48 49 50 |
# File 'lib/percheron/stack.rb', line 48 def logs!(unit_name, follow: false) Actions::Logs.new(unit_from_name(unit_name), follow: follow).execute! end |
#metastore_key ⇒ Object
24 25 26 |
# File 'lib/percheron/stack.rb', line 24 def @metastore_key ||= 'stacks.%s' % [ name ] end |
#purge!(unit_names: [], force: false) ⇒ Object
92 93 94 95 |
# File 'lib/percheron/stack.rb', line 92 def purge!(unit_names: [], force: false) unit_names = stack_units.keys if unit_names.empty? execute!(Actions::Purge, filter_unit_names(unit_names).reverse, force: force) end |
#restart!(unit_names: []) ⇒ Object
67 68 69 70 |
# File 'lib/percheron/stack.rb', line 67 def restart!(unit_names: []) unit_names = stack_units.keys if unit_names.empty? execute!(Actions::Restart, filter_unit_names(unit_names)) end |
#shell!(unit_name, raw_command: Percheron::Actions::Shell::DEFAULT_COMMAND) ⇒ Object
44 45 46 |
# File 'lib/percheron/stack.rb', line 44 def shell!(unit_name, raw_command: Percheron::Actions::Shell::DEFAULT_COMMAND) Actions::Shell.new(unit_from_name(unit_name), raw_command: raw_command).execute! end |
#start!(unit_names: []) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/percheron/stack.rb', line 57 def start!(unit_names: []) unit_names = stack_units.keys if unit_names.empty? unit_names = needed_units_for(unit_names) exec_on_needed_units_for(unit_names) do |unit| needed_units = unit.startable_needed_units.values Actions::Start.new(unit, needed_units: needed_units).execute! end nil end |
#stop!(unit_names: []) ⇒ Object
52 53 54 55 |
# File 'lib/percheron/stack.rb', line 52 def stop!(unit_names: []) unit_names = stack_units.keys if unit_names.empty? execute!(Actions::Stop, filter_unit_names(unit_names).reverse) end |
#unit_configs ⇒ Object
28 29 30 |
# File 'lib/percheron/stack.rb', line 28 def unit_configs stack_config.units end |
#units(unit_names = []) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/percheron/stack.rb', line 32 def units(unit_names = []) unit_names = unit_names.empty? ? stack_units.keys : unit_names unit_names.each_with_object({}) do |unit_name, all| all[unit_name] = unit_from_name(unit_name) end end |
#valid? ⇒ Boolean
104 105 106 |
# File 'lib/percheron/stack.rb', line 104 def valid? Validators::Stack.new(self).valid? end |