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



104
105
106
107
108
109
110
111
112
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 104

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 => 422
  end
end

#createObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 62

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



80
81
82
83
84
85
86
87
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 80

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



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

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



117
118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 117

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 => 404
  end
end

#showObject



21
# File 'app/controllers/api/v2/job_invocations_controller.rb', line 21

def show; end