floe 0.13.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/floe.rb CHANGED
@@ -8,8 +8,11 @@ require_relative "floe/logging"
8
8
  require_relative "floe/runner"
9
9
 
10
10
  require_relative "floe/validation_mixin"
11
+ require_relative "floe/workflow_base"
11
12
  require_relative "floe/workflow"
13
+ # mixins used by workflow components
12
14
  require_relative "floe/workflow/error_matcher_mixin"
15
+ require_relative "floe/workflow/branch"
13
16
  require_relative "floe/workflow/catcher"
14
17
  require_relative "floe/workflow/choice_rule"
15
18
  require_relative "floe/workflow/choice_rule/not"
@@ -17,6 +20,7 @@ require_relative "floe/workflow/choice_rule/or"
17
20
  require_relative "floe/workflow/choice_rule/and"
18
21
  require_relative "floe/workflow/choice_rule/data"
19
22
  require_relative "floe/workflow/context"
23
+ require_relative "floe/workflow/item_processor"
20
24
  require_relative "floe/workflow/intrinsic_function"
21
25
  require_relative "floe/workflow/intrinsic_function/parser"
22
26
  require_relative "floe/workflow/intrinsic_function/transformer"
@@ -25,11 +29,14 @@ require_relative "floe/workflow/payload_template"
25
29
  require_relative "floe/workflow/reference_path"
26
30
  require_relative "floe/workflow/retrier"
27
31
  require_relative "floe/workflow/state"
32
+ # mixins used by states
33
+ require_relative "floe/workflow/states/child_workflow_mixin"
34
+ require_relative "floe/workflow/states/input_output_mixin"
35
+ require_relative "floe/workflow/states/non_terminal_mixin"
36
+ require_relative "floe/workflow/states/retry_catch_mixin"
28
37
  require_relative "floe/workflow/states/choice"
29
38
  require_relative "floe/workflow/states/fail"
30
- require_relative "floe/workflow/states/input_output_mixin"
31
39
  require_relative "floe/workflow/states/map"
32
- require_relative "floe/workflow/states/non_terminal_mixin"
33
40
  require_relative "floe/workflow/states/parallel"
34
41
  require_relative "floe/workflow/states/pass"
35
42
  require_relative "floe/workflow/states/succeed"
@@ -43,7 +50,18 @@ module Floe
43
50
  class Error < StandardError; end
44
51
  class InvalidWorkflowError < Error; end
45
52
  class InvalidExecutionInput < Error; end
46
- class PathError < Error; end
53
+
54
+ class ExecutionError < Error
55
+ attr_reader :floe_error
56
+
57
+ def initialize(message, floe_error = "States.Runtime")
58
+ super(message)
59
+ @floe_error = floe_error
60
+ end
61
+ end
62
+
63
+ class PathError < ExecutionError
64
+ end
47
65
 
48
66
  def self.logger
49
67
  @logger ||= NullLogger.new
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/inline"
4
+ gemfile do
5
+ source "https://rubygems.org"
6
+ gem "optimist"
7
+ gem "colorize"
8
+ end
9
+ require "pp"
10
+
11
+ SUB_COMMANDS = {
12
+ "execute" => "Execute an .asl file through the stepfunctions simulator.",
13
+ "intrinsic" => "Execute an intrinsic function or JSONPath standalone."
14
+ }.freeze
15
+ Optimist.options do
16
+ banner "Run the aws stepfunctions simulator."
17
+ banner ""
18
+ banner "Notes:"
19
+ banner " This tool requires the stepfunctions simulator to be installed locally and running."
20
+ banner " Installation instructions can be found at https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local.html."
21
+ banner ""
22
+ banner "Commands:"
23
+ SUB_COMMANDS.each { |k, v| banner " #{k.ljust(14)}#{v}" }
24
+ banner ""
25
+ banner " For more help with a specific command use #{$PROGRAM_NAME} <command> --help"
26
+ banner ""
27
+ banner "Global Options:"
28
+ stop_on SUB_COMMANDS.keys
29
+ end
30
+ cmd = ARGV.shift
31
+ Optimist.educate if cmd.nil?
32
+ Optimist.die "unknown subcommand #{cmd.inspect}" unless SUB_COMMANDS.include?(cmd)
33
+
34
+ def aws_stepfunctions(args)
35
+ cmd = "aws stepfunctions --endpoint-url http://localhost:8083 #{args}"
36
+ puts "** #{cmd}".light_black if ENV["DEBUG"]
37
+ output = `#{cmd}`.chomp
38
+ output = output.empty? ? {} : JSON.parse(output)
39
+ puts output.pretty_inspect.light_black if ENV["DEBUG"]
40
+ output
41
+ rescue JSON::ParserError => err
42
+ warn "ERROR: #{err}".light_red if ENV["DEBUG"]
43
+ {}
44
+ end
45
+
46
+ def execute_stepfunction(definition, input)
47
+ require "json"
48
+ require "shellwords"
49
+
50
+ begin
51
+ state_machine_arn = aws_stepfunctions("create-state-machine --definition #{Shellwords.escape(definition)} --name 'StateMachine' --role-arn 'arn:aws:iam::012345678901:role/DummyRole'")["stateMachineArn"]
52
+ exit 1 if state_machine_arn.nil?
53
+
54
+ input = input ? "--input #{Shellwords.escape(input)}" : ""
55
+ execution_arn = aws_stepfunctions("start-execution --state-machine-arn #{state_machine_arn} #{input}")["executionArn"]
56
+ exit 1 if execution_arn.nil?
57
+
58
+ status, output = aws_stepfunctions("describe-execution --execution-arn #{execution_arn}").values_at("status", "output")
59
+ if status == "FAILED"
60
+ warn "ERROR: Execution failed. See simulator for reason.".light_red
61
+ exit 1
62
+ end
63
+ ensure
64
+ aws_stepfunctions("stop-execution --execution-arn #{execution_arn}") if execution_arn
65
+ aws_stepfunctions("delete-state-machine --state-machine-arn #{state_machine_arn}") if state_machine_arn
66
+ end
67
+
68
+ puts output if output
69
+ end
70
+
71
+ def execute
72
+ opts = Optimist.options do
73
+ banner SUB_COMMANDS["execute"]
74
+ banner ""
75
+
76
+ opt :file, "The .asl file to execute", :default => "definition.asl"
77
+ opt :input, "Input to the execution", :type => :string
78
+ end
79
+
80
+ definition = File.read(opts[:file]).chomp
81
+ execute_stepfunction(definition, opts[:input])
82
+ end
83
+
84
+ def intrinsic
85
+ opts = Optimist.options do
86
+ banner SUB_COMMANDS["intrinsic"]
87
+ banner ""
88
+
89
+ opt :function, "The intrinsic function or JSONPath to run", :type => :string, :required => true
90
+ opt :input, "Input to the execution", :type => :string
91
+ end
92
+
93
+ require "json"
94
+
95
+ definition = {
96
+ "StartAt" => "ExecState",
97
+ "States" => {
98
+ "ExecState" => {
99
+ "Type" => "Pass",
100
+ "Parameters" => {"data.$" => opts[:function]},
101
+ "OutputPath" => "$.data",
102
+ "End" => true
103
+ }
104
+ }
105
+ }.to_json
106
+
107
+ execute_stepfunction(definition, opts[:input])
108
+ end
109
+
110
+ send(cmd)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: floe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-16 00:00:00.000000000 Z
11
+ date: 2024-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_spawn
@@ -182,6 +182,8 @@ files:
182
182
  - LICENSE.txt
183
183
  - README.md
184
184
  - Rakefile
185
+ - examples/map.asl
186
+ - examples/parallel.asl
185
187
  - examples/set-credential.asl
186
188
  - examples/workflow.asl
187
189
  - exe/floe
@@ -199,6 +201,7 @@ files:
199
201
  - lib/floe/validation_mixin.rb
200
202
  - lib/floe/version.rb
201
203
  - lib/floe/workflow.rb
204
+ - lib/floe/workflow/branch.rb
202
205
  - lib/floe/workflow/catcher.rb
203
206
  - lib/floe/workflow/choice_rule.rb
204
207
  - lib/floe/workflow/choice_rule/and.rb
@@ -210,11 +213,13 @@ files:
210
213
  - lib/floe/workflow/intrinsic_function.rb
211
214
  - lib/floe/workflow/intrinsic_function/parser.rb
212
215
  - lib/floe/workflow/intrinsic_function/transformer.rb
216
+ - lib/floe/workflow/item_processor.rb
213
217
  - lib/floe/workflow/path.rb
214
218
  - lib/floe/workflow/payload_template.rb
215
219
  - lib/floe/workflow/reference_path.rb
216
220
  - lib/floe/workflow/retrier.rb
217
221
  - lib/floe/workflow/state.rb
222
+ - lib/floe/workflow/states/child_workflow_mixin.rb
218
223
  - lib/floe/workflow/states/choice.rb
219
224
  - lib/floe/workflow/states/fail.rb
220
225
  - lib/floe/workflow/states/input_output_mixin.rb
@@ -222,11 +227,13 @@ files:
222
227
  - lib/floe/workflow/states/non_terminal_mixin.rb
223
228
  - lib/floe/workflow/states/parallel.rb
224
229
  - lib/floe/workflow/states/pass.rb
230
+ - lib/floe/workflow/states/retry_catch_mixin.rb
225
231
  - lib/floe/workflow/states/succeed.rb
226
232
  - lib/floe/workflow/states/task.rb
227
233
  - lib/floe/workflow/states/wait.rb
234
+ - lib/floe/workflow_base.rb
228
235
  - renovate.json
229
- - sig/floe.rbs/floe.rbs
236
+ - tools/step_functions
230
237
  homepage: https://github.com/ManageIQ/floe
231
238
  licenses:
232
239
  - Apache-2.0
@@ -1,4 +0,0 @@
1
- module Floe
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end