naf 2.0.4 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +28 -4
- data/RELEASE_NOTES.rdoc +8 -0
- data/app/assets/javascripts/dataTablesTemplates/application_schedules.js +72 -0
- data/app/assets/javascripts/dataTablesTemplates/applications.js +12 -21
- data/app/controllers/naf/application_schedule_affinity_tabs_controller.rb +5 -8
- data/app/controllers/naf/application_schedules_controller.rb +98 -0
- data/app/controllers/naf/applications_controller.rb +6 -98
- data/app/controllers/naf/historical_jobs_controller.rb +18 -8
- data/app/helpers/naf/application_helper.rb +47 -22
- data/app/models/logical/naf/application.rb +9 -126
- data/app/models/logical/naf/application_schedule.rb +186 -0
- data/app/models/logical/naf/construction_zone/boss.rb +4 -5
- data/app/models/logical/naf/construction_zone/foreman.rb +34 -13
- data/app/models/logical/naf/construction_zone/proletariat.rb +1 -0
- data/app/models/logical/naf/construction_zone/work_order.rb +11 -4
- data/app/models/logical/naf/job_fetcher.rb +1 -0
- data/app/models/naf/application.rb +5 -16
- data/app/models/naf/application_schedule.rb +117 -43
- data/app/models/naf/historical_job.rb +6 -3
- data/app/models/naf/queued_job.rb +3 -0
- data/app/models/naf/run_interval_style.rb +20 -0
- data/app/models/naf/running_job.rb +3 -0
- data/app/models/process/naf/data_migration/backfill_application_schedule_run_interval.rb +85 -0
- data/app/models/process/naf/log_archiver.rb +1 -1
- data/app/models/process/naf/log_reader.rb +141 -0
- data/app/models/process/naf/runner.rb +6 -49
- data/app/views/naf/application_schedule_affinity_tabs/_form.html.erb +1 -1
- data/app/views/naf/{applications → application_schedules}/_application_schedule_prerequisites.html.erb +1 -1
- data/app/views/naf/application_schedules/_form.html.erb +120 -0
- data/app/views/naf/application_schedules/edit.html.erb +11 -0
- data/app/views/naf/application_schedules/index.html.erb +47 -0
- data/app/views/naf/application_schedules/index.json.erb +8 -0
- data/app/views/naf/application_schedules/new.html.erb +11 -0
- data/app/views/naf/application_schedules/show.html.erb +130 -0
- data/app/views/naf/applications/_form.html.erb +44 -106
- data/app/views/naf/applications/_search_container.html.erb +29 -29
- data/app/views/naf/applications/index.html.erb +1 -10
- data/app/views/naf/applications/index.json.erb +22 -6
- data/app/views/naf/applications/show.html.erb +47 -97
- data/app/views/naf/logger_styles/_form.html.erb +0 -3
- data/app/views/naf/machines/_form.html.erb +3 -4
- data/config/routes.rb +3 -4
- data/db/migrate/20131219195439_add_run_interval_styles_table.rb +49 -0
- data/db/migrate/20140113183243_drop_run_start_minute_from_application_schedules.rb +18 -0
- data/lib/naf/version.rb +1 -1
- data/naf.gemspec +1 -1
- data/spec/controllers/naf/application_schedule_affinity_tabs_controller_spec.rb +34 -27
- data/spec/controllers/naf/applications_controller_spec.rb +0 -48
- data/spec/factories/naf.rb +14 -8
- data/spec/models/logical/naf/application_spec.rb +9 -37
- data/spec/models/logical/naf/machine_spec.rb +1 -1
- data/spec/models/naf/application_schedule_spec.rb +38 -50
- data/spec/models/naf/application_spec.rb +3 -3
- data/spec/models/naf/historical_job_spec.rb +4 -2
- data/spec/models/naf/queued_job_spec.rb +2 -0
- data/spec/models/naf/run_interval_style_spec.rb +28 -0
- data/spec/models/naf/running_job_spec.rb +2 -0
- metadata +19 -7
- data/app/models/logical/naf/job_creator.rb +0 -151
- data/app/views/naf/applications/_application_schedule.html.erb +0 -80
- data/spec/models/logical/naf/job_creator_spec.rb +0 -102
@@ -1,151 +0,0 @@
|
|
1
|
-
module Logical
|
2
|
-
module Naf
|
3
|
-
class JobCreator
|
4
|
-
def queue_application(application,
|
5
|
-
application_run_group_restriction,
|
6
|
-
application_run_group_name,
|
7
|
-
application_run_group_limit = 1,
|
8
|
-
priority = 0,
|
9
|
-
affinities = [],
|
10
|
-
prerequisites = [],
|
11
|
-
enqueue = false)
|
12
|
-
|
13
|
-
# Before adding a job to the queue, check whether the number of
|
14
|
-
# jobs (running/queued) is equal to or greater than the application
|
15
|
-
# run group limit, or if enqueue_backlogs is set to false. If so,
|
16
|
-
# do not add the job to the queue
|
17
|
-
running_jobs = retrieve_jobs(::Naf::RunningJob, application.command, application_run_group_name)
|
18
|
-
queued_jobs = retrieve_jobs(::Naf::QueuedJob, application.command, application_run_group_name)
|
19
|
-
|
20
|
-
if enqueue == false && (running_jobs.present? || queued_jobs.present?)
|
21
|
-
group_limit = running_jobs.try(:application_run_group_limit).to_i + queued_jobs.try(:application_run_group_limit).to_i
|
22
|
-
total_jobs = running_jobs.try(:count).to_i + queued_jobs.try(:count).to_i
|
23
|
-
|
24
|
-
return if group_limit <= total_jobs
|
25
|
-
end
|
26
|
-
|
27
|
-
::Naf::HistoricalJob.transaction do
|
28
|
-
historical_job = ::Naf::HistoricalJob.create!(application_id: application.id,
|
29
|
-
application_type_id: application.application_type_id,
|
30
|
-
command: application.command,
|
31
|
-
application_run_group_restriction_id: application_run_group_restriction.id,
|
32
|
-
application_run_group_name: application_run_group_name,
|
33
|
-
application_run_group_limit: application_run_group_limit,
|
34
|
-
priority: priority,
|
35
|
-
log_level: application.log_level)
|
36
|
-
|
37
|
-
# Create historical job affinity tabs for each affinity associated with the historical job
|
38
|
-
affinities.each do |affinity|
|
39
|
-
affinity_parameter = ::Naf::ApplicationScheduleAffinityTab.
|
40
|
-
where(affinity_id: affinity.id,
|
41
|
-
application_schedule_id: application.application_schedule.try(:id)).
|
42
|
-
first.try(:affinity_parameter)
|
43
|
-
::Naf::HistoricalJobAffinityTab.create(historical_job_id: historical_job.id,
|
44
|
-
affinity_id: affinity.id,
|
45
|
-
affinity_parameter: affinity_parameter)
|
46
|
-
end
|
47
|
-
|
48
|
-
verify_and_create_prerequisites(historical_job, prerequisites)
|
49
|
-
|
50
|
-
create_queue_job(historical_job)
|
51
|
-
|
52
|
-
return historical_job
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def retrieve_jobs(klass, command, application_run_group_name)
|
57
|
-
klass.select('application_run_group_limit, MAX(created_at) AS created_at, count(*)').
|
58
|
-
where('command = ? AND application_run_group_name = ?', command, application_run_group_name).
|
59
|
-
group('application_run_group_name, application_run_group_limit').first
|
60
|
-
end
|
61
|
-
|
62
|
-
def queue_application_schedule(application_schedule, schedules_queued_already = [])
|
63
|
-
prerequisite_jobs = []
|
64
|
-
|
65
|
-
# Check if schedule has been queued
|
66
|
-
if schedules_queued_already.include? application_schedule.id
|
67
|
-
raise ::Naf::HistoricalJob::JobPrerequisiteLoop.new(application_schedule)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Keep track of queued schedules
|
71
|
-
schedules_queued_already << application_schedule.id
|
72
|
-
# Queue application schedule prerequisites
|
73
|
-
application_schedule.prerequisites.each do |application_schedule_prerequisite|
|
74
|
-
prerequisite_jobs << queue_application_schedule(application_schedule_prerequisite, schedules_queued_already)
|
75
|
-
end
|
76
|
-
|
77
|
-
# Queue the application
|
78
|
-
return queue_application(application_schedule.application,
|
79
|
-
application_schedule.application_run_group_restriction,
|
80
|
-
application_schedule.application_run_group_name,
|
81
|
-
application_schedule.application_run_group_limit,
|
82
|
-
application_schedule.priority,
|
83
|
-
application_schedule.affinities,
|
84
|
-
prerequisite_jobs,
|
85
|
-
application_schedule.enqueue_backlogs)
|
86
|
-
end
|
87
|
-
|
88
|
-
# This method act similar to queue_application but is used for testing purpose
|
89
|
-
def queue_rails_job(command,
|
90
|
-
application_run_group_restriction = ::Naf::ApplicationRunGroupRestriction.limited_per_all_machines,
|
91
|
-
application_run_group_name = :command,
|
92
|
-
application_run_group_limit = 1,
|
93
|
-
priority = 0,
|
94
|
-
affinities = [],
|
95
|
-
prerequisites = [])
|
96
|
-
application_run_group_name = command if application_run_group_name == :command
|
97
|
-
::Naf::HistoricalJob.transaction do
|
98
|
-
historical_job = ::Naf::HistoricalJob.create!(application_type_id: 1,
|
99
|
-
command: command,
|
100
|
-
application_run_group_restriction_id: application_run_group_restriction.id,
|
101
|
-
application_run_group_name: application_run_group_name,
|
102
|
-
application_run_group_limit: application_run_group_limit,
|
103
|
-
priority: priority)
|
104
|
-
affinities.each do |affinity|
|
105
|
-
::Naf::HistoricalJobAffinityTab.create(historical_job_id: historical_job.id, affinity_id: affinity.id)
|
106
|
-
end
|
107
|
-
|
108
|
-
verify_and_create_prerequisites(historical_job, prerequisites)
|
109
|
-
|
110
|
-
create_queue_job(historical_job)
|
111
|
-
|
112
|
-
return historical_job
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def verify_and_create_prerequisites(job, prerequisites)
|
117
|
-
job.verify_prerequisites(prerequisites)
|
118
|
-
# Create historical job prerequisites for each prerequisite associated with the historical job
|
119
|
-
prerequisites.each do |prerequisite|
|
120
|
-
::Naf::HistoricalJobPrerequisite.create(historical_job_id: job.id,
|
121
|
-
prerequisite_historical_job_id: prerequisite.id)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def create_queue_job(historical_job)
|
126
|
-
queued_job = ::Naf::QueuedJob.new(application_id: historical_job.application_id,
|
127
|
-
application_type_id: historical_job.application_type_id,
|
128
|
-
command: historical_job.command,
|
129
|
-
application_run_group_restriction_id: historical_job.application_run_group_restriction_id,
|
130
|
-
application_run_group_name: historical_job.application_run_group_name,
|
131
|
-
application_run_group_limit: historical_job.application_run_group_limit,
|
132
|
-
priority: historical_job.priority)
|
133
|
-
queued_job.id = historical_job.id
|
134
|
-
queued_job.save!
|
135
|
-
end
|
136
|
-
|
137
|
-
def queue_test
|
138
|
-
queue_rails_job("#{self.class.name}.test")
|
139
|
-
end
|
140
|
-
|
141
|
-
def self.test(*foo)
|
142
|
-
seconds = rand 120 + 15
|
143
|
-
puts "TEST CALLED: #{Time.zone.now}: #{foo.inspect}: sleeping for #{seconds} seconds"
|
144
|
-
sleep(seconds)
|
145
|
-
puts "TEST DONE: #{Time.zone.now}: #{foo.inspect}"
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
MiddleClass = JobCreator
|
150
|
-
end
|
151
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
<div class="field">
|
2
|
-
<%= f.hidden_field :_destroy %>
|
3
|
-
</div>
|
4
|
-
|
5
|
-
<h3 class="display-inline-block">Schedule | </h3>
|
6
|
-
<%= link_to "Remove", "#" , id: "remove_application_schedule", class: "display-inline-block"%>
|
7
|
-
|
8
|
-
<%= f.hidden_field :application_id %>
|
9
|
-
|
10
|
-
<div class="field">
|
11
|
-
<%= f.label :application_run_group_restriction_id, "Application run group restriction*" %>
|
12
|
-
<%= f.select(:application_run_group_restriction_id,
|
13
|
-
::Naf::ApplicationRunGroupRestriction.all.map { |a| [a.application_run_group_restriction_name, a.id] },
|
14
|
-
include_blank: true) %>
|
15
|
-
</div>
|
16
|
-
</br/>
|
17
|
-
|
18
|
-
<div class="field">
|
19
|
-
<%= f.label :application_run_group_name %>
|
20
|
-
<%= select_tag(:run_group_name_type, options_for_select([["custom", "custom"],
|
21
|
-
["command", "command"],
|
22
|
-
["not set", "not set"]],
|
23
|
-
@run_group_name_type)) %><br/>
|
24
|
-
<%= f.text_area :application_run_group_name, rows: 4, cols: 32, placeholder: "Please input Application Run Group Name" %>
|
25
|
-
</div>
|
26
|
-
</br/>
|
27
|
-
|
28
|
-
<div class="field">
|
29
|
-
<%= f.label :run_start_minute, "Run Start Time (count of minutes after 12:00 am)" %>
|
30
|
-
<%= f.text_field :run_start_minute %>
|
31
|
-
</div>
|
32
|
-
</br/>
|
33
|
-
|
34
|
-
<div class="field">
|
35
|
-
<%= f.label :run_interval, "Run Interval (minutes)" %>
|
36
|
-
<%= f.text_field :run_interval %>
|
37
|
-
</div>
|
38
|
-
</br/>
|
39
|
-
|
40
|
-
<div class="field">
|
41
|
-
<%= f.label :priority %>
|
42
|
-
<%= f.text_field :priority %>
|
43
|
-
</div>
|
44
|
-
</br/>
|
45
|
-
|
46
|
-
<div class="field">
|
47
|
-
<%= f.label :application_run_group_limit %>
|
48
|
-
<%= f.text_field :application_run_group_limit %>
|
49
|
-
</div>
|
50
|
-
</br/>
|
51
|
-
|
52
|
-
<div class="field">
|
53
|
-
<%= f.label :enabled %>
|
54
|
-
<%= f.check_box :enabled %>
|
55
|
-
</div>
|
56
|
-
</br/>
|
57
|
-
|
58
|
-
<div class="field">
|
59
|
-
<%= f.label :visible %>
|
60
|
-
<%= f.check_box :visible %>
|
61
|
-
</div>
|
62
|
-
<br/>
|
63
|
-
|
64
|
-
<div class="field">
|
65
|
-
<%= f.label :enqueue_backlogs %>
|
66
|
-
<%= f.check_box :enqueue_backlogs %>
|
67
|
-
</div>
|
68
|
-
<br/>
|
69
|
-
|
70
|
-
<% if @show_prerequisite %>
|
71
|
-
<%= f.fields_for :application_schedule_prerequisites do |builder| %>
|
72
|
-
<%= render "application_schedule_prerequisites", f: builder %>
|
73
|
-
<% end %>
|
74
|
-
<% else %>
|
75
|
-
<% f.fields_for :application_schedule_prerequisites do |builder| %>
|
76
|
-
<%= render "application_schedule_prerequisites", f: builder %>
|
77
|
-
<% end %>
|
78
|
-
<% end %>
|
79
|
-
|
80
|
-
<%= naf_link_to_add_fields "Add Schedule Prerequisite", f, :application_schedule_prerequisites %>
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Logical
|
4
|
-
module Naf
|
5
|
-
describe JobCreator do
|
6
|
-
|
7
|
-
let!(:job_creator) { ::Logical::Naf::JobCreator.new }
|
8
|
-
let!(:historical_job) { FactoryGirl.create(:job) }
|
9
|
-
let(:application) { FactoryGirl.create(:scheduled_application) }
|
10
|
-
|
11
|
-
describe '#queue_application' do
|
12
|
-
it 'not queue an application if the group limit is less than number of queued/running jobs' do
|
13
|
-
historical_job.application_run_group_name = application.application_schedule.application_run_group_name
|
14
|
-
historical_job.command = application.command
|
15
|
-
historical_job.save!
|
16
|
-
job_creator.create_queue_job(historical_job)
|
17
|
-
|
18
|
-
job_creator.queue_application(application,
|
19
|
-
application.application_schedule.application_run_group_restriction,
|
20
|
-
application.application_schedule.application_run_group_name).should be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'return a historical_job that has been queued' do
|
24
|
-
job_creator.queue_application(application,
|
25
|
-
application.application_schedule.application_run_group_restriction,
|
26
|
-
application.application_schedule.application_run_group_name).should be_instance_of(::Naf::HistoricalJob)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'create affinity tabs when affinities are present' do
|
30
|
-
job_creator.queue_application(application,
|
31
|
-
application.application_schedule.application_run_group_restriction,
|
32
|
-
application.application_schedule.application_run_group_name,
|
33
|
-
1,
|
34
|
-
0,
|
35
|
-
[::Naf::Affinity.first])
|
36
|
-
::Naf::HistoricalJobAffinityTab.should have(1).records
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#retrieve_jobs' do
|
41
|
-
before do
|
42
|
-
FactoryGirl.create(:queued_job, application_run_group_name: 'Test',
|
43
|
-
application_run_group_limit: 1)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'return the correct records' do
|
47
|
-
job_creator.retrieve_jobs(::Naf::QueuedJob, '::Naf::QueuedJob.test hello world', 'Test').
|
48
|
-
count.to_i.should == 1
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#queue_application_schedule' do
|
53
|
-
it 'raise error if schedule has been queued' do
|
54
|
-
expect { job_creator.queue_application_schedule(application.application_schedule, [application.application_schedule.id]) }.
|
55
|
-
to raise_error(::Naf::HistoricalJob::JobPrerequisiteLoop)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'return a historical_job that has been queued' do
|
59
|
-
job_creator.queue_application_schedule(application.application_schedule).should be_instance_of(::Naf::HistoricalJob)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '#queue_rails_job' do
|
64
|
-
it 'create and return a historical_job' do
|
65
|
-
job = job_creator.queue_rails_job(:command)
|
66
|
-
job.should be_instance_of(::Naf::HistoricalJob)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'create affinity tabs when affinites are present' do
|
70
|
-
job_creator.queue_rails_job(:command,
|
71
|
-
::Naf::ApplicationRunGroupRestriction.limited_per_all_machines,
|
72
|
-
:command,
|
73
|
-
1,
|
74
|
-
0,
|
75
|
-
[::Naf::Affinity.first])
|
76
|
-
|
77
|
-
::Naf::HistoricalJobAffinityTab.should have(1).records
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe '#verify_and_create_prerequisites' do
|
82
|
-
before do
|
83
|
-
prereq_job = FactoryGirl.create(:job)
|
84
|
-
job_creator.verify_and_create_prerequisites(historical_job, [prereq_job])
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'insert a row correctly into naf.historical_job_prerequisites' do
|
88
|
-
::Naf::HistoricalJobPrerequisite.should have(1).records
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe '#create_queue_job' do
|
93
|
-
it 'insert a row correctly into naf.queued_jobs' do
|
94
|
-
job_creator.create_queue_job(historical_job)
|
95
|
-
::Naf::QueuedJob.should have(1).records
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
end
|