Class: Api::V2::JobInvocationsController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::V2::JobInvocationsController
- Includes:
- Api::Version2, Foreman::Renderer
- Defined in:
- app/controllers/api/v2/job_invocations_controller.rb
Instance Method Summary collapse
- #cancel ⇒ Object
- #create ⇒ Object
- #index ⇒ Object
- #output ⇒ Object
- #outputs ⇒ Object
- #raw_output ⇒ Object
- #rerun ⇒ Object
- #resource_name(resource = controller_name) ⇒ Object
- #show ⇒ Object
Instance Method Details
#cancel ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 129 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 |
#create ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 89 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. }) end |
#index ⇒ Object
15 16 17 |
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 15 def index @job_invocations = resource_scope_for_index end |
#output ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 105 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 |
#outputs ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 160 def outputs hosts = @job_invocation.targeting.hosts.(: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_output ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 117 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 |
#rerun ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 143 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
173 174 175 176 177 178 179 180 |
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 173 def resource_name(resource = controller_name) case resource when 'organization', 'location' nil else 'job_invocation' end end |
#show ⇒ Object
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.(:view_hosts, Host) @template_invocations = @job_invocation.template_invocations .where(host: @hosts) .includes(:input_values) if params[:host_status] == 'true' 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 |