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,213 @@
1
+ require 'uuidtools'
2
+
3
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
6
+ # may not use this file except in compliance with the License. A copy of
7
+ # the License is located at
8
+ #
9
+ # http://aws.amazon.com/apache2.0/
10
+ #
11
+ # or in the "license" file accompanying this file. This file is
12
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
13
+ # ANY KIND, either express or implied. See the License for the specific
14
+ # language governing permissions and limitations under the License.
15
+
16
+ module AWS
17
+ class SimpleWorkflow
18
+
19
+ # Provides an interface to count, and receive decision tasks
20
+ # ({DecisionTask} objects) from the service.
21
+ #
22
+ # == Counting
23
+ #
24
+ # To get a count of decision tasks needing attention, call {#count}
25
+ # with a task list name:
26
+ #
27
+ # domain.decision_tasks.count('my-task-list') #=> 7
28
+ #
29
+ # == Getting a single decision task
30
+ #
31
+ # To process a single task use {#poll_for_single_task}:
32
+ #
33
+ # domain.decision_tasks.poll_for_single_task('my-task-list') do |task|
34
+ # # this block is yielded to only if a task is found
35
+ # # within 60 seconds.
36
+ # end
37
+ #
38
+ # At the end of the block, the decision task is auto-completed.
39
+ # If you prefer you can omit the block and +nil+ or a {DecisionTask}
40
+ # will be returned.
41
+ #
42
+ # if task = domain.decision_tasks.poll_for_single_task('my-task-list')
43
+ # # you need to call complete! or the decision task will time out
44
+ # task.complete!
45
+ # end
46
+ #
47
+ # == Polling for Tasks in a Loop
48
+ #
49
+ # You can poll indefinetly for tasks in a loop with {#poll}:
50
+ #
51
+ # domain.decision_tasks.poll('my-task-list') do |task|
52
+ # # yields once for every decision task found
53
+ # end
54
+ #
55
+ # Just like the block form above, the decision task is auto completed at
56
+ # the end of the block. Please note, if you call +break+ or +return+
57
+ # from inside the block, you *MUST* call {DecisionTask#complete!} or
58
+ # the task will timeout.
59
+ #
60
+ # == Events and Decisions
61
+ #
62
+ # Each decision task provides an enumerable collection of both
63
+ # new events ({DecisionTask#new_events}) and all events
64
+ # ({DecisionTask#events}).
65
+ #
66
+ # Based on the events in the workflow execution history, you should
67
+ # call methods on the decision task. See {DecisionTask} for
68
+ # a complete list of decision methods.
69
+ #
70
+ class DecisionTaskCollection
71
+
72
+ include Core::Model
73
+ include OptionFormatters
74
+
75
+ # @private
76
+ def initialize domain, options = {}
77
+ @domain = domain
78
+ super
79
+ end
80
+
81
+ # @return [Domain]
82
+ attr_reader :domain
83
+
84
+ # Returns the number of decision tasks in the specified +task_list+.
85
+ #
86
+ # @note This operation is eventually consistent. The results are best
87
+ # effort and may not exactly reflect recent updates and changes.
88
+ #
89
+ # @param [String] task_list Name of the task list to count
90
+ # decision tasks for.
91
+ #
92
+ # @return [Integer] Returns the number of descision tasks for the
93
+ # given +task_list+.
94
+ #
95
+ def count task_list
96
+ options = {}
97
+ options[:domain] = domain.name
98
+ options[:task_list] = { :name => task_list }
99
+ response = client.count_pending_decision_tasks(options)
100
+ Count.new(response.data['count'], response.data['truncated'])
101
+ end
102
+
103
+ # Polls the service for a single decision task. The service may
104
+ # hold the request for up to 60 seconds before responding.
105
+ #
106
+ # # try to get a single task, may return nil when no tasks available
107
+ # task = domain.decision_tasks.poll_for_single_task('task-list')
108
+ # if task
109
+ # # make decisions ...
110
+ # task.complete!
111
+ # end
112
+ #
113
+ # You can optionally pass a block and that will only be yielded
114
+ # to when a decision task is available within the 60 seconds.
115
+ #
116
+ # domain.decision_tasks.poll_for_single_task('task-list') do |task|
117
+ # # make decisions
118
+ # # task.complete! is called for you at the end of the block
119
+ # end
120
+ #
121
+ # With the block form you do not need to call #complete! on the
122
+ # decision task. It will be called when the block exists.
123
+ #
124
+ # @note If you are not using the block form you must call
125
+ # {DecisionTask#complete!} yourself or your decision task will
126
+ # timeout.
127
+ #
128
+ # @param [String] task_list Specifies the task list to poll for
129
+ # decision tasks.
130
+ #
131
+ # @param [Hash] options
132
+ #
133
+ # @option options [String] :identity The identity of the decider
134
+ # requesting a decision task. This will be recorded in the
135
+ # DecisionTaskStarted event in the workflow history.
136
+ # If +:identity+ is not passed, a random UUID will be generated.
137
+ #
138
+ # @option options [Boolean] :reverse_event_order (false) When true,
139
+ # the history events on the decision task will enumerate in
140
+ # reverse chronological order (newest events first). By default
141
+ # the events are enumerated in chronological order (oldest first).
142
+ #
143
+ # @option options [Integer] :event_batch_size (1000) When enumerating
144
+ # events on the decision task, multiple requests may be required
145
+ # to fetch all of the events. You can specify the maximum number
146
+ # of events to request each time (must not be greater than 1000).
147
+ #
148
+ # @yieldparam [DecisionTask] decision_task
149
+ #
150
+ # @return [DecisionTask,nil] Returns a decision task or +nil+. If
151
+ # a block was passed then +nil+ is always returned. If a block
152
+ # is not passed, then +nil+ or a {DecisionTask} will be returned.
153
+ #
154
+ def poll_for_single_task task_list, options = {}, &block
155
+
156
+ client_opts = {}
157
+ client_opts[:domain] = domain.name
158
+ client_opts[:identity] = options[:identity] if options[:identity]
159
+ client_opts[:task_list] = { :name => task_list }
160
+ client_opts[:maximum_page_size] = options[:event_batch_size] || 1000
161
+ client_opts[:reverse_order] = options.key?(:reverse_event_order) ?
162
+ options[:reverse_event_order] : false
163
+
164
+ response = client.poll_for_decision_task(client_opts)
165
+
166
+ if response.data['taskToken']
167
+ decision_task = DecisionTask.new(domain, client_opts, response.data)
168
+ if block_given?
169
+ yield(decision_task)
170
+ decision_task.complete! unless decision_task.responded?
171
+ nil
172
+ else
173
+ decision_task
174
+ end
175
+ else
176
+ nil
177
+ end
178
+
179
+ end
180
+
181
+ # Polls indefinetly for decision tasks. Each deicsion task found is
182
+ # yielded to the block. At the end of the block the decision task
183
+ # is auto-completed ({DecisionTask#complete!} is called).
184
+ #
185
+ # # yields once for each decision task found, indefinetly
186
+ # domain.decision_tasks.poll do |decision_task|
187
+ # # make decisions here
188
+ # end
189
+ #
190
+ # @note If you to terminate the block (by calling +break+ or +return+)
191
+ # then it is your responsibility to call #complete! on the decision
192
+ # task.
193
+ #
194
+ # @param (see #poll_for_single_task)
195
+ #
196
+ # @option (see #poll_for_single_task)
197
+ #
198
+ # @yieldparam [DecisionTask] decision_task
199
+ #
200
+ # @return [nil]
201
+ #
202
+ def poll task_list, options = {}, &block
203
+ loop do
204
+ poll_for_single_task(task_list, options) do |decision_task|
205
+ yield(decision_task)
206
+ end
207
+ end
208
+ nil
209
+ end
210
+
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,122 @@
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
+ # Domains are used to organize workflows types and activities for
18
+ # an account.
19
+ #
20
+ # @attr_reader [String,nil] description Returns
21
+ #
22
+ # @attr_reader [Integer,Symbol] retention_period Returns the retention
23
+ # period for this domain. The return value may be an integer (number
24
+ # of days history is kept around) or the symbol +:none+, implying
25
+ # no expiry of closed workflow executions.
26
+ #
27
+ # @attr_reader [Symbol] status Returns the domain's status. Status will
28
+ # be either +:registered+ or +:deprecated+.
29
+ #
30
+ class Domain < Resource
31
+
32
+ include OptionFormatters
33
+
34
+ # @private
35
+ def initialize name, options = {}
36
+ @name = name.to_s
37
+ super(options)
38
+ end
39
+
40
+ # @return [String] Returns the name of this domain.
41
+ attr_reader :name
42
+
43
+ info_attribute :description, :static => true
44
+
45
+ info_attribute :status, :to_sym => true
46
+
47
+ config_attribute :retention_period,
48
+ :as => 'workflowExecutionRetentionPeriodInDays',
49
+ :duration => true,
50
+ :static => true
51
+
52
+ # @return [WorkflowTypeCollection]
53
+ def workflow_types
54
+ WorkflowTypeCollection.new(self)
55
+ end
56
+
57
+ # @return [ActivityTypeCollection]
58
+ def activity_types
59
+ ActivityTypeCollection.new(self)
60
+ end
61
+
62
+ # @return [WorkflowExecutionCollection]
63
+ def workflow_executions
64
+ WorkflowExecutionCollection.new(self)
65
+ end
66
+
67
+ # @return [DecisionTaskCollection]
68
+ def decision_tasks
69
+ DecisionTaskCollection.new(self)
70
+ end
71
+
72
+ # @return [ActivityTaskCollection]
73
+ def activity_tasks
74
+ ActivityTaskCollection.new(self)
75
+ end
76
+
77
+ # @return [Boolean] Returns true if this domain has been deprecated.
78
+ def deprecated?
79
+ self.status == :deprecated
80
+ end
81
+
82
+ # Deprecates the domain. After a domain has been deprecated it cannot
83
+ # be used to create new workflow executions or register new types.
84
+ # However, you can still use visibility actions on this domain.
85
+ #
86
+ # Deprecating a domain also deprecates all activity and workflow
87
+ # types registered in the domain. Executions that were started
88
+ # before the domain was deprecated will continue to run.
89
+ #
90
+ # @return [nil]
91
+ #
92
+ def deprecate
93
+ client.deprecate_domain(:name => name)
94
+ nil
95
+ end
96
+ alias_method :delete, :deprecate
97
+
98
+ provider(:describe_domain) do |provider|
99
+ provider.provides *info_attributes.keys
100
+ provider.provides *config_attributes.keys
101
+ provider.find do |resp|
102
+ if resp.data['domainInfo']['name'] == name
103
+ resp.data['domainInfo'].merge(resp.data['configuration'])
104
+ end
105
+ end
106
+ end
107
+
108
+ provider(:list_domains) do |provider|
109
+ provider.provides *info_attributes.keys
110
+ provider.find do |resp|
111
+ resp.data['domainInfos'].find{|d| d['name'] == name }
112
+ end
113
+ end
114
+
115
+ protected
116
+ def resource_identifiers
117
+ [[:name,name]]
118
+ end
119
+
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,169 @@
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
+ # The primary interface for registerign, listing and deprecating
18
+ # domains.
19
+ #
20
+ # == Creating a Domain
21
+ #
22
+ # To create a domain you need to pass a unique name to #create.
23
+ #
24
+ # domain = simple_workflow.domains.create('my-domain', :none)
25
+ # #=> #<AWS::SimpleWorkflow::Domain name:my-domain>
26
+ #
27
+ # == Gettin a Domain
28
+ #
29
+ # Domains are indexed by their name.
30
+ #
31
+ # domain = simple_workflow.domains['my-domain']
32
+ #
33
+ # == Enumerating Domains
34
+ #
35
+ # You can call Enumerable methods on a domain collection to iterate
36
+ # the domains controlled by your account.
37
+ #
38
+ # simple_workflow.domains.each {|domain| ... }
39
+ #
40
+ # By default only registered domains are enumerated. If you would like
41
+ # to enumerate deprecated (deleted) domains you need to pass the
42
+ # +:deprecated+ option.
43
+ #
44
+ # # returns an array of names for all deprecated domains
45
+ # simple_workflow.domains.deprecated.map(&:name)
46
+ #
47
+ # See {AWS::Core::Collection} to see other useful methods you can
48
+ # call against a domain collection (e.g. #enum, #page, #each_batch).
49
+ #
50
+ class DomainCollection
51
+
52
+ include OptionFormatters
53
+ include Core::Collection::Limitable
54
+
55
+ def initialize options = {}
56
+
57
+ @registration_status = options[:registration_status] ?
58
+ options[:registration_status].to_s.upcase : 'REGISTERED'
59
+
60
+ @reverse_order = options.key?(:reverse_order) ?
61
+ !!options[:reverse_order] : false
62
+
63
+ super(options)
64
+
65
+ end
66
+
67
+ # Registers a new domain.
68
+ #
69
+ # # register a domain named 'domain' that has no expiry on workflow
70
+ # # execution history
71
+ # domain = AWS::SimpleWorkflow.new.domains.register('domain', :none)
72
+ #
73
+ # @param [String] name Name of the domain to register. The name must
74
+ # be unique.
75
+ #
76
+ # @param [Integer,:none] retention_period A duration (in days)
77
+ # for which the record (including the history) of workflow
78
+ # executions in this domain should be kept by the service.
79
+ # After the retention period, the workflow execution will not be
80
+ # available in the results of visibility calls.
81
+ #
82
+ # If you pass the symbol +:none+ then there is no expiration for
83
+ # workflow execution history (effectively an infinite rention
84
+ # period).
85
+ #
86
+ # @param [Hash] options
87
+ #
88
+ # @option [String] :description (nil) Textual description of the domain.
89
+ #
90
+ # @return [Domain] Returns the newly created {Domain} object.
91
+ #
92
+ def register name, retention_period, options = {}
93
+
94
+ client_opts = {}
95
+ client_opts[:name] = name
96
+ client_opts[:workflow_execution_retention_period_in_days] = retention_period
97
+ client_opts[:description] = options[:description] if options[:description]
98
+
99
+ duration_opts(client_opts, :workflow_execution_retention_period_in_days)
100
+ client.register_domain(client_opts)
101
+
102
+ client_opts[:retention_period] = retention_period.to_s =~ /^\d+$/ ?
103
+ retention_period.to_i : retention_period.to_s.downcase.to_sym
104
+
105
+ Domain.new(name, client_opts.merge(:config => config))
106
+
107
+ end
108
+ alias_method :create, :register
109
+
110
+ # @return [Domain] Returns the domain with the given name.
111
+ def [] name
112
+ Domain.new(name, :config => config)
113
+ end
114
+
115
+ # @return [DomainCollection] Returns a domain collection that
116
+ # will only enumerate registered domains.
117
+ def registered
118
+ collection_with(:registration_status => 'REGISTERED')
119
+ end
120
+
121
+ # @return [DomainCollection] Returns a domain collection that
122
+ # will only enumerate deprecated (deleted) domains.
123
+ def deprecated
124
+ collection_with(:registration_status => 'DEPRECATED')
125
+ end
126
+
127
+ # @return [DomainCollection] Returns a domain collection that
128
+ # enumerates domains in reverse alphabetical order. Default
129
+ # ordering is ascending alphabetical.
130
+ def reverse_order
131
+ collection_with(:reverse_order => true)
132
+ end
133
+
134
+ protected
135
+ def collection_with options = {}
136
+ self.class.new({
137
+ :registration_status => @registration_status,
138
+ :reverse_order => @reverse_order,
139
+ :config => config,
140
+ }.merge(options))
141
+ end
142
+
143
+ protected
144
+ def _each_item next_token, limit, options = {}, &block
145
+
146
+ options[:maximum_page_size] = limit if limit
147
+ options[:next_page_token] = next_token if next_token
148
+ options[:registration_status] ||= @registration_status
149
+ options[:reverse_order] = @reverse_order unless
150
+ options.has_key?(:reverse_order)
151
+
152
+ response = client.list_domains(options)
153
+ response.data['domainInfos'].each do |desc|
154
+
155
+ domain = Domain.new_from(:list_domains, desc,
156
+ desc['name'], :config => config)
157
+
158
+ yield(domain)
159
+
160
+ end
161
+
162
+ response.data['nextPageToken']
163
+
164
+ end
165
+
166
+ end
167
+
168
+ end
169
+ end