Class: ManageIQ::Floe::Workflow
- Inherits:
-
Object
- Object
- ManageIQ::Floe::Workflow
- Defined in:
- lib/manageiq/floe/workflow.rb,
lib/manageiq/floe/workflow/path.rb,
lib/manageiq/floe/workflow/state.rb,
lib/manageiq/floe/workflow/runner.rb,
lib/manageiq/floe/workflow/catcher.rb,
lib/manageiq/floe/workflow/retrier.rb,
lib/manageiq/floe/workflow/states/map.rb,
lib/manageiq/floe/workflow/choice_rule.rb,
lib/manageiq/floe/workflow/states/fail.rb,
lib/manageiq/floe/workflow/states/pass.rb,
lib/manageiq/floe/workflow/states/task.rb,
lib/manageiq/floe/workflow/states/wait.rb,
lib/manageiq/floe/workflow/runner/docker.rb,
lib/manageiq/floe/workflow/runner/podman.rb,
lib/manageiq/floe/workflow/states/choice.rb,
lib/manageiq/floe/workflow/reference_path.rb,
lib/manageiq/floe/workflow/states/succeed.rb,
lib/manageiq/floe/workflow/states/parallel.rb,
lib/manageiq/floe/workflow/choice_rule/data.rb,
lib/manageiq/floe/workflow/payload_template.rb,
lib/manageiq/floe/workflow/runner/kubernetes.rb,
lib/manageiq/floe/workflow/choice_rule/boolean.rb
Defined Under Namespace
Modules: States Classes: Catcher, ChoiceRule, Path, PayloadTemplate, ReferencePath, Retrier, Runner, State
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#first_state ⇒ Object
readonly
Returns the value of attribute first_state.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#start_at ⇒ Object
readonly
Returns the value of attribute start_at.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
-
#states_by_name ⇒ Object
readonly
Returns the value of attribute states_by_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(payload, context = {}, credentials = {}) ⇒ Workflow
constructor
A new instance of Workflow.
- #run! ⇒ Object
- #to_ascii(path: nil) ⇒ Object
- #to_dot ⇒ Object
- #to_svg(path: nil) ⇒ Object
Constructor Details
#initialize(payload, context = {}, credentials = {}) ⇒ Workflow
Returns a new instance of Workflow.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/manageiq/floe/workflow.rb', line 17 def initialize(payload, context = {}, credentials = {}) payload = JSON.parse(payload) if payload.kind_of?(String) context = JSON.parse(context) if context.kind_of?(String) credentials = JSON.parse(credentials) if credentials.kind_of?(String) @payload = payload @context = context @credentials = credentials @states = payload["States"].to_a.map { |name, state| State.build!(self, name, state) } @states_by_name = states.to_h { |state| [state.name, state] } @start_at = @payload["StartAt"] @first_state = @states_by_name[@start_at] rescue JSON::ParserError => err raise ManageIQ::Floe::InvalidWorkflowError, err. end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
15 16 17 |
# File 'lib/manageiq/floe/workflow.rb', line 15 def context @context end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
15 16 17 |
# File 'lib/manageiq/floe/workflow.rb', line 15 def credentials @credentials end |
#first_state ⇒ Object (readonly)
Returns the value of attribute first_state.
15 16 17 |
# File 'lib/manageiq/floe/workflow.rb', line 15 def first_state @first_state end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
15 16 17 |
# File 'lib/manageiq/floe/workflow.rb', line 15 def payload @payload end |
#start_at ⇒ Object (readonly)
Returns the value of attribute start_at.
15 16 17 |
# File 'lib/manageiq/floe/workflow.rb', line 15 def start_at @start_at end |
#states ⇒ Object (readonly)
Returns the value of attribute states.
15 16 17 |
# File 'lib/manageiq/floe/workflow.rb', line 15 def states @states end |
#states_by_name ⇒ Object (readonly)
Returns the value of attribute states_by_name.
15 16 17 |
# File 'lib/manageiq/floe/workflow.rb', line 15 def states_by_name @states_by_name end |
Class Method Details
.load(path_or_io, context = {}, credentials = {}) ⇒ Object
9 10 11 12 |
# File 'lib/manageiq/floe/workflow.rb', line 9 def load(path_or_io, context = {}, credentials = {}) payload = path_or_io.respond_to?(:read) ? path_or_io.read : File.read(path_or_io) new(payload, context, credentials) end |
Instance Method Details
#run! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/manageiq/floe/workflow.rb', line 33 def run! state = first_state input = context.dup until state.nil? state, output = state.run!(input) input = output end output end |
#to_ascii(path: nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/manageiq/floe/workflow.rb', line 72 def to_ascii(path: nil) require "open3" out, err, _status = Open3.capture3("graph-easy", :stdin_data => to_dot) raise "Error from graph-easy:\n#{err}" if err && !err.empty? File.write(path, out) if path out end |
#to_dot ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/manageiq/floe/workflow.rb', line 45 def to_dot String.new.tap do |s| s << "digraph {\n" states.each do |state| s << state.to_dot << "\n" end s << "\n" states.each do |state| Array(state.to_dot_transitions).each do |transition| s << transition << "\n" end end s << "}\n" end end |
#to_svg(path: nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/manageiq/floe/workflow.rb', line 61 def to_svg(path: nil) require "open3" out, err, _status = Open3.capture3("dot -Tsvg", :stdin_data => to_dot) raise "Error from graphviz:\n#{err}" if err && !err.empty? File.write(path, out) if path out end |