Class: Kontena::Stacks::ChangeResolver
- Inherits:
-
Object
- Object
- Kontena::Stacks::ChangeResolver
- Defined in:
- lib/kontena/stacks/change_resolver.rb
Instance Attribute Summary collapse
-
#new_data ⇒ Object
readonly
Returns the value of attribute new_data.
-
#old_data ⇒ Object
readonly
Returns the value of attribute old_data.
Instance Method Summary collapse
-
#added_services ⇒ Array<String>
An array of services that should be added.
-
#added_stacks ⇒ Array<String>
An array of stack installation names that should be removed.
- #analyze ⇒ Object
-
#initialize(old_data, new_data) ⇒ ChangeResolver
constructor
Creates a change analysis from two sets of stack data.
-
#remaining_stacks ⇒ Array<String>
An array of installed stack names that should exist after upgrade.
-
#removed_services ⇒ Array<String>
An array of services that should be removed.
-
#removed_stacks ⇒ Array<String>
An array of stack installation names that should be removed.
-
#replaced_stacks ⇒ Hash
A hash of “installed-stack-name” => { :from => ‘stackname’, :to => ‘new-stackname’ }.
- #safe? ⇒ Boolean
-
#stack_upgraded?(name) ⇒ Boolean
Stack is upgraded if version, stack name, variables change or stack is root.
-
#upgraded_services ⇒ Array<String>
An array of services that should be upgraded.
-
#upgraded_stacks ⇒ Array<String>
An array of stack installation names that should be upgraded.
Constructor Details
#initialize(old_data, new_data) ⇒ ChangeResolver
Creates a change analysis from two sets of stack data. The format is a flat hash of all related stacks.
13 14 15 16 17 |
# File 'lib/kontena/stacks/change_resolver.rb', line 13 def initialize(old_data, new_data) @old_data = old_data.is_a?(StackDataSet) ? old_data : StackDataSet.new(old_data) @new_data = new_data.is_a?(StackDataSet) ? new_data : StackDataSet.new(new_data) analyze end |
Instance Attribute Details
#new_data ⇒ Object (readonly)
Returns the value of attribute new_data.
6 7 8 |
# File 'lib/kontena/stacks/change_resolver.rb', line 6 def new_data @new_data end |
#old_data ⇒ Object (readonly)
Returns the value of attribute old_data.
6 7 8 |
# File 'lib/kontena/stacks/change_resolver.rb', line 6 def old_data @old_data end |
Instance Method Details
#added_services ⇒ Array<String>
20 21 22 |
# File 'lib/kontena/stacks/change_resolver.rb', line 20 def added_services @added_services ||= [] end |
#added_stacks ⇒ Array<String>
40 41 42 |
# File 'lib/kontena/stacks/change_resolver.rb', line 40 def added_stacks @added_stacks ||= [] end |
#analyze ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/kontena/stacks/change_resolver.rb', line 64 def analyze old_names = old_data.stack_names new_names = new_data.stack_names removed_stacks.concat(old_names - new_names) added_stacks.concat(new_names - old_names) (new_names & old_names).each do |candidate| upgraded_stacks << candidate if stack_upgraded?(candidate) end removed_stacks.each do |removed_stack| removed_services.concat( old_data.stack(removed_stack).service_names.map { |name| "#{removed_stack}/#{name}"} ) end added_stacks.each do |added_stack| added_services.concat( new_data.stack(added_stack).service_names.map { |name| "#{added_stack}/#{name}"} ) end upgraded_stacks.each do |upgraded_stack| old_stack = old_data.stack(upgraded_stack).stack_name new_stack = new_data.stack(upgraded_stack).stack_name unless old_stack == new_stack replaced_stacks[upgraded_stack] = { from: old_stack, to: new_stack } end old_services = old_data.stack(upgraded_stack).service_names.map { |name| "#{upgraded_stack}/#{name}" } new_services = new_data.stack(upgraded_stack).service_names.map { |name| "#{upgraded_stack}/#{name}" } removed_services.concat(old_services - new_services) added_services.concat(new_services - old_services) upgraded_services.concat(new_services & old_services) end end |
#remaining_stacks ⇒ Array<String>
55 56 57 |
# File 'lib/kontena/stacks/change_resolver.rb', line 55 def remaining_stacks @remaining_stacks ||= added_stacks + upgraded_stacks end |
#removed_services ⇒ Array<String>
25 26 27 |
# File 'lib/kontena/stacks/change_resolver.rb', line 25 def removed_services @removed_services ||= [] end |
#removed_stacks ⇒ Array<String>
35 36 37 |
# File 'lib/kontena/stacks/change_resolver.rb', line 35 def removed_stacks @removed_stacks ||= [] end |
#replaced_stacks ⇒ Hash
50 51 52 |
# File 'lib/kontena/stacks/change_resolver.rb', line 50 def replaced_stacks @replaced_stacks ||= {} end |
#safe? ⇒ Boolean
60 61 62 |
# File 'lib/kontena/stacks/change_resolver.rb', line 60 def safe? removed_stacks.empty? && replaced_stacks.empty? && removed_services.empty? end |
#stack_upgraded?(name) ⇒ Boolean
Stack is upgraded if version, stack name, variables change or stack is root
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/kontena/stacks/change_resolver.rb', line 107 def stack_upgraded?(name) old_stack = old_data.stack(name) new_stack = new_data.stack(name) return true if new_stack.root? return true if old_stack.version != new_stack.version return true if old_stack.stack_name != new_stack.stack_name return true if old_stack.variables != new_stack.variables false end |
#upgraded_services ⇒ Array<String>
30 31 32 |
# File 'lib/kontena/stacks/change_resolver.rb', line 30 def upgraded_services @upgraded_services ||= [] end |
#upgraded_stacks ⇒ Array<String>
45 46 47 |
# File 'lib/kontena/stacks/change_resolver.rb', line 45 def upgraded_stacks @upgraded_stacks ||= [] end |