aws-sdk 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/lib/aws.rb +2 -0
  2. data/lib/aws/api_config/SimpleWorkflow-2012-01-25.yml +1163 -0
  3. data/lib/aws/core.rb +16 -11
  4. data/lib/aws/core/configuration.rb +65 -47
  5. data/lib/aws/dynamo_db/item_collection.rb +2 -3
  6. data/lib/aws/dynamo_db/table.rb +2 -2
  7. data/lib/aws/ec2/collection.rb +1 -1
  8. data/lib/aws/ec2/snapshot_collection.rb +1 -1
  9. data/lib/aws/ec2/tagged_collection.rb +6 -1
  10. data/lib/aws/elb/backend_server_policy_collection.rb +1 -11
  11. data/lib/aws/elb/load_balancer.rb +4 -4
  12. data/lib/aws/elb/load_balancer_collection.rb +1 -1
  13. data/lib/aws/iam/policy.rb +1 -1
  14. data/lib/aws/record.rb +10 -4
  15. data/lib/aws/record/hash_model/finder_methods.rb +2 -3
  16. data/lib/aws/s3/bucket_lifecycle_configuration.rb +2 -2
  17. data/lib/aws/s3/policy.rb +1 -1
  18. data/lib/aws/simple_email_service.rb +8 -2
  19. data/lib/aws/simple_workflow.rb +223 -0
  20. data/lib/aws/simple_workflow/activity_task.rb +173 -0
  21. data/lib/aws/simple_workflow/activity_task_collection.rb +112 -0
  22. data/lib/aws/simple_workflow/activity_type.rb +131 -0
  23. data/lib/aws/simple_workflow/activity_type_collection.rb +93 -0
  24. data/lib/aws/simple_workflow/client.rb +57 -0
  25. data/lib/aws/simple_workflow/config.rb +18 -0
  26. data/lib/aws/simple_workflow/count.rb +49 -0
  27. data/lib/aws/simple_workflow/decision_task.rb +603 -0
  28. data/lib/aws/simple_workflow/decision_task_collection.rb +213 -0
  29. data/lib/aws/simple_workflow/domain.rb +122 -0
  30. data/lib/aws/simple_workflow/domain_collection.rb +169 -0
  31. data/lib/aws/simple_workflow/errors.rb +57 -0
  32. data/lib/aws/simple_workflow/history_event.rb +276 -0
  33. data/lib/aws/simple_workflow/history_event_collection.rb +76 -0
  34. data/lib/aws/simple_workflow/option_formatters.rb +75 -0
  35. data/lib/aws/simple_workflow/request.rb +80 -0
  36. data/lib/aws/simple_workflow/resource.rb +94 -0
  37. data/lib/aws/simple_workflow/type.rb +89 -0
  38. data/lib/aws/simple_workflow/type_collection.rb +139 -0
  39. data/lib/aws/simple_workflow/workflow_execution.rb +386 -0
  40. data/lib/aws/simple_workflow/workflow_execution_collection.rb +617 -0
  41. data/lib/aws/simple_workflow/workflow_type.rb +177 -0
  42. data/lib/aws/simple_workflow/workflow_type_collection.rb +91 -0
  43. data/lib/aws/sns/policy.rb +1 -1
  44. data/lib/aws/sns/subscription.rb +2 -2
  45. data/lib/aws/sqs/errors.rb +2 -2
  46. data/lib/aws/sqs/policy.rb +1 -1
  47. metadata +111 -54
@@ -0,0 +1,57 @@
1
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ module AWS
15
+ class SimpleWorkflow
16
+
17
+ # @private
18
+ module Errors
19
+
20
+ module ModeledError
21
+
22
+ def initialize(request = nil, response = nil)
23
+ message = extract_message(response)
24
+ include_error_type(response) if response
25
+ super(request, response, message)
26
+ end
27
+
28
+ def extract_message(response)
29
+ if response and
30
+ response.body
31
+ JSON.load(response.body)["message"] || code
32
+ else
33
+ code
34
+ end
35
+ end
36
+
37
+ def include_error_type(response)
38
+ if response.status >= 500
39
+ extend Errors::ServerError
40
+ else
41
+ extend Errors::ClientError
42
+ end
43
+ end
44
+
45
+ def code
46
+ self.class.name =~ /(::)?([^:]+)$/
47
+ $2
48
+ end
49
+
50
+ end
51
+
52
+ include Core::LazyErrorClasses
53
+
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,276 @@
1
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ require 'json'
15
+
16
+ module AWS
17
+ class SimpleWorkflow
18
+
19
+ # == Getting History Events
20
+ #
21
+ # History events belong to workflow executions. You can get them
22
+ # from an execution two ways:
23
+ #
24
+ # 1) By enumerating events from the execution
25
+ #
26
+ # workflow_execution.events.each do |event|
27
+ # # ...
28
+ # end
29
+ #
30
+ # 2) By enumerating events from the context of a {DecisionTask}:
31
+ #
32
+ # workflow_execution.decision_tasks.poll do |decision_task|
33
+ # decision_task.events.each do |event|
34
+ # end
35
+ # end
36
+ #
37
+ # == History Event Attributes
38
+ #
39
+ # All history events respond to the following 4 methods:
40
+ #
41
+ # * {#event_type}
42
+ # * {#event_id}
43
+ # * {#created_at}
44
+ # * {#attributes}
45
+ #
46
+ # For a complete list of event types and a complete list of attributes
47
+ # returned with each event type, see the service API documentation.
48
+ #
49
+ # Because the service returns attributes with camelCase name the
50
+ # structure returned by {#attributes} allows you to access attributes
51
+ # by their snake_case name or their camelCase name:
52
+ #
53
+ # event.attributes.workflow_type
54
+ # event.attributes['workflowType']
55
+ #
56
+ # See {HistoryEvent::Attributes} for more information about working
57
+ # with the returned attributes.
58
+ #
59
+ class HistoryEvent
60
+
61
+ include Core::Model
62
+
63
+ # @param [WorkflowExecution] workflow_execution
64
+ #
65
+ # @param [Hash,String] details A hash or JSON string describing
66
+ # the history event.
67
+ #
68
+ def initialize workflow_execution, details
69
+
70
+ @workflow_execution = workflow_execution
71
+ @details = details.is_a?(String) ? JSON.parse(details) : details
72
+ @event_type = @details['eventType']
73
+ @event_id = @details['eventId']
74
+ @created_at = Time.at(@details['eventTimestamp'])
75
+
76
+ attributes_key = "#{event_type}EventAttributes"
77
+ attributes_key[0] = attributes_key[0,1].downcase
78
+ attribute_data = @details[attributes_key] || {}
79
+ @attributes = Attributes.new(workflow_execution, attribute_data)
80
+
81
+ super
82
+
83
+ end
84
+
85
+ # @return [WorkflowExecution] The workflow execution this history
86
+ # event belongs to.
87
+ attr_reader :workflow_execution
88
+
89
+ # @return [String] Returns the name of the history event type.
90
+ attr_reader :event_type
91
+
92
+ # @return [Integer] Returns the event id.
93
+ attr_reader :event_id
94
+ alias_method :id, :event_id
95
+
96
+ # @return [Time] When the event history was created.
97
+ attr_reader :created_at
98
+
99
+ # @return [Attributes] Returns an object that provides hash-like
100
+ # access to the history event attributes.
101
+ attr_reader :attributes
102
+
103
+ # @return [Hash] Returns a hash representation of the event.
104
+ def to_h
105
+ {
106
+ :event_type => event_type,
107
+ :event_id => event_id,
108
+ :created_at => created_at,
109
+ :attributes => attributes.to_h,
110
+ }
111
+ end
112
+
113
+ # @return [String] Returns a JSON representation of this workflow
114
+ # execution.
115
+ def to_json
116
+ @details.to_json
117
+ end
118
+
119
+ # @private
120
+ def inspect
121
+ "<#{self.class.name} #{to_h.inspect}>"
122
+ end
123
+
124
+ # A collection off attributes that provides method and hash style
125
+ # access to a collection of attributes.
126
+ #
127
+ # If you are exploring a history event, you can call {#keys} to get
128
+ # a complete list of attribute names present. You can also reference
129
+ # the service API documentation that lists all history event types
130
+ # along with their returned attributes.
131
+ #
132
+ # == Indifferent Access
133
+ #
134
+ # Here are a few examples showing the different ways to access an
135
+ # attribute:
136
+ #
137
+ # event = workflow_executions.events.first
138
+ #
139
+ # # equivalent
140
+ # event.attributes.task_list
141
+ # event.attributes[:task_list]
142
+ # event.attributes['task_list']
143
+ # event.attributes['taskList']
144
+ #
145
+ # As shown in the example above keys and method names can be
146
+ # snake_cased or camelCased (strings or symbols).
147
+ #
148
+ # == Special Attributes
149
+ #
150
+ # The following list of attributes are treated specially. Generally this
151
+ # means they return
152
+ #
153
+ # * timeout attributes (e.g. taskStartToCloseTimeout) are returned as
154
+ # integers (number of seconds) or the special symbol :none, implying
155
+ # there is no timeout.
156
+ #
157
+ # * childPolicy is cast to a symbol
158
+ #
159
+ # * activityType is returned as a {ActivityType} object.
160
+ #
161
+ # * workflowType is returned as a {WorkflowType} object.
162
+ #
163
+ # * workflowExecution is returned as a {WorkflowExecution} object.
164
+ #
165
+ # * taskList is returned as a string, not a hash.
166
+ #
167
+ class Attributes
168
+
169
+ # @private
170
+ def initialize workflow_execution, data
171
+ @workflow_execution = workflow_execution
172
+ @data = data
173
+ end
174
+
175
+ # @param [String,Symbol] key
176
+ # @return Returns the attribute with the given name (key).
177
+ def [] key
178
+ key = _camel_case(key)
179
+ if @data.key?(key)
180
+ _cast(key, @data[key])
181
+ else
182
+ msg = "no such attribute `#{key}`, valid keys are #{_key_string}"
183
+ raise ArgumentError, msg
184
+ end
185
+ end
186
+
187
+ # @return [Array<Symbol>] Returns a list of valid keys for this
188
+ # set of attributes.
189
+ def keys
190
+ @data.keys.collect{|key| _snake_case(key) }
191
+ end
192
+
193
+ # @return [Boolean] Returns true if the attribute with the given
194
+ # name is set.
195
+ def key? key
196
+ @data.key?(_camel_case(key))
197
+ end
198
+ alias_method :member?, :key?
199
+ alias_method :include?, :key?
200
+ alias_method :has_key?, :key?
201
+
202
+ # (see {#[]})
203
+ def method_missing method
204
+ self[method]
205
+ end
206
+
207
+ # @return [Hash] Returns all of the attributes in a hash with
208
+ # snaked_cased and symbolized keys.
209
+ def to_h
210
+ @data.inject({}) do |h,(key,value)|
211
+ value = _cast(key,value)
212
+ if value.is_a?(Array)
213
+ value = value.map{|v| v.is_a?(Attributes) ? v.to_h : v }
214
+ end
215
+ h[_snake_case(key)] = value.is_a?(Attributes) ? value.to_h : value
216
+ h
217
+ end
218
+ end
219
+
220
+ # @private
221
+ def inspect
222
+ "<Attributes #{to_h.inspect}>"
223
+ end
224
+
225
+ protected
226
+ def _key_string
227
+ keys.map(&:inspect).join(', ')
228
+ end
229
+
230
+ protected
231
+ def _cast key, value
232
+ case key
233
+ when /Timeout$/
234
+ value.to_s =~ /^\d+$/ ? value.to_i : value.downcase.to_sym
235
+ when 'taskList'
236
+ value['name']
237
+ when 'childPolicy'
238
+ value.downcase.to_sym
239
+ when 'activityType'
240
+ name = value['name']
241
+ version = value['version']
242
+ @workflow_execution.domain.activity_types[name,version]
243
+ when 'workflowType'
244
+ name = value['name']
245
+ version = value['version']
246
+ @workflow_execution.domain.workflow_types[name,version]
247
+ when 'workflowExecution'
248
+ workflow_id = value['workflowId']
249
+ run_id = value['runId']
250
+ @workflow_execution.domain.workflow_executions[workflow_id, run_id]
251
+ else
252
+ case value
253
+ when Array then value.collect{|v| _cast(key,v) }
254
+ when Hash then Attributes.new(@workflow_execution, value)
255
+ else value
256
+ end
257
+ end
258
+ end
259
+
260
+ protected
261
+ def _snake_case key
262
+ Core::Inflection.ruby_name(key.to_s).to_sym
263
+ end
264
+
265
+ protected
266
+ def _camel_case key
267
+ key = key.to_s.split(/_/).collect{|k| k[0] = k[0,1].upcase; k}.join
268
+ key[0] = key[0,1].downcase
269
+ key
270
+ end
271
+
272
+ end
273
+
274
+ end
275
+ end
276
+ end
@@ -0,0 +1,76 @@
1
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ module AWS
15
+ class SimpleWorkflow
16
+
17
+ # This collection represents the history events ({HistoryEvent}) for a
18
+ # single workflow execution.
19
+ #
20
+ # See {Core::Collection} for documentation on the standard enumerable
21
+ # methods and their options.
22
+ #
23
+ class HistoryEventCollection
24
+
25
+ include Core::Collection::Limitable
26
+
27
+ # @param [WorkflowExecution] The execution this history event
28
+ # belongs to.
29
+ #
30
+ # @param [Hash] options
31
+ #
32
+ # @option options [Boolean] :reverse_order (false) When true,
33
+ # history events are enumerated in reverse chronological order.
34
+ #
35
+ def initialize workflow_execution, options = {}
36
+ @workflow_execution = workflow_execution
37
+ @reverse_order = options.key?(:reverse_order) ?
38
+ !!options[:reverse_order] : false
39
+ super
40
+ end
41
+
42
+ # @return [WorkflowExectuion]
43
+ attr_reader :workflow_execution
44
+
45
+ # @return [WorkflowExecutionCollection] Returns a collection that
46
+ # enumerates workflow executions in reverse order.
47
+ def reverse_order
48
+ self.class.new(workflow_execution, :reverse_order => true)
49
+ end
50
+
51
+ protected
52
+ def _each_item next_token, limit, options = {}, &block
53
+
54
+ options[:domain] = workflow_execution.domain.name
55
+ options[:execution] = {
56
+ :workflow_id => workflow_execution.workflow_id,
57
+ :run_id => workflow_execution.run_id,
58
+ }
59
+ options[:maximum_page_size] = limit if limit
60
+ options[:next_page_token] = next_token if next_token
61
+ options[:reverse_order] = @reverse_order unless
62
+ options.has_key?(:reverse_order)
63
+
64
+ response = client.get_workflow_execution_history(options)
65
+ response.data['events'].each do |desc|
66
+ event = HistoryEvent.new(workflow_execution, desc)
67
+ yield(event)
68
+ end
69
+
70
+ response.data['nextPageToken']
71
+
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,75 @@
1
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ module AWS
15
+ class SimpleWorkflow
16
+
17
+ # @private
18
+ module OptionFormatters
19
+
20
+ protected
21
+ def upcase_opts options, *opt_names
22
+ opt_names.each do |opt|
23
+ if options.has_key?(opt)
24
+ options[opt] = options[opt].to_s.upcase
25
+ end
26
+ end
27
+ end
28
+
29
+ protected
30
+ def duration_opts options, *opt_names
31
+ opt_names.each do |opt|
32
+ options[opt] = options[opt].to_s.upcase if options[opt]
33
+ end
34
+ end
35
+
36
+ def start_execution_opts options, workflow_type = nil
37
+
38
+ if workflow_type
39
+
40
+ options[:workflow_id] ||= UUIDTools::UUID.random_create.to_s
41
+
42
+ if workflow_type.is_a?(WorkflowType)
43
+ options[:workflow_type] = {}
44
+ options[:workflow_type][:name] = workflow_type.name
45
+ options[:workflow_type][:version] = workflow_type.version
46
+ elsif
47
+ workflow_type.is_a?(Hash) and
48
+ workflow_type[:name].is_a?(String) and
49
+ workflow_type[:version] .is_a?(String)and
50
+ workflow_type.keys.length == 2
51
+ then
52
+ options[:workflow_type] = workflow_type
53
+ else
54
+ msg = "expected workflow_type to be a WorkflowType object or " +
55
+ "a hash with :name and :version"
56
+ raise ArgumentError, msg
57
+ end
58
+
59
+ end
60
+
61
+ upcase_opts(options, :child_policy)
62
+
63
+ duration_opts(options,
64
+ :execution_start_to_close_timeout,
65
+ :task_start_to_close_timeout)
66
+
67
+ if options.has_key?(:task_list)
68
+ options[:task_list] = { :name => options[:task_list].to_s }
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+ end
75
+ end