Class: Actions::ProxyAction
- Inherits:
-
Base
- Object
- Dynflow::Action
- Base
- Actions::ProxyAction
show all
- Includes:
- Dynflow::Action::Cancellable
- Defined in:
- app/lib/actions/proxy_action.rb
Defined Under Namespace
Classes: CallbackData, ProxyActionMissing, ProxyActionStopped
Instance Method Summary
collapse
Methods inherited from Base
#already_running?, #humanized_errors, #humanized_input, #humanized_name, #humanized_output, #notify_paused, #serializer_class, #task, #task_input, #task_output
included, #log_task_state_change
Instance Method Details
#abort_proxy_task ⇒ Object
109
110
111
112
|
# File 'app/lib/actions/proxy_action.rb', line 109
def abort_proxy_task
proxy.cancel_task(proxy_task_id)
error! ForemanTasks::Task::TaskCancelledException.new(_('Task aborted: the task might be still running on the proxy'))
end
|
#cancel_proxy_task ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'app/lib/actions/proxy_action.rb', line 99
def cancel_proxy_task
if output[:cancel_sent]
error! ForemanTasks::Task::TaskCancelledException.new(_('Cancel enforced: the task might be still running on the proxy'))
else
proxy.cancel_task(proxy_task_id)
output[:cancel_sent] = true
suspend
end
end
|
#check_task_status ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/lib/actions/proxy_action.rb', line 86
def check_task_status
response = proxy.status_of_task(proxy_task_id)
if %w[stopped paused].include? response['state']
if response['result'] == 'error'
raise ::Foreman::Exception, _('The smart proxy task %s failed.') % proxy_task_id
else
on_data(get_proxy_data(response))
end
else
suspend
end
end
|
#clean_remote_task(*_args) ⇒ Object
201
202
203
|
# File 'app/lib/actions/proxy_action.rb', line 201
def clean_remote_task(*_args)
remote_task.destroy! if remote_task
end
|
#default_connection_options ⇒ Object
188
189
190
191
192
193
194
|
# File 'app/lib/actions/proxy_action.rb', line 188
def default_connection_options
{ :retry_interval => Setting['foreman_tasks_proxy_action_retry_interval'] || 15,
:retry_count => Setting['foreman_tasks_proxy_action_retry_count'] || 4,
:proxy_batch_triggering => Setting['foreman_tasks_proxy_batch_trigger'] || false }
end
|
#fill_continuous_output(continuous_output) ⇒ Object
The proxy action is able to contribute to continuous output
166
167
168
169
170
171
172
|
# File 'app/lib/actions/proxy_action.rb', line 166
def fill_continuous_output(continuous_output)
failed_proxy_tasks.each do |failure_data|
message = _('Initialization error: %s') %
"#{failure_data[:exception_class]} - #{failure_data[:exception_message]}"
continuous_output.add_output(message, 'debug', failure_data[:timestamp])
end
end
|
178
179
180
181
|
# File 'app/lib/actions/proxy_action.rb', line 178
def metadata
output[:metadata] ||= {}
output[:metadata]
end
|
183
184
185
186
|
# File 'app/lib/actions/proxy_action.rb', line 183
def metadata=(thing)
output[:metadata] ||= {}
output[:metadata] = thing
end
|
#on_data(data, meta = {}) ⇒ Object
120
121
122
123
|
# File 'app/lib/actions/proxy_action.rb', line 120
def on_data(data, meta = {})
action_logger.info(_('Event delivered by request %{request_id}') % { :request_id => meta[:request_id] }) if meta[:request_id].present?
output[:proxy_output] = data
end
|
#on_proxy_action_missing ⇒ Object
132
133
134
|
# File 'app/lib/actions/proxy_action.rb', line 132
def on_proxy_action_missing
error! ProxyActionMissing.new(_('Proxy task gone missing from the smart proxy'))
end
|
#on_proxy_action_stopped ⇒ Object
136
137
138
|
# File 'app/lib/actions/proxy_action.rb', line 136
def on_proxy_action_stopped
check_task_status
end
|
#on_resume ⇒ Object
114
115
116
117
|
# File 'app/lib/actions/proxy_action.rb', line 114
def on_resume
suspend
end
|
#plan(proxy, klass, options) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/lib/actions/proxy_action.rb', line 27
def plan(proxy, klass, options)
options[:connection_options] ||= {}
default_connection_options.each do |key, value|
options[:connection_options][key] = value unless options[:connection_options].key?(key)
end
plan_self(options.merge(:proxy_url => proxy.url, :proxy_action_name => klass.to_s, :proxy_version => proxy_version(proxy)))
if input[:use_batch_triggering] && with_batch_triggering?(input[:proxy_version])
prepare_remote_task.save!
end
end
|
#proxy_action_name ⇒ Object
141
142
143
|
# File 'app/lib/actions/proxy_action.rb', line 141
def proxy_action_name
input[:proxy_action_name]
end
|
81
82
83
84
|
# File 'app/lib/actions/proxy_action.rb', line 81
def proxy_input(task_id = task.id)
input.merge(:callback => { :task_id => task_id,
:step_id => run_step_id })
end
|
#proxy_operation_name ⇒ Object
146
147
148
|
# File 'app/lib/actions/proxy_action.rb', line 146
def proxy_operation_name
input[:proxy_operation_name]
end
|
#proxy_output(live = false) ⇒ Object
154
155
156
157
158
159
160
161
162
163
|
# File 'app/lib/actions/proxy_action.rb', line 154
def proxy_output(live = false)
if output.key?(:proxy_output) || state == :error
output.fetch(:proxy_output, {})
elsif live && proxy_task_id
response = proxy.status_of_task(proxy_task_id)
get_proxy_data(response)
else
{}
end
end
|
#proxy_output=(output) ⇒ Object
174
175
176
|
# File 'app/lib/actions/proxy_action.rb', line 174
def proxy_output=(output)
output[:proxy_output] = output
end
|
#remote_task ⇒ Object
63
64
65
|
# File 'app/lib/actions/proxy_action.rb', line 63
def remote_task
@remote_task ||= ForemanTasks::RemoteTask.find_by(:execution_plan_id => execution_plan_id, :step_id => run_step_id)
end
|
#run(event = nil) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/lib/actions/proxy_action.rb', line 40
def run(event = nil)
with_connection_error_handling(event) do |event|
case event
when nil
start_or_resume
when ::Dynflow::Action::Skip
when ::Dynflow::Action::Cancellable::Cancel
cancel_proxy_task
when ::Dynflow::Action::Cancellable::Abort
abort_proxy_task
when CallbackData
on_data(event.data, event.meta)
when ProxyActionMissing
on_proxy_action_missing
when ProxyActionStopped
on_proxy_action_stopped
else
raise "Unexpected event #{event.inspect}"
end
end
end
|
#trigger_proxy_task ⇒ Object
67
68
69
70
71
72
73
|
# File 'app/lib/actions/proxy_action.rb', line 67
def trigger_proxy_task
suspend do |_suspended_action|
remote_task = prepare_remote_task
remote_task.trigger(proxy_action_name, proxy_input)
output[:proxy_task_id] = remote_task.remote_task_id
end
end
|
#trigger_remote_task ⇒ Object
75
76
77
78
79
|
# File 'app/lib/actions/proxy_action.rb', line 75
def trigger_remote_task
suspend do |_suspended_action|
ForemanTasks::RemoteTask.batch_trigger(remote_task.operation, [remote_task])
end
end
|
#wipe_secrets!(_execution_plan) ⇒ Object
Removes the :secrets key from the action's input and output and saves the action
126
127
128
129
130
|
# File 'app/lib/actions/proxy_action.rb', line 126
def wipe_secrets!(_execution_plan)
input.delete(:secrets)
output.delete(:secrets)
world.persistence.save_action(execution_plan_id, self)
end
|
#with_batch_triggering?(proxy_version) ⇒ Boolean
196
197
198
199
|
# File 'app/lib/actions/proxy_action.rb', line 196
def with_batch_triggering?(proxy_version)
((proxy_version[:major] == 1 && proxy_version[:minor] > 20) || proxy_version[:major] > 1) &&
input.fetch(:connection_options, {}).fetch(:proxy_batch_triggering, false)
end
|