Class: Api::V2::JobInvocationsController

Inherits:
BaseController
  • Object
show all
Includes:
Api::Version2, Foreman::Renderer, RemoteExecutionHelper
Defined in:
app/controllers/api/v2/job_invocations_controller.rb

Instance Method Summary collapse

Methods included from RemoteExecutionHelper

#description_checkbox_f, #description_format_help, #description_format_textarea_f, #documentation_button_rex, #host_counter, #host_tasks_authorizer, #invocation_count, #invocation_description, #invocation_result, #job_hosts_authorizer, #job_invocation_task_buttons, #job_invocations_buttons, #job_report_template, #job_report_template_parameters, #link_to_invocation_task_if_authorized, #load_template_from_task, #normalize_line_sets, #preview_box, #providers_options, #remote_execution_provider_for, #targeting_hosts, #template_invocation_actions, #template_invocation_status, #template_invocation_task_buttons, #time_in_words_span

Instance Method Details

#cancelObject



138
139
140
141
142
143
144
145
146
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 138

def cancel
  if @job_invocation.task.cancellable?
    result = @job_invocation.cancel(params.fetch('force', false))
    render :json => { :cancelled => result, :id => @job_invocation.id }
  else
    render :json => { :message => _('The job could not be cancelled.') },
      :status => :unprocessable_entity
  end
end

#createObject



85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 85

def create
  composer = JobInvocationComposer.from_api_params(
    job_invocation_params
  )
  composer.trigger!
  @job_invocation = composer.job_invocation
  @hosts = @job_invocation.targeting.hosts
  process_response @job_invocation
rescue JobInvocationComposer::JobTemplateNotFound, JobInvocationComposer::FeatureNotFound => e
  not_found(error: { message: e.message })
end

#hostsObject



114
115
116
117
118
119
120
121
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 114

def hosts
  set_hosts_and_template_invocations
  set_statuses_and_smart_proxies
  @total = @job_invocation.targeting.hosts.size
  @hosts = @hosts.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page], :per_page => params[:per_page])
  @subtotal = @hosts.respond_to?(:total_entries) ? @hosts.total_entries : @hosts.sizes
  render :hosts, :layout => 'api/v2/layouts/index_layout'
end

#indexObject



16
17
18
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 16

def index
  @job_invocations = resource_scope_for_index
end

#outputObject



101
102
103
104
105
106
107
108
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 101

def output
  if @nested_obj.task.scheduled?
    render :json => delayed_task_output(@nested_obj.task, :default => [])
    return
  end

  render :json => host_output(@nested_obj, @host, :default => [], :since => params[:since])
end

#outputsObject



169
170
171
172
173
174
175
176
177
178
179
180
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 169

def outputs
  hosts = @job_invocation.targeting.hosts.authorized(:view_hosts, Host)
  hosts = hosts.search_for(params['search_query']) if params['search_query']
  raw = ActiveRecord::Type::Boolean.new.cast params['raw']
  default_value = raw ? '' : []
  outputs = hosts.map do |host|
    host_output(@job_invocation, host, :default => default_value, :since => params['since'], :raw => raw)
      .merge(host_id: host.id)
  end

  render :json => { :outputs => outputs }
end

#raw_outputObject



126
127
128
129
130
131
132
133
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 126

def raw_output
  if @nested_obj.task.scheduled?
    render :json => delayed_task_output(@nested_obj.task)
    return
  end

  render :json => host_output(@nested_obj, @host, :raw => true)
end

#rerunObject



152
153
154
155
156
157
158
159
160
161
162
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 152

def rerun
  composer = JobInvocationComposer.from_job_invocation(@job_invocation, params)
  if composer.rerun_possible?
    composer.trigger!
    @job_invocation = composer.job_invocation
    process_response @job_invocation
  else
    render :json => { :error => _('Could not rerun job %{id} because its template could not be found') % { :id => composer.reruns } },
      :status => :not_found
  end
end

#resource_name(resource = controller_name) ⇒ Object



182
183
184
185
186
187
188
189
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 182

def resource_name(resource = controller_name)
  case resource
  when 'organization', 'location'
    nil
  else
    'job_invocation'
  end
end

#showObject



23
24
25
26
27
28
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 23

def show
  set_hosts_and_template_invocations
  if params[:host_status] == 'true'
    set_statuses_and_smart_proxies
  end
end