naf 1.1.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -2
- data/app/assets/images/{papertrail_job.png → job.png} +0 -0
- data/app/assets/images/{papertrail_machine.png → machine.png} +0 -0
- data/app/assets/images/{papertrail_machine_runner.png → machine_runner.png} +0 -0
- data/app/assets/javascripts/col_reorder_with_resize.js +1228 -0
- data/app/assets/javascripts/dataTablesTemplates/applications.js +2 -1
- data/app/assets/javascripts/dataTablesTemplates/jobs.js +2 -1
- data/app/assets/javascripts/dataTablesTemplates/machine_runner_invocations.js +2 -1
- data/app/assets/javascripts/dataTablesTemplates/machine_runners.js +2 -1
- data/app/assets/javascripts/dataTablesTemplates/machines.js +2 -1
- data/app/assets/javascripts/jquery.dataTables.js +10339 -5103
- data/app/assets/javascripts/naf.js +1 -0
- data/app/assets/stylesheets/jquery_ui/jquery-ui-1.8.5.custom.css.erb +6 -6
- data/app/assets/stylesheets/min_naf/layout.css.scss +94 -43
- data/app/assets/stylesheets/naf/layout.css.scss +94 -43
- data/app/controllers/naf/affinities_controller.rb +1 -1
- data/app/controllers/naf/applications_controller.rb +3 -0
- data/app/controllers/naf/historical_job_affinity_tabs_controller.rb +1 -1
- data/app/controllers/naf/historical_jobs_controller.rb +2 -5
- data/app/controllers/naf/log_parsers_controller.rb +16 -0
- data/app/controllers/naf/log_viewer_controller.rb +19 -0
- data/app/controllers/naf/machine_affinity_slots_controller.rb +1 -1
- data/app/controllers/naf/machine_runners_controller.rb +12 -0
- data/app/controllers/naf/machines_controller.rb +8 -10
- data/app/controllers/naf/status_controller.rb +12 -0
- data/app/helpers/naf/application_helper.rb +19 -38
- data/app/helpers/naf/time_helper.rb +37 -0
- data/app/models/logical/naf/application.rb +13 -19
- data/app/models/logical/naf/construction_zone/boss.rb +1 -1
- data/app/models/logical/naf/construction_zone/foreman.rb +1 -1
- data/app/models/logical/naf/job.rb +39 -34
- data/app/models/logical/naf/job_creator.rb +19 -23
- data/app/models/logical/naf/job_fetcher.rb +36 -6
- data/app/models/logical/naf/log_file.rb +70 -0
- data/app/models/logical/naf/log_parser/base.rb +272 -0
- data/app/models/logical/naf/log_parser/job.rb +65 -0
- data/app/models/logical/naf/log_parser/machine.rb +64 -0
- data/app/models/logical/naf/log_parser/runner.rb +72 -0
- data/app/models/logical/naf/log_reader.rb +85 -0
- data/app/models/logical/naf/machine.rb +39 -1
- data/app/models/naf/affinity.rb +18 -0
- data/app/models/naf/application_schedule_affinity_tab.rb +1 -0
- data/app/models/naf/application_type.rb +2 -1
- data/app/models/naf/historical_job.rb +9 -29
- data/app/models/naf/machine.rb +8 -0
- data/app/models/naf/machine_runner.rb +11 -2
- data/app/models/naf/machine_runner_invocation.rb +9 -1
- data/app/models/naf/running_job.rb +40 -1
- data/app/models/process/naf/application.rb +3 -3
- data/app/models/process/naf/log_archiver.rb +78 -0
- data/app/models/process/naf/machine_manager.rb +3 -1
- data/app/models/process/naf/runner.rb +286 -162
- data/app/models/process/naf/runner_log.rb +26 -0
- data/app/views/naf/application_schedule_affinity_tabs/_form.html.erb +1 -5
- data/app/views/naf/applications/show.html.erb +1 -1
- data/app/views/naf/historical_job_affinity_tabs/_form.html.erb +1 -5
- data/app/views/naf/historical_jobs/_form.html.erb +1 -1
- data/app/views/naf/historical_jobs/_runners.html.erb +21 -12
- data/app/views/naf/historical_jobs/_search_container.html.erb +1 -2
- data/app/views/naf/historical_jobs/index.html.erb +0 -1
- data/app/views/naf/historical_jobs/index.json.erb +4 -4
- data/app/views/naf/historical_jobs/show.html.erb +57 -51
- data/app/views/naf/log_viewer/_job_logs.html.erb +65 -0
- data/app/views/naf/log_viewer/_log_display.html.erb +259 -0
- data/app/views/naf/log_viewer/_log_layout.html.erb +59 -0
- data/app/views/naf/log_viewer/_machine_logs.html.erb +62 -0
- data/app/views/naf/log_viewer/_runner_logs.html.erb +62 -0
- data/app/views/naf/log_viewer/_search_options.html.erb +36 -0
- data/app/views/naf/log_viewer/_update_page_title.html.erb +9 -0
- data/app/views/naf/log_viewer/index.html.erb +1 -0
- data/app/views/naf/logger_names/_form.html.erb +1 -2
- data/app/views/naf/machine_affinity_slots/_form.html.erb +1 -5
- data/app/views/naf/machine_runner_invocations/show.html.erb +4 -0
- data/app/views/naf/machine_runners/show.html.erb +44 -34
- data/app/views/naf/machines/index.json.erb +14 -6
- data/app/views/naf/machines/show.html.erb +44 -40
- data/app/views/naf/shared/_auto_resize_width.html.erb +7 -0
- data/app/views/naf/shared/_date_select.html.erb +65 -0
- data/app/views/naf/shared/_select_per_page.html.erb +48 -13
- data/app/views/naf/status/index.html.erb +27 -0
- data/bin/naf +26 -0
- data/config/initializers/naf.rb +13 -1
- data/config/routes.rb +16 -2
- data/db/migrate/20131106162436_add_uuid_column_to_machine_runner_invocations.rb +15 -0
- data/db/migrate/20131121185222_move_tabs_column_from_historical_jobs_to_running_jobs.rb +15 -0
- data/lib/generators/templates/config/logging/naf.yml +0 -8
- data/lib/generators/templates/config/logging/nafjob.yml +0 -8
- data/lib/generators/templates/config/logging/nafrunner.yml +0 -8
- data/lib/generators/templates/naf.rb +0 -8
- data/lib/naf.rb +0 -8
- data/lib/naf/configuration.rb +0 -4
- data/lib/naf/version.rb +1 -1
- data/lib/tasks/naf_tasks.rake +18 -0
- data/naf.gemspec +3 -1
- data/spec/controllers/naf/affinities_controller_spec.rb +0 -1
- data/spec/controllers/naf/applications_controller_spec.rb +3 -2
- data/spec/controllers/naf/machine_affinity_slots_controller_spec.rb +0 -1
- data/spec/controllers/naf/machines_controller_spec.rb +1 -1
- data/spec/dummy/config/logging/naf.yml +0 -8
- data/spec/dummy/config/logging/nafjob.yml +0 -9
- data/spec/dummy/config/logging/nafrunner.yml +0 -10
- data/spec/factories/naf.rb +4 -0
- data/spec/models/logical/naf/application_spec.rb +3 -4
- data/spec/models/logical/naf/job_creator_spec.rb +91 -21
- data/spec/models/logical/naf/job_spec.rb +19 -6
- data/spec/models/logical/naf/log_file_spec.rb +105 -0
- data/spec/models/logical/naf/machine_runner_invocation_spec.rb +41 -0
- data/spec/models/logical/naf/machine_runner_spec.rb +42 -0
- data/spec/models/logical/naf/machine_spec.rb +98 -28
- data/spec/models/naf/affinity_classification_spec.rb +20 -0
- data/spec/models/naf/affinity_spec.rb +21 -0
- data/spec/models/naf/historical_job_spec.rb +2 -44
- data/spec/models/naf/machine_runner_invocation_spec.rb +17 -1
- data/spec/models/naf/running_job_spec.rb +64 -1
- metadata +40 -9
- data/app/models/log4r/papertrail_outputter.rb +0 -19
- data/app/views/naf/historical_jobs/edit.html.erb +0 -11
- data/app/views/naf/machines/_show.html.erb +0 -169
|
@@ -44,8 +44,11 @@ module Naf
|
|
|
44
44
|
|
|
45
45
|
def create
|
|
46
46
|
@application = Naf::Application.new(params[:application])
|
|
47
|
+
check_application_run_group_name
|
|
48
|
+
set_application_run_group_name
|
|
47
49
|
if @application.save
|
|
48
50
|
app_schedule = @application.application_schedule
|
|
51
|
+
@application.update_attributes(params[:application])
|
|
49
52
|
if app_schedule.present?
|
|
50
53
|
prerequisites =
|
|
51
54
|
app_schedule.prerequisites.map do |prerequisite|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module Naf
|
|
2
2
|
class HistoricalJobsController < Naf::ApplicationController
|
|
3
3
|
include Naf::ApplicationHelper
|
|
4
|
+
helper Naf::TimeHelper
|
|
4
5
|
|
|
5
6
|
before_filter :set_rows_per_page
|
|
6
7
|
before_filter :set_search_status
|
|
@@ -102,10 +103,6 @@ module Naf
|
|
|
102
103
|
end
|
|
103
104
|
end
|
|
104
105
|
|
|
105
|
-
def edit
|
|
106
|
-
@historical_job = Naf::HistoricalJob.find(params[:id])
|
|
107
|
-
end
|
|
108
|
-
|
|
109
106
|
def update
|
|
110
107
|
respond_to do |format|
|
|
111
108
|
@historical_job = Naf::HistoricalJob.find(params[:id])
|
|
@@ -119,6 +116,7 @@ module Naf
|
|
|
119
116
|
|
|
120
117
|
if running_job = ::Naf::RunningJob.find_by_id(params[:id])
|
|
121
118
|
running_job.update_attributes(request_to_terminate: true)
|
|
119
|
+
@historical_job.update_attributes(request_to_terminate: true)
|
|
122
120
|
end
|
|
123
121
|
end
|
|
124
122
|
|
|
@@ -150,7 +148,6 @@ module Naf
|
|
|
150
148
|
else
|
|
151
149
|
hash[:application_url] = nil
|
|
152
150
|
end
|
|
153
|
-
hash[:papertrail_url] = naf_papertrail_link(job)
|
|
154
151
|
|
|
155
152
|
return hash
|
|
156
153
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Naf
|
|
2
|
+
class LogParsersController < Naf::ApplicationController
|
|
3
|
+
|
|
4
|
+
def logs
|
|
5
|
+
response = params['logical_type'].constantize.new(params).logs
|
|
6
|
+
if response.present?
|
|
7
|
+
success = true
|
|
8
|
+
else
|
|
9
|
+
success = false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
render json: "convertToJsonCallback(" + { success: success }.merge(response).to_json + ")"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Naf
|
|
2
|
+
class LogViewerController < Naf::ApplicationController
|
|
3
|
+
|
|
4
|
+
def index
|
|
5
|
+
if params['record_type'] == 'job'
|
|
6
|
+
@job = ::Naf::HistoricalJob.find_by_id(params['record_id'].to_i)
|
|
7
|
+
@status = ::Logical::Naf::Job.new(@job).status
|
|
8
|
+
@partial = 'job_logs'
|
|
9
|
+
elsif params['record_type'] == 'machine'
|
|
10
|
+
@machine = ::Naf::Machine.find_by_id(params['record_id'].to_i)
|
|
11
|
+
@partial = 'machine_logs'
|
|
12
|
+
elsif params['record_type'] == 'runner'
|
|
13
|
+
@runner = ::Naf::MachineRunner.find_by_id(params['record_id'].to_i)
|
|
14
|
+
@partial = 'runner_logs'
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -6,7 +6,7 @@ module Naf
|
|
|
6
6
|
def index
|
|
7
7
|
@rows = []
|
|
8
8
|
if params[:machine_id]
|
|
9
|
-
@rows = Naf::MachineAffinitySlot.where(machine_id: params[:machine_id])
|
|
9
|
+
@rows = Naf::MachineAffinitySlot.includes(:machine, :affinity).where(machine_id: params[:machine_id])
|
|
10
10
|
end
|
|
11
11
|
render template: 'naf/datatable'
|
|
12
12
|
end
|
|
@@ -22,5 +22,17 @@ module Naf
|
|
|
22
22
|
@machine_runner = Naf::MachineRunner.find(params[:id])
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
def runner_count
|
|
26
|
+
running = ::Naf::MachineRunner.running.uniq.count
|
|
27
|
+
winding_down = ::Naf::MachineRunner.winding_down.uniq.count
|
|
28
|
+
down = ::Naf::MachineRunner.dead_count
|
|
29
|
+
|
|
30
|
+
render json: {
|
|
31
|
+
running: running,
|
|
32
|
+
winding_down: winding_down,
|
|
33
|
+
down: down
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
25
37
|
end
|
|
26
38
|
end
|
|
@@ -2,6 +2,7 @@ module Naf
|
|
|
2
2
|
class MachinesController < Naf::ApplicationController
|
|
3
3
|
|
|
4
4
|
include Naf::ApplicationHelper
|
|
5
|
+
include Naf::TimeHelper
|
|
5
6
|
|
|
6
7
|
before_filter :set_rows_per_page
|
|
7
8
|
|
|
@@ -21,7 +22,7 @@ module Naf
|
|
|
21
22
|
machine = []
|
|
22
23
|
@total_records = Naf::Machine.count(:all)
|
|
23
24
|
Logical::Naf::Machine.all(filter).map(&:to_hash).map do |hash|
|
|
24
|
-
|
|
25
|
+
hash.map do |key, value|
|
|
25
26
|
value = '' if value.nil?
|
|
26
27
|
machine << value
|
|
27
28
|
end
|
|
@@ -36,7 +37,7 @@ module Naf
|
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def show
|
|
39
|
-
@machine = Naf::Machine.find(params[:id])
|
|
40
|
+
@machine = Naf::Machine.includes(:machine_affinity_slots).find(params[:id])
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
def new
|
|
@@ -81,15 +82,12 @@ module Naf
|
|
|
81
82
|
end
|
|
82
83
|
end
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
hash[:papertrail_url] = naf_papertrail_link(machine)
|
|
89
|
-
hash[:papertrail_runner_url] = naf_papertrail_link(machine, true)
|
|
90
|
-
|
|
91
|
-
hash
|
|
85
|
+
def last_checked_schedule_at
|
|
86
|
+
render json: {
|
|
87
|
+
last_checked_schedule_at: time_format(::Naf::Machine.last_time_schedules_were_checked)
|
|
88
|
+
}
|
|
92
89
|
end
|
|
93
90
|
|
|
91
|
+
|
|
94
92
|
end
|
|
95
93
|
end
|
|
@@ -20,16 +20,17 @@ module Naf
|
|
|
20
20
|
NAF_READ_ONLY_RESOURCES = []
|
|
21
21
|
NAF_CREATE_BLOCKED_RESOURCES = []
|
|
22
22
|
NAF_ALL_VISIBLE_RESOURCES = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
'historical_jobs' => '',
|
|
24
|
+
'applications' => '',
|
|
25
|
+
'machines' => '',
|
|
26
|
+
'runners' => ['machine_runners',
|
|
27
|
+
'machine_runner_invocations'],
|
|
28
|
+
'affinities' => '',
|
|
29
|
+
'loggers' => ['logger_styles', 'logger_names'],
|
|
30
|
+
'janitorial_assignments' => ['janitorial_archive_assignments',
|
|
31
|
+
'janitorial_create_assignments',
|
|
32
|
+
'janitorial_drop_assignments'],
|
|
33
|
+
'status' => ''
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
def naf_tabs
|
|
@@ -221,34 +222,6 @@ module Naf
|
|
|
221
222
|
end
|
|
222
223
|
end
|
|
223
224
|
|
|
224
|
-
def include_actions_in_table?
|
|
225
|
-
current_page?(naf.root_url) or
|
|
226
|
-
current_page?(controller: 'applications', action: 'index') or
|
|
227
|
-
current_page?(controller: 'historical_jobs', action: 'index')
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
def naf_papertrail_link(record, runner = false)
|
|
231
|
-
if group_id = Naf.papertrail_group_id
|
|
232
|
-
url = "http://www.papertrailapp.com/groups/#{group_id}/events"
|
|
233
|
-
if record.kind_of?(::Naf::HistoricalJob) || record.kind_of?(::Logical::Naf::Job)
|
|
234
|
-
if record.pid.present?
|
|
235
|
-
query = "jid(#{record.id})"
|
|
236
|
-
url << "?q=#{CGI.escape(query)}"
|
|
237
|
-
end
|
|
238
|
-
elsif record.kind_of?(::Naf::Machine) || record.kind_of?(::Logical::Naf::Machine)
|
|
239
|
-
query = record.server_name
|
|
240
|
-
unless query.nil?
|
|
241
|
-
query << " runner" if runner
|
|
242
|
-
url << "?q=#{CGI.escape(query)}"
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
else
|
|
246
|
-
url = "http://www.papertrailapp.com/dashboard"
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
return url
|
|
250
|
-
end
|
|
251
|
-
|
|
252
225
|
def naf_link_to_remove_fields(name, f)
|
|
253
226
|
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
|
|
254
227
|
end
|
|
@@ -271,5 +244,13 @@ module Naf
|
|
|
271
244
|
end
|
|
272
245
|
end
|
|
273
246
|
|
|
247
|
+
def http_protocol
|
|
248
|
+
if ['staging', 'production'].include?(Rails.env)
|
|
249
|
+
'https://'
|
|
250
|
+
else
|
|
251
|
+
'http://'
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
274
255
|
end
|
|
275
256
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Naf
|
|
2
|
+
module TimeHelper
|
|
3
|
+
|
|
4
|
+
def time_difference(value, started_at = nil)
|
|
5
|
+
seconds = value % 60
|
|
6
|
+
value = (value - seconds) / 60
|
|
7
|
+
minutes = value % 60
|
|
8
|
+
value = (value - minutes) / 60
|
|
9
|
+
hours = value % 24
|
|
10
|
+
value = (value - hours) / 24
|
|
11
|
+
days = value % 7
|
|
12
|
+
more_hours = hours + days * 24 if days > 0
|
|
13
|
+
|
|
14
|
+
if started_at.present?
|
|
15
|
+
"-#{hours.to_i + more_hours.to_i}h#{minutes.to_i}m, #{started_at.localtime.strftime("%Y-%m-%d %r")}"
|
|
16
|
+
else
|
|
17
|
+
if days < 2
|
|
18
|
+
"-#{hours.to_i + more_hours.to_i}h#{minutes.to_i}m#{seconds.to_i}s"
|
|
19
|
+
else
|
|
20
|
+
"-#{days.to_i}d#{hours.to_i}h#{minutes.to_i}m#{seconds.to_i}s"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def time_format(time)
|
|
26
|
+
return '' if time.nil?
|
|
27
|
+
|
|
28
|
+
value = Time.zone.now - time
|
|
29
|
+
if value < 60
|
|
30
|
+
return "#{value.to_i} seconds ago"
|
|
31
|
+
else
|
|
32
|
+
return time_difference(value)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -54,9 +54,11 @@ module Logical
|
|
|
54
54
|
if search.present? and search[field].present?
|
|
55
55
|
application_scope =
|
|
56
56
|
if field == :application_run_group_name
|
|
57
|
-
application_scope.where(
|
|
57
|
+
application_scope.where(
|
|
58
|
+
["lower(#{::Naf.schema_name}.application_schedules.application_run_group_name) ~ ?", Regexp.escape(search[field].downcase)]
|
|
59
|
+
)
|
|
58
60
|
else
|
|
59
|
-
application_scope.where(["lower(#{field}) ~ ?", search[field].downcase])
|
|
61
|
+
application_scope.where(["lower(#{field}) ~ ?", Regexp.escape(search[field].downcase)])
|
|
60
62
|
end
|
|
61
63
|
end
|
|
62
64
|
end
|
|
@@ -157,25 +159,17 @@ module Logical
|
|
|
157
159
|
end
|
|
158
160
|
|
|
159
161
|
def affinities
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
else
|
|
168
|
-
affinity_tabs << tab.affinity.affinity_name
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
if tab.affinity_parameter.present? && tab.affinity_parameter > 0
|
|
172
|
-
affinity_tabs << "(#{tab.affinity_parameter}), "
|
|
162
|
+
@app.application_schedule.application_schedule_affinity_tabs.map do |tab|
|
|
163
|
+
if tab.affinity_short_name.present?
|
|
164
|
+
if tab.affinity_parameter.present? && tab.affinity_parameter > 0
|
|
165
|
+
tab.affinity_short_name + "(#{tab.affinity_parameter})"
|
|
166
|
+
else
|
|
167
|
+
tab.affinity_short_name
|
|
168
|
+
end
|
|
173
169
|
else
|
|
174
|
-
|
|
170
|
+
tab.affinity_classification_name + '_' + tab.affinity_name
|
|
175
171
|
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
affinity_tabs[0..-3]
|
|
172
|
+
end.join(", \n")
|
|
179
173
|
end
|
|
180
174
|
|
|
181
175
|
end
|
|
@@ -87,7 +87,7 @@ module Logical::Naf::ConstructionZone
|
|
|
87
87
|
:application_run_group_limit => number_of_jobs,
|
|
88
88
|
:application_run_group_restriction => ::Naf::ApplicationRunGroupRestriction.limited_per_machine
|
|
89
89
|
}.merge(parameters)
|
|
90
|
-
machine_parameters[:affinities] =
|
|
90
|
+
machine_parameters[:affinities] =
|
|
91
91
|
[machine.affinity] + if machine_parameters[:affinities].nil?
|
|
92
92
|
[]
|
|
93
93
|
elsif machine_parameters[:affinities].is_a? Array
|
|
@@ -35,7 +35,7 @@ module Logical::Naf::ConstructionZone
|
|
|
35
35
|
#(::Naf::QueuedJob.where(:application_run_group_name => application_run_group_name).count +
|
|
36
36
|
#::Naf::RunningJob.where(:application_run_group_name => application_run_group_name,
|
|
37
37
|
#:started_on_machine_id => @machine.id).count) >= application_run_group_limit
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
# XXX just returning false
|
|
40
40
|
false
|
|
41
41
|
elsif application_run_group_restriction.id == ::Naf::ApplicationRunGroupRestriction.limited_per_all_machines.id
|
|
@@ -5,6 +5,7 @@ module Logical
|
|
|
5
5
|
class Job
|
|
6
6
|
include ActionView::Helpers::DateHelper
|
|
7
7
|
include ActionView::Helpers::TextHelper
|
|
8
|
+
include ::Naf::TimeHelper
|
|
8
9
|
|
|
9
10
|
COLUMNS = [:id,
|
|
10
11
|
:server,
|
|
@@ -147,7 +148,7 @@ module Logical
|
|
|
147
148
|
if search[field].present?
|
|
148
149
|
conditions << " AND "
|
|
149
150
|
conditions << "lower(#{field}) ~ :#{field}"
|
|
150
|
-
values[field.to_sym] = search[field].downcase
|
|
151
|
+
values[field.to_sym] = Regexp.escape(search[field].downcase)
|
|
151
152
|
end
|
|
152
153
|
end
|
|
153
154
|
|
|
@@ -178,7 +179,7 @@ module Logical
|
|
|
178
179
|
JobStatuses::Terminated.all(conditions)
|
|
179
180
|
end
|
|
180
181
|
sql << "LIMIT :limit OFFSET :offset"
|
|
181
|
-
jobs = ::Naf::HistoricalJob.find_by_sql([sql, values])
|
|
182
|
+
jobs = ::Naf::HistoricalJob.find_by_sql([sql, values]).uniq
|
|
182
183
|
|
|
183
184
|
jobs.map{ |physical_job| new(physical_job) }
|
|
184
185
|
else
|
|
@@ -225,7 +226,7 @@ module Logical
|
|
|
225
226
|
job_scope = job_scope.where(field => search[field]) if search[field].present?
|
|
226
227
|
end
|
|
227
228
|
SEARCH_FIELDS.each do |field|
|
|
228
|
-
job_scope = job_scope.where(["lower(#{field}) ~ ?", search[field].downcase]) if search[field].present?
|
|
229
|
+
job_scope = job_scope.where(["lower(#{field}) ~ ?", Regexp.escape(search[field].downcase)]) if search[field].present?
|
|
229
230
|
end
|
|
230
231
|
|
|
231
232
|
job_scope
|
|
@@ -270,7 +271,7 @@ module Logical
|
|
|
270
271
|
if value < 60
|
|
271
272
|
"#{value.to_i} seconds ago, #{@job.started_at.localtime.strftime("%Y-%m-%d %r")}"
|
|
272
273
|
elsif value < 172_800
|
|
273
|
-
time_difference(value)
|
|
274
|
+
time_difference(value, @job.started_at)
|
|
274
275
|
elsif value >= 172_800
|
|
275
276
|
"#{time_ago_in_words(@job.started_at, true)} ago, #{@job.started_at.localtime.strftime("%Y-%m-%d %r")}"
|
|
276
277
|
else
|
|
@@ -281,27 +282,6 @@ module Logical
|
|
|
281
282
|
end
|
|
282
283
|
end
|
|
283
284
|
|
|
284
|
-
def time_difference(value, time_format_on=true)
|
|
285
|
-
seconds = value % 60
|
|
286
|
-
value = (value - seconds) / 60
|
|
287
|
-
minutes = value % 60
|
|
288
|
-
value = (value - minutes) / 60
|
|
289
|
-
hours = value % 24
|
|
290
|
-
value = (value - hours) / 24
|
|
291
|
-
days = value % 7
|
|
292
|
-
more_hours = hours + days * 24 if days > 0
|
|
293
|
-
|
|
294
|
-
if time_format_on
|
|
295
|
-
"-#{hours.to_i}h#{minutes.to_i}m, #{@job.started_at.localtime.strftime("%Y-%m-%d %r")}"
|
|
296
|
-
else
|
|
297
|
-
if days < 2
|
|
298
|
-
"-#{more_hours.to_i}h#{minutes.to_i}m#{seconds.to_i}s"
|
|
299
|
-
else
|
|
300
|
-
"-#{days.to_i}d#{hours.to_i}h#{minutes.to_i}m#{seconds.to_i}s"
|
|
301
|
-
end
|
|
302
|
-
end
|
|
303
|
-
end
|
|
304
|
-
|
|
305
285
|
def has_started?
|
|
306
286
|
@job.started_at.present?
|
|
307
287
|
end
|
|
@@ -313,9 +293,13 @@ module Logical
|
|
|
313
293
|
def run_time
|
|
314
294
|
if @job.started_at.present?
|
|
315
295
|
if @job.finished_at.present?
|
|
316
|
-
|
|
296
|
+
if @job.started_at > @job.finished_at
|
|
297
|
+
time_difference(@job.started_at - @job.finished_at)[1..-1]
|
|
298
|
+
else
|
|
299
|
+
time_difference(@job.finished_at - @job.started_at)[1..-1]
|
|
300
|
+
end
|
|
317
301
|
else
|
|
318
|
-
time_difference(Time.zone.now - @job.started_at
|
|
302
|
+
time_difference(Time.zone.now - @job.started_at)[1..-1]
|
|
319
303
|
end
|
|
320
304
|
else
|
|
321
305
|
""
|
|
@@ -331,27 +315,48 @@ module Logical
|
|
|
331
315
|
end
|
|
332
316
|
|
|
333
317
|
def affinities
|
|
334
|
-
@job.
|
|
335
|
-
if
|
|
336
|
-
if
|
|
337
|
-
|
|
318
|
+
@job.historical_job_affinity_tabs.map do |tab|
|
|
319
|
+
if tab.affinity_short_name.present?
|
|
320
|
+
if tab.affinity_parameter.present? && tab.affinity_parameter > 0
|
|
321
|
+
tab.affinity_short_name + "(#{tab.affinity_parameter})"
|
|
338
322
|
else
|
|
339
|
-
|
|
323
|
+
tab.affinity_short_name
|
|
340
324
|
end
|
|
325
|
+
else
|
|
326
|
+
tab.affinity_classification_name + '_' + tab.affinity_name
|
|
341
327
|
end
|
|
342
328
|
end.join(", \n")
|
|
343
329
|
end
|
|
344
330
|
|
|
345
331
|
def tags
|
|
346
|
-
if @job.tags.present?
|
|
332
|
+
if @job.running_job.try(:tags).present?
|
|
347
333
|
# Only show custom visible tags
|
|
348
|
-
job_tags = @job.tags.gsub(/[{}]/,'').split(',')
|
|
334
|
+
job_tags = @job.running_job.tags.gsub(/[{}]/,'').split(',')
|
|
349
335
|
(job_tags.select { |elem| !['$', '_'].include?elem[0] }).join(', ')
|
|
350
336
|
else
|
|
351
337
|
nil
|
|
352
338
|
end
|
|
353
339
|
end
|
|
354
340
|
|
|
341
|
+
def runner
|
|
342
|
+
if @job.machine_runner_invocation.present?
|
|
343
|
+
machine = @job.machine_runner_invocation.machine_runner.machine
|
|
344
|
+
if machine.present?
|
|
345
|
+
if machine.server_name.present?
|
|
346
|
+
machine.server_name.to_s
|
|
347
|
+
else
|
|
348
|
+
if Rails.env == 'development'
|
|
349
|
+
"localhost:#{Rails::Server.new.options[:Port]}"
|
|
350
|
+
else
|
|
351
|
+
machine.server_address
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
else
|
|
356
|
+
''
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
|
|
355
360
|
end
|
|
356
361
|
end
|
|
357
362
|
end
|