Class: JobInvocationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- JobInvocationsController
show all
- Includes:
- Foreman::Controller::AutoCompleteSearch, ForemanTasks::Concerns::Parameters::Triggering, JobInvocationsChartHelper, RemoteExecutionHelper
- Defined in:
- app/controllers/job_invocations_controller.rb
Instance Method Summary
collapse
#description_checkbox_f, #description_format_help, #description_format_textarea_f, #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
#job_invocation_cancelled_status, #job_invocation_chart, #job_invocation_data, #job_invocation_failed_status, #job_invocation_pending_status, #job_invocation_status, #job_invocation_success_status, #task_cancelled?, #task_failed?
Instance Method Details
#cancel ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'app/controllers/job_invocations_controller.rb', line 128
def cancel
@job_invocation = resource_base.find(params[:id])
result = @job_invocation.cancel(params[:force])
if result
flash[:info] = if params[:force]
_('Trying to abort the job')
else
_('Trying to cancel the job')
end
else
flash[:warning] = if params[:force]
_('The job cannot be aborted at the moment.')
else
_('The job cannot be cancelled at the moment.')
end
end
redirect_back(:fallback_location => job_invocation_path(@job_invocation))
end
|
#chart ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/controllers/job_invocations_controller.rb', line 89
def chart
find_resource
render :json => {
:finished => @job_invocation.finished?,
:job_invocations => job_invocation_data(@job_invocation)[:columns],
:statuses => {
:success => @job_invocation.progress_report[:success],
:cancelled => @job_invocation.progress_report[:cancelled],
:failed => @job_invocation.progress_report[:error],
:pending => @job_invocation.progress_report[:pending],
},
}
end
|
#create ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'app/controllers/job_invocations_controller.rb', line 54
def create
@composer = prepare_composer
if @composer.trigger
redirect_to job_invocation_path(@composer.job_invocation)
else
redirect_to new_job_invocation_path({:inputs => params[:inputs], :feature => params[:feature], :host_ids => params[:host_ids]})
end
end
|
#index ⇒ Object
79
80
81
|
# File 'app/controllers/job_invocations_controller.rb', line 79
def index
@job_invocations = resource_base_search_and_page.preload(:task, :targeting).order('job_invocations.id DESC')
end
|
#legacy_create ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'app/controllers/job_invocations_controller.rb', line 44
def legacy_create
@composer = prepare_composer
if @composer.trigger
redirect_to job_invocation_path(@composer.job_invocation)
else
@composer.job_invocation.description_format = nil if params.fetch(:job_invocation, {}).key?(:description_override)
render :action => 'new'
end
end
|
#new ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/job_invocations_controller.rb', line 7
def new
return @composer = prepare_composer if params[:feature].present?
ui_params = {
:host_ids => params[:host_ids],
:targeting => {
:targeting_type => Targeting::STATIC_TYPE,
:bookmark_id => params[:bookmark_id],
},
}
if params.key?(:search)
query = params[:search].empty? ? "name != ''" : params[:search]
ui_params[:targeting].update(:search_query => query)
end
if (template = JobTemplate.find_by(id: params[:template_id]))
ui_params[:job_invocation] = {
:job_category => template.job_category,
:providers => {
template.provider_type => {:job_template_id => template.id},
},
}
end
@composer = JobInvocationComposer.from_ui_params(ui_params)
end
|
#preview_hosts ⇒ Object
103
104
105
106
107
108
109
110
111
112
|
# File 'app/controllers/job_invocations_controller.rb', line 103
def preview_hosts
composer = prepare_composer
@hosts = composer.targeted_hosts.limit(Setting[:entries_per_page])
@additional = composer.targeted_hosts.count - Setting[:entries_per_page]
@dynamic = composer.targeting.dynamic?
@query = composer.displayed_search_query
render :partial => 'job_invocations/preview_hosts_list'
end
|
#preview_job_invocations_per_host ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'app/controllers/job_invocations_controller.rb', line 148
def preview_job_invocations_per_host
job_invocations = resource_base.search_for("targeted_host_id = #{params[:host_id]} and (status=#{params[:status]})").limit(params[:limit] || 3)
job_invocations = job_invocations.map do |job|
@job_invocation = job
template_invocation = job.template_invocations.find { |template_inv| template_inv.host_id == params[:host_id].to_i }
task = template_invocation.try(:run_host_job_task)
status_mapper = task ? HostStatus::ExecutionStatus::ExecutionTaskStatusMapper.new(task) : job
{
start_at: job.start_at,
description: job.description,
id: job.id,
status: status_mapper.status,
status_label: status_mapper.status_label,
}
end
render :json => {:job_invocations => job_invocations}
end
|
#refresh ⇒ Object
84
85
86
87
|
# File 'app/controllers/job_invocations_controller.rb', line 84
def refresh
params[:job_invocation].delete :description_format if params[:job_invocation].key?(:description_override)
@composer = prepare_composer
end
|
#report ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'app/controllers/job_invocations_controller.rb', line 114
def report
@job_invocation = resource_base.find(params[:id])
template = job_report_template
unless template
return not_found(_('Report template not found or not configured properly'))
end
unless ReportTemplate.authorized(:generate_report_templates).find_by(:id => template.id)
return render_403(_('Missing permissions to generate report templates'))
end
redirect_to generate_report_template_path(template, job_report_template_parameters(@job_invocation, template))
end
|
#rerun ⇒ Object
36
37
38
39
40
41
42
|
# File 'app/controllers/job_invocations_controller.rb', line 36
def rerun
job_invocation = resource_base.find(params[:id])
@composer = JobInvocationComposer.from_job_invocation(job_invocation, params)
@job_organization = Taxonomy.find_by(id: job_invocation.task.input[:current_organization_id])
@job_location = Taxonomy.find_by(id: job_invocation.task.input[:current_location_id])
render :action => 'new'
end
|
#show ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/controllers/job_invocations_controller.rb', line 63
def show
@job_invocation = resource_base.includes(:template_invocations => :run_host_job_task).find(params[:id])
@job_organization = Taxonomy.find_by(id: @job_invocation.task.input[:current_organization_id])
@job_location = Taxonomy.find_by(id: @job_invocation.task.input[:current_location_id])
@auto_refresh = @job_invocation.task.try(:pending?)
respond_to do |format|
format.json do
targeting_hosts_resources
end
format.html
format.js
end
end
|