Class: Api::V2::JobInvocationsController

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

Instance Method Summary collapse

Instance Method Details

#cancelObject



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

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



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 72

def create
  if job_invocation_params[:feature].present?
    composer = composer_for_feature
  else
    validate_template
    composer = JobInvocationComposer.from_api_params(
      job_invocation_params
    )
  end
  composer.trigger!
  @job_invocation = composer.job_invocation
  process_response @job_invocation
end

#indexObject



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

def index
  @job_invocations = resource_scope_for_index
end

#outputObject



90
91
92
93
94
95
96
97
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 90

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

#raw_outputObject



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

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



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

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

#showObject



22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 22

def show
  @hosts = @job_invocation.targeting.hosts.authorized(:view_hosts, Host)
  @template_invocations = @job_invocation.template_invocations
                                         .where(host: @hosts)
                                         .includes(:input_values)

  if params[:host_status]
    template_invocations = @template_invocations.includes(:run_host_job_task).to_a
    @host_statuses = Hash[template_invocations.map { |ti| [ti.host_id, template_invocation_status(ti)] }]
  end
end