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.
Files changed (118) hide show
  1. data/Gemfile +4 -2
  2. data/app/assets/images/{papertrail_job.png → job.png} +0 -0
  3. data/app/assets/images/{papertrail_machine.png → machine.png} +0 -0
  4. data/app/assets/images/{papertrail_machine_runner.png → machine_runner.png} +0 -0
  5. data/app/assets/javascripts/col_reorder_with_resize.js +1228 -0
  6. data/app/assets/javascripts/dataTablesTemplates/applications.js +2 -1
  7. data/app/assets/javascripts/dataTablesTemplates/jobs.js +2 -1
  8. data/app/assets/javascripts/dataTablesTemplates/machine_runner_invocations.js +2 -1
  9. data/app/assets/javascripts/dataTablesTemplates/machine_runners.js +2 -1
  10. data/app/assets/javascripts/dataTablesTemplates/machines.js +2 -1
  11. data/app/assets/javascripts/jquery.dataTables.js +10339 -5103
  12. data/app/assets/javascripts/naf.js +1 -0
  13. data/app/assets/stylesheets/jquery_ui/jquery-ui-1.8.5.custom.css.erb +6 -6
  14. data/app/assets/stylesheets/min_naf/layout.css.scss +94 -43
  15. data/app/assets/stylesheets/naf/layout.css.scss +94 -43
  16. data/app/controllers/naf/affinities_controller.rb +1 -1
  17. data/app/controllers/naf/applications_controller.rb +3 -0
  18. data/app/controllers/naf/historical_job_affinity_tabs_controller.rb +1 -1
  19. data/app/controllers/naf/historical_jobs_controller.rb +2 -5
  20. data/app/controllers/naf/log_parsers_controller.rb +16 -0
  21. data/app/controllers/naf/log_viewer_controller.rb +19 -0
  22. data/app/controllers/naf/machine_affinity_slots_controller.rb +1 -1
  23. data/app/controllers/naf/machine_runners_controller.rb +12 -0
  24. data/app/controllers/naf/machines_controller.rb +8 -10
  25. data/app/controllers/naf/status_controller.rb +12 -0
  26. data/app/helpers/naf/application_helper.rb +19 -38
  27. data/app/helpers/naf/time_helper.rb +37 -0
  28. data/app/models/logical/naf/application.rb +13 -19
  29. data/app/models/logical/naf/construction_zone/boss.rb +1 -1
  30. data/app/models/logical/naf/construction_zone/foreman.rb +1 -1
  31. data/app/models/logical/naf/job.rb +39 -34
  32. data/app/models/logical/naf/job_creator.rb +19 -23
  33. data/app/models/logical/naf/job_fetcher.rb +36 -6
  34. data/app/models/logical/naf/log_file.rb +70 -0
  35. data/app/models/logical/naf/log_parser/base.rb +272 -0
  36. data/app/models/logical/naf/log_parser/job.rb +65 -0
  37. data/app/models/logical/naf/log_parser/machine.rb +64 -0
  38. data/app/models/logical/naf/log_parser/runner.rb +72 -0
  39. data/app/models/logical/naf/log_reader.rb +85 -0
  40. data/app/models/logical/naf/machine.rb +39 -1
  41. data/app/models/naf/affinity.rb +18 -0
  42. data/app/models/naf/application_schedule_affinity_tab.rb +1 -0
  43. data/app/models/naf/application_type.rb +2 -1
  44. data/app/models/naf/historical_job.rb +9 -29
  45. data/app/models/naf/machine.rb +8 -0
  46. data/app/models/naf/machine_runner.rb +11 -2
  47. data/app/models/naf/machine_runner_invocation.rb +9 -1
  48. data/app/models/naf/running_job.rb +40 -1
  49. data/app/models/process/naf/application.rb +3 -3
  50. data/app/models/process/naf/log_archiver.rb +78 -0
  51. data/app/models/process/naf/machine_manager.rb +3 -1
  52. data/app/models/process/naf/runner.rb +286 -162
  53. data/app/models/process/naf/runner_log.rb +26 -0
  54. data/app/views/naf/application_schedule_affinity_tabs/_form.html.erb +1 -5
  55. data/app/views/naf/applications/show.html.erb +1 -1
  56. data/app/views/naf/historical_job_affinity_tabs/_form.html.erb +1 -5
  57. data/app/views/naf/historical_jobs/_form.html.erb +1 -1
  58. data/app/views/naf/historical_jobs/_runners.html.erb +21 -12
  59. data/app/views/naf/historical_jobs/_search_container.html.erb +1 -2
  60. data/app/views/naf/historical_jobs/index.html.erb +0 -1
  61. data/app/views/naf/historical_jobs/index.json.erb +4 -4
  62. data/app/views/naf/historical_jobs/show.html.erb +57 -51
  63. data/app/views/naf/log_viewer/_job_logs.html.erb +65 -0
  64. data/app/views/naf/log_viewer/_log_display.html.erb +259 -0
  65. data/app/views/naf/log_viewer/_log_layout.html.erb +59 -0
  66. data/app/views/naf/log_viewer/_machine_logs.html.erb +62 -0
  67. data/app/views/naf/log_viewer/_runner_logs.html.erb +62 -0
  68. data/app/views/naf/log_viewer/_search_options.html.erb +36 -0
  69. data/app/views/naf/log_viewer/_update_page_title.html.erb +9 -0
  70. data/app/views/naf/log_viewer/index.html.erb +1 -0
  71. data/app/views/naf/logger_names/_form.html.erb +1 -2
  72. data/app/views/naf/machine_affinity_slots/_form.html.erb +1 -5
  73. data/app/views/naf/machine_runner_invocations/show.html.erb +4 -0
  74. data/app/views/naf/machine_runners/show.html.erb +44 -34
  75. data/app/views/naf/machines/index.json.erb +14 -6
  76. data/app/views/naf/machines/show.html.erb +44 -40
  77. data/app/views/naf/shared/_auto_resize_width.html.erb +7 -0
  78. data/app/views/naf/shared/_date_select.html.erb +65 -0
  79. data/app/views/naf/shared/_select_per_page.html.erb +48 -13
  80. data/app/views/naf/status/index.html.erb +27 -0
  81. data/bin/naf +26 -0
  82. data/config/initializers/naf.rb +13 -1
  83. data/config/routes.rb +16 -2
  84. data/db/migrate/20131106162436_add_uuid_column_to_machine_runner_invocations.rb +15 -0
  85. data/db/migrate/20131121185222_move_tabs_column_from_historical_jobs_to_running_jobs.rb +15 -0
  86. data/lib/generators/templates/config/logging/naf.yml +0 -8
  87. data/lib/generators/templates/config/logging/nafjob.yml +0 -8
  88. data/lib/generators/templates/config/logging/nafrunner.yml +0 -8
  89. data/lib/generators/templates/naf.rb +0 -8
  90. data/lib/naf.rb +0 -8
  91. data/lib/naf/configuration.rb +0 -4
  92. data/lib/naf/version.rb +1 -1
  93. data/lib/tasks/naf_tasks.rake +18 -0
  94. data/naf.gemspec +3 -1
  95. data/spec/controllers/naf/affinities_controller_spec.rb +0 -1
  96. data/spec/controllers/naf/applications_controller_spec.rb +3 -2
  97. data/spec/controllers/naf/machine_affinity_slots_controller_spec.rb +0 -1
  98. data/spec/controllers/naf/machines_controller_spec.rb +1 -1
  99. data/spec/dummy/config/logging/naf.yml +0 -8
  100. data/spec/dummy/config/logging/nafjob.yml +0 -9
  101. data/spec/dummy/config/logging/nafrunner.yml +0 -10
  102. data/spec/factories/naf.rb +4 -0
  103. data/spec/models/logical/naf/application_spec.rb +3 -4
  104. data/spec/models/logical/naf/job_creator_spec.rb +91 -21
  105. data/spec/models/logical/naf/job_spec.rb +19 -6
  106. data/spec/models/logical/naf/log_file_spec.rb +105 -0
  107. data/spec/models/logical/naf/machine_runner_invocation_spec.rb +41 -0
  108. data/spec/models/logical/naf/machine_runner_spec.rb +42 -0
  109. data/spec/models/logical/naf/machine_spec.rb +98 -28
  110. data/spec/models/naf/affinity_classification_spec.rb +20 -0
  111. data/spec/models/naf/affinity_spec.rb +21 -0
  112. data/spec/models/naf/historical_job_spec.rb +2 -44
  113. data/spec/models/naf/machine_runner_invocation_spec.rb +17 -1
  114. data/spec/models/naf/running_job_spec.rb +64 -1
  115. metadata +40 -9
  116. data/app/models/log4r/papertrail_outputter.rb +0 -19
  117. data/app/views/naf/historical_jobs/edit.html.erb +0 -11
  118. data/app/views/naf/machines/_show.html.erb +0 -169
@@ -0,0 +1,26 @@
1
+ require 'open4'
2
+
3
+ module Process::Naf
4
+ class RunnerLog < ::Af::Application
5
+
6
+ opt :invocation_uuid,
7
+ "unique identifer used for runner logs",
8
+ default: `uuidgen`
9
+
10
+ def work
11
+ log_file = ::Logical::Naf::LogFile.new("#{::Naf::PREFIX_PATH}/#{::Naf.schema_name}/runners/#{@invocation_uuid}/")
12
+ log_file.open
13
+
14
+ while $stdin.gets
15
+ begin
16
+ log_file << $_.rstrip
17
+ ensure
18
+ log_file.write
19
+ end
20
+ end
21
+
22
+ log_file.close
23
+ end
24
+
25
+ end
26
+ end
@@ -10,11 +10,7 @@
10
10
 
11
11
  <div class="field">
12
12
  <%= f.label :affinity_id, "Affinity*" %></br>
13
- <%= f.select(:affinity_id,
14
- ::Naf::Affinity.selectable.map{
15
- |a| [a.affinity_classification.affinity_classification_name + ', ' + a.affinity_name, a.id]
16
- },
17
- include_blank: true) %>
13
+ <%= f.select(:affinity_id, ::Naf::Affinity.names_list, include_blank: true) %>
18
14
  </div>
19
15
  </br>
20
16
 
@@ -136,7 +136,7 @@
136
136
  <td><%= link_to "Application Schedule Affinity Tabs",
137
137
  application_application_schedule_application_schedule_affinity_tabs_path(@application, @application.application_schedule) %>
138
138
  </td>
139
- <td><%= @application.application_schedule.affinities.map(&:affinity_name).join(', ') %></td>
139
+ <td><%= @logical_application.affinities %></td>
140
140
  </tr>
141
141
  <% end %>
142
142
  <tr>
@@ -16,11 +16,7 @@
16
16
 
17
17
  <div class="field">
18
18
  <%= f.label :affinity %><br />
19
- <%= f.select(:affinity_id,
20
- ::Naf::Affinity.selectable.map{
21
- |a| [a.affinity_classification.affinity_classification_name + ', ' + a.affinity_name, a.id]
22
- },
23
- include_blank: true) %>
19
+ <%= f.select(:affinity_id, ::Naf::Affinity.names_list, include_blank: true) %>
24
20
  </div>
25
21
  </br>
26
22
 
@@ -4,7 +4,7 @@
4
4
  <h2><%= pluralize(@historical_job.errors.count, "error") %> prohibited this application from being saved:</h2>
5
5
 
6
6
  <ul>
7
- <% @historical_job.errors.full_messages.each do |msg| %>
7
+ <% @historical_job.errors.full_messages.each do |msg| %>
8
8
  <li><%= msg %></li>
9
9
  <% end %>
10
10
  </ul>
@@ -5,18 +5,27 @@
5
5
  <h3 id="record_name">Runners: </h3>
6
6
  </div>
7
7
  </td>
8
- <td>
9
- <div class="running"><%= ::Naf::MachineRunner.running.uniq.count %> running&nbsp;</div>
8
+ <td width='5%'>
9
+ <div class="running-count"><%= ::Naf::MachineRunner.running.uniq.count %> running</div>
10
+ </td>
11
+ <td width='7%'>
12
+ <div class="winding-down-count"><%= ::Naf::MachineRunner.winding_down.uniq.count %> winding down</div>
13
+ </td>
14
+ <td width='5%'>
15
+ <div class="down-count"><%= ::Naf::MachineRunner.dead_count %> down</div>
16
+ </td>
17
+ <td width='15%'>
18
+ <div id='page-label'>
19
+ <h3 id='record_name'>Schedules last checked at: </h3>
20
+ </div>
21
+ </td>
22
+ <td width='15%'>
23
+ <div class='last_checked_schedule_at'><%= time_format(::Naf::Machine.last_time_schedules_were_checked) %></div>
24
+ </td>
25
+ <td width='65%'>
26
+ <div id='create_links' style='position: relative; float:right;'>
27
+ <span id='create'><%= naf_generate_create_link %></span>
28
+ </div>
10
29
  </td>
11
- <% if ::Naf::MachineRunner.winding_down.count > 0 -%>
12
- <td>
13
- <div class="winding-down"><%= ::Naf::MachineRunner.winding_down.uniq.count %> winding down&nbsp;&nbsp;</div>
14
- </td>
15
- <% end %>
16
- <% if ::Naf::MachineRunner.dead.count > 0 -%>
17
- <td>
18
- <div class="down"><%= ::Naf::MachineRunner.dead.count %> down</div>
19
- </td>
20
- <% end %>
21
30
  </tr>
22
31
  </table>
@@ -1,4 +1,3 @@
1
- <br/>
2
1
  <div class="display-inline-block search_select_input">
3
2
  <%= label(:status, "Status:") %>
4
3
  <%= select_tag("search[status]",
@@ -8,7 +7,7 @@
8
7
  ["Waiting", :waiting],
9
8
  ["Finished", :finished],
10
9
  ["Errored", :errored]], @search_status),
11
- { class: 'datatable_variable' }) %></b>
10
+ { class: 'datatable_variable' }) %>
12
11
  </div>
13
12
  &nbsp;&nbsp;
14
13
 
@@ -1,6 +1,5 @@
1
1
  <% content_for :body do %>
2
2
  <%= render partial: 'runners' %>
3
- <%= render partial: 'naf/shared/information_container', locals: { record_name: "Jobs" } %>
4
3
  <%= render partial: 'search_container' %>
5
4
  <%= render partial: 'naf/shared/select_per_page' %>
6
5
 
@@ -8,11 +8,11 @@
8
8
  end
9
9
  end
10
10
 
11
- job[12] = link_to image_tag('papertrail_job.png',
11
+ job[12] = link_to image_tag('job.png',
12
12
  class: 'action',
13
- title: "View job(id: #{job[0]}, title: #{job[4]}) log in Papertrail"),
14
- job[12],
15
- { target: '_blank', class: "papertrail", id: job[0] }
13
+ title: "View job(id: #{job[0]}, title: #{job[4]}) log"),
14
+ url_for({ controller: 'log_viewer', action: 'index', record_id: job[0], record_type: 'job' }),
15
+ { target: '_blank', id: job[0] }
16
16
 
17
17
  if job[10] == "Running" || job[10] == 'Queued' || job[10] == 'Waiting'
18
18
  job[12] << "&nbsp;&nbsp;&nbsp;".html_safe
@@ -1,41 +1,14 @@
1
1
  <% content_for :body do %>
2
2
  <div id="flash_message">
3
- <% unless notice.blank? %>
4
- <script type='text/javascript'>
5
- jQuery("<p id='notice'><%= notice %></p>")
6
- .appendTo('#flash_message')
7
- .slideDown().delay(5000).slideUp();
8
- </script>
9
- <% end %>
3
+ <% unless notice.blank? %>
4
+ <script type='text/javascript'>
5
+ jQuery("<p id='notice'><%= notice %></p>")
6
+ .appendTo('#flash_message')
7
+ .slideDown().delay(5000).slideUp();
8
+ </script>
9
+ <% end %>
10
10
  </div>
11
11
 
12
- <script type='text/javascript'>
13
- jQuery(document).ready(function () {
14
- jQuery(document).delegate('.terminate', "click", function(){
15
- var answer = confirm("You are terminating this job. Are you sure you want to do this?");
16
- if (!answer) {
17
- return false;
18
- }
19
- var id = <%= @historical_job.id %>;
20
- var url = '/job_system/historical_jobs/' + id;
21
- jQuery.ajax({
22
- url:url,
23
- type:'POST',
24
- dataType:'json',
25
- data:{ "historical_job[request_to_terminate]":1, "historical_job_id":id, "_method":"put" },
26
- success:function (data) {
27
- if (data.success) {
28
- var title = data.title ? data.title : data.command
29
- jQuery("<p id='notice'>A Job " + title + " was terminated!</p>").
30
- appendTo('#flash_message').slideDown().delay(5000).slideUp();
31
- setTimeout('window.location.reload()', 5600);
32
- }
33
- }
34
- });
35
- });
36
- });
37
- </script>
38
-
39
12
  <div id="record">
40
13
  <h2>Historical Job</h2>
41
14
  <% if flash[:error] -%>
@@ -44,8 +17,6 @@
44
17
 
45
18
  <%= link_to 'Back to Jobs', historical_jobs_path %>
46
19
  &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
47
- <%= link_to 'Edit', edit_historical_job_path(@historical_job) %>
48
- &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
49
20
  <%= link_to "Add Affinity", new_historical_job_historical_job_affinity_tab_path(@historical_job) %>
50
21
  </br>
51
22
  </br>
@@ -125,7 +96,7 @@
125
96
  </tr>
126
97
  <tr>
127
98
  <td>Tags</td>
128
- <td><%= @historical_job.tags %></td>
99
+ <td><%= @historical_job.running_job.try(:tags) %></td>
129
100
  </tr>
130
101
  <tr>
131
102
  <td>Request To Terminate</td>
@@ -155,16 +126,18 @@
155
126
  <td><%= link_to "Historical Job Affinity Tabs",
156
127
  historical_job_historical_job_affinity_tabs_path(@historical_job.id) %>
157
128
  </td>
158
- <td><%= @historical_job.affinities.map(&:affinity_name).join(', ') %></td>
159
- </tr>
160
- <tr>
161
- <td>Terminate Job</td>
162
- <td><%= link_to image_tag('terminate.png',
163
- class: 'action',
164
- title: "Terminate job(id: #{@historical_job.id}, title: #{@historical_job.title})"),
165
- "#", { class: "terminate" }
166
- %></td>
167
- </tr>
129
+ <td><%= @logical_job.affinities %></td>
130
+ </tr>
131
+ <% if ['Running', 'Waiting', 'Queued'].include?(@logical_job.status) -%>
132
+ <tr>
133
+ <td>Terminate Job</td>
134
+ <td><%= link_to image_tag('terminate.png',
135
+ class: 'action',
136
+ title: "Terminate job(id: #{@historical_job.id}, title: #{@historical_job.title})"),
137
+ "#", { class: "terminate" }
138
+ %></td>
139
+ </tr>
140
+ <% end %>
168
141
  </tbody>
169
142
  </table>
170
143
  </br>
@@ -190,12 +163,45 @@
190
163
  </tbody>
191
164
  </table>
192
165
  </br>
166
+ <%= render partial: 'naf/log_viewer/log_layout', locals: { record_id: @historical_job.id, record_type: 'job' } %>
193
167
 
194
- <h2>Stdout</h2>
195
- <iframe src="<%= naf_papertrail_link(@historical_job, true) %>" id="stdout" class="scrollable-output">
196
- Your browser doesn't support iframe!
197
- </iframe>
198
168
  </div>
199
169
  <% end %>
200
170
 
171
+
201
172
  <%= render partial: 'naf/shared/application' %>
173
+ <%= render partial: 'naf/shared/auto_resize_width', locals: { div_class: '.scrollable-output' } %>
174
+ <%= render partial: 'naf/log_viewer/log_display',
175
+ locals: { record_id: @historical_job.id,
176
+ status: @logical_job.status,
177
+ logs_url: "#{http_protocol}#{@logical_job.runner}#{naf.logs_log_parsers_path}",
178
+ record_type: 'job' } %>
179
+
180
+ <% content_for :javascripts do %>
181
+ <script type='text/javascript'>
182
+ jQuery(document).ready(function () {
183
+ jQuery(document).delegate('.terminate', "click", function(){
184
+ var answer = confirm("You are terminating this job. Are you sure you want to do this?");
185
+ if (!answer) {
186
+ return false;
187
+ }
188
+ var id = <%= @historical_job.id %>;
189
+ var url = '/job_system/historical_jobs/' + id;
190
+ jQuery.ajax({
191
+ url: url,
192
+ type:'POST',
193
+ dataType:'json',
194
+ data:{ "historical_job[request_to_terminate]": 1, "historical_job_id": id, "_method": "put" },
195
+ success:function (data) {
196
+ if (data.success) {
197
+ var title = data.title ? data.title : data.command
198
+ jQuery("<p id='notice'>A Job " + title + " was terminated!</p>").
199
+ appendTo('#flash_message').slideDown().delay(5000).slideUp();
200
+ setTimeout('window.location.reload()', 5600);
201
+ }
202
+ }
203
+ });
204
+ });
205
+ });
206
+ </script>
207
+ <% end %>
@@ -0,0 +1,65 @@
1
+ <div id='naf'>
2
+ <div id="fluid">
3
+ <div id='bd'>
4
+ <div id="record">
5
+ <FONT FACE= "Courier New">
6
+ <div id="stdout" class="scrollable-output-expanded"></div>
7
+ </br>
8
+ <FONT FACE= "Arial">
9
+
10
+ <div id="stdout_header">
11
+ <div>
12
+ <%= render partial: 'search_options' %>
13
+ <div style="width: 100%; display: table;">
14
+ <div style="display: table-row">
15
+ <div style="width: 600px; display: table-cell;">
16
+ <%= label_tag 'From:' %>
17
+ <%= render partial: 'naf/shared/date_select', locals: { prefix: 'date_select_from', dropdown_width: 'width: 15%;' } %>
18
+ </br>
19
+ <%= label_tag 'To:' %>&nbsp;&nbsp;&nbsp;&nbsp;
20
+ <%= render partial: 'naf/shared/date_select', locals: { prefix: 'date_select_to', dropdown_width: 'width: 15%;' } %>
21
+ </div>
22
+ <div style="display: table-cell;">
23
+ <strong style="margin-left: 10%; size: 10%">Job Information</strong>
24
+ <table id='naf_table_show' style="margin-left: 10%; width: 92.5%">
25
+ <thead>
26
+ <tr>
27
+ <td width="7%">ID</td>
28
+ <td>Command</td>
29
+ <td width="30%">Server</td>
30
+ <td width="8%">Pid</td>
31
+ <td width="15%">Status</td>
32
+ </tr>
33
+ </thead>
34
+ <tbody>
35
+ <tr>
36
+ <td><%= @job.id %></td>
37
+ <td style="white-space: pre-wrap;"><%= @job.command %></td>
38
+ <% logical_job = ::Logical::Naf::Job.new(@job) %>
39
+ <td><%= logical_job.runner %></td>
40
+ <td><%= @job.pid %></td>
41
+ <td class="<%= add_color(logical_job.status) %>"><%= logical_job.status %></td>
42
+ </tr>
43
+ </tbody>
44
+ </table>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </br>
49
+
50
+ <%= submit_tag("Search the logs", id: 'log_search_submit') %>
51
+ &nbsp;&nbsp;&nbsp;
52
+ <%= link_to 'Back to Job', { controller: 'historical_jobs', action: 'show', id: @job.id } %>
53
+ </div>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ </div>
59
+
60
+ <%= render partial: 'update_page_title', locals: { title: "Job(#{@job.id}) Logs" } %>
61
+ <%= render partial: 'naf/shared/auto_resize_width', locals: { div_class: '.scrollable-output-expanded' } %>
62
+ <%= render partial: 'log_display', locals: { record_id: @job.id,
63
+ status: logical_job.status,
64
+ logs_url: "#{http_protocol}#{logical_job.runner}#{naf.logs_log_parsers_path}",
65
+ record_type: 'job' } %>
@@ -0,0 +1,259 @@
1
+ <% content_for :javascripts do %>
2
+ <script type='text/javascript'>
3
+ var record_id = "<%= record_id %>";
4
+ var logical_type = null;
5
+ setLogicalType();
6
+ var logs_url = "<%= logs_url %>";
7
+ var search_params = null;
8
+ var regex_options = null;
9
+ var search_command = false;
10
+ var grep = false;
11
+ var search_date_from_year = '';
12
+ var search_date_from_month = '';
13
+ var search_date_from_day = '';
14
+ var search_date_from_hour = '';
15
+ var search_date_from_minute = '';
16
+ var search_date_to_year = '';
17
+ var search_date_to_month = '';
18
+ var search_date_to_day = '';
19
+ var search_date_to_hour = '';
20
+ var search_date_to_minute = '';
21
+ var show_help_window = false;
22
+ var logs = null;
23
+ var old_height = null;
24
+ var new_height = null;
25
+ var log_type = 'new';
26
+ var newest_log = null;
27
+ var read_from_s3 = false;
28
+ var last_file_checked = null;
29
+ var newest_file_checked = null;
30
+
31
+ jQuery(document).ready(function () {
32
+ jQuery(".description").hide();
33
+ getLog();
34
+ jQuery('#stdout').css('width', jQuery('#stdout').width());
35
+
36
+ jQuery('#log_search_submit').click(function () {
37
+ initializeVariables();
38
+
39
+ if(checkSearchDate(search_date_from_year, search_date_from_month, search_date_from_day,
40
+ search_date_from_hour, search_date_from_minute)){
41
+ log_type = 'old';
42
+ callAjax();
43
+ }
44
+ else{
45
+ resetDateFilters();
46
+ jQuery('#stdout').empty();
47
+ jQuery('#stdout').append('If specifying a date search, select a value for each dropdown (year/month/day/hour/minute)');
48
+ }
49
+ });
50
+
51
+ jQuery('#stdout').scroll(function (){
52
+ if(jQuery('#stdout').scrollTop() == 0 && jQuery('#stdout').text() != 'No logs were found for this search query! '){
53
+ log_type = 'old'
54
+ callAjax();
55
+ }
56
+ else if(jQuery('#stdout')[0].scrollHeight - jQuery('#stdout').scrollTop() == jQuery('#stdout').innerHeight()){
57
+ log_type = 'new'
58
+ newest_log = jQuery('#stdout')[0].children.item(jQuery('#stdout')[0].children.length - 1).textContent;
59
+
60
+ if(jQuery('#auto_scroll').text() == 'Auto Scroll (OFF)'){
61
+ jQuery('#auto_scroll').click();
62
+ }
63
+ }
64
+ else{
65
+ if(jQuery('#auto_scroll').text() == 'Auto Scroll (ON)'){
66
+ setAutoScrollOff();
67
+ }
68
+ }
69
+ });
70
+
71
+ jQuery("#regex_help").click(function() {
72
+ if(show_help_window == false){
73
+ jQuery(".description").show();
74
+ show_help_window = true;
75
+ }
76
+ else{
77
+ jQuery(".description").hide();
78
+ show_help_window = false;
79
+ }
80
+ });
81
+
82
+ jQuery('#auto_scroll').click(function(){
83
+ if(jQuery('#auto_scroll').text() == 'Auto Scroll (ON)'){
84
+ setAutoScrollOff();
85
+ }
86
+ else{
87
+ setAutoScrollOn();
88
+ jQuery("#stdout").scrollTop(jQuery('#stdout')[0].scrollHeight);
89
+ getLog();
90
+ }
91
+ });
92
+ });
93
+
94
+ function callAjax(){
95
+ jQuery.ajax({
96
+ url: logs_url,
97
+ dataType: 'jsonp',
98
+ jsonpCallback: 'convertToJsonCallback',
99
+ xhrFields: {
100
+ withCredentials: true
101
+ },
102
+ data: {
103
+ 'record_id': record_id,
104
+ 'logical_type': logical_type,
105
+ 'log_type': log_type,
106
+ 'newest_log': newest_log,
107
+ 'read_from_s3': read_from_s3,
108
+ 'last_file_checked': last_file_checked,
109
+ 'newest_file_checked': newest_file_checked,
110
+ 'search_params': jQuery('#log_search').val(),
111
+ 'regex_options': jQuery('#regex_options').val(),
112
+ 'grep': grep,
113
+ 'from_time': [search_date_from_year,
114
+ search_date_from_month,
115
+ search_date_from_day,
116
+ search_date_from_hour,
117
+ search_date_from_minute],
118
+ 'to_time': [search_date_to_year,
119
+ search_date_to_month,
120
+ search_date_to_day,
121
+ search_date_to_hour,
122
+ search_date_to_minute]
123
+ },
124
+ success: function(response) {
125
+ logs = response['logs'];
126
+ updateVariables(response);
127
+
128
+ if(search_command == true){
129
+ jQuery('#stdout').text('')
130
+ jQuery('#stdout').append(logs);
131
+ if(jQuery('#stdout').text() == '') {
132
+ logs = "No logs were found for this search query!<br>";
133
+ setAutoScrollOff();
134
+ }
135
+ jQuery("#stdout").scrollTop(jQuery('#stdout')[0].scrollHeight);
136
+
137
+ search_command = false;
138
+ }
139
+ else{
140
+ if(logs == '' && jQuery('#stdout')[0].children.length == 0) {
141
+ logs = "&nbsp;&nbsp;<span>No logs were found!<br></span>";
142
+ setAutoScrollOff();
143
+ }
144
+
145
+ if(logs != ''){
146
+ if(log_type == 'new'){
147
+ jQuery('#stdout').append(logs);
148
+ jQuery("#stdout").scrollTop(jQuery('#stdout')[0].scrollHeight);
149
+ }
150
+ else{
151
+ jQuery('#stdout').prepend(logs);
152
+ log_type = 'new';
153
+ if(old_height == null && new_height == null){
154
+ old_height = jQuery('#stdout')[0].scrollHeight;
155
+ new_height = jQuery('#stdout')[0].scrollHeight;
156
+ jQuery("#stdout").scrollTop(jQuery('#stdout')[0].scrollHeight - new_height + 1);
157
+ }
158
+ else{
159
+ old_height = new_height;
160
+ new_height = jQuery('#stdout')[0].scrollHeight;
161
+ jQuery("#stdout").scrollTop(new_height - old_height);
162
+ }
163
+ }
164
+ }
165
+ }
166
+ },
167
+ error: function(response) {
168
+ jQuery('#stdout').prepend('Something went wrong, retry your search.');
169
+ }
170
+ });
171
+ }
172
+
173
+ function getLog() {
174
+ if(jQuery('#auto_scroll').text() == 'Auto Scroll (ON)'){
175
+ callAjax();
176
+ setTimeout(getLog, 5000);
177
+ }
178
+ }
179
+
180
+ function initializeVariables(){
181
+ newest_log = null;
182
+ logs = null;
183
+ last_file_checked = null;
184
+ newest_file_checked = null;
185
+ show_help_window = false;
186
+ search_command = true;
187
+ grep = jQuery('#grep').is(':checked');
188
+ search_params = jQuery('#log_search').val();
189
+ regex_options = jQuery('#regex_options').val();
190
+ search_date_from_year = jQuery('#date_select_from_year').val();
191
+ search_date_from_month = jQuery('#date_select_from_month').val();
192
+ search_date_from_day = jQuery('#date_select_from_day').val();
193
+ search_date_from_hour = jQuery('#date_select_from_hour').val();
194
+ search_date_from_minute = jQuery('#date_select_from_minute').val();
195
+ search_date_to_year = jQuery('#date_select_to_year').val();
196
+ search_date_to_month = jQuery('#date_select_to_month').val();
197
+ search_date_to_day = jQuery('#date_select_to_day').val();
198
+ search_date_to_hour = jQuery('#date_select_to_hour').val();
199
+ search_date_to_minute = jQuery('#date_select_to_minute').val();
200
+ }
201
+
202
+ function resetDateFilters(){
203
+ search_date_from_year = '';
204
+ search_date_from_month = '';
205
+ search_date_from_day = '';
206
+ search_date_from_hour = '';
207
+ search_date_from_minute = '';
208
+ search_date_to_year = '';
209
+ search_date_to_month = '';
210
+ search_date_to_day = '';
211
+ search_date_to_hour = '';
212
+ search_date_to_minute = '';
213
+ }
214
+
215
+ function updateVariables(response){
216
+ if(response['read_from_s3'] != ''){
217
+ read_from_s3 = response['read_from_s3'];
218
+ }
219
+ if(response['last_file_checked'] != ''){
220
+ last_file_checked = response['last_file_checked'];
221
+ }
222
+ if(response['newest_file_checked'] != ''){
223
+ newest_file_checked = response['newest_file_checked'];
224
+ }
225
+ if(response['newest_log'] != ''){
226
+ newest_log = response['newest_log'];
227
+ }
228
+ }
229
+
230
+ function checkSearchDate(year, month, day, hour, minute){
231
+ return (year == '' && month == '' && day == '' && hour == '' && minute == '') ||
232
+ (year != '' && month != '' && day != '' && hour != '' && minute != '')
233
+ }
234
+
235
+ function setLogicalType(){
236
+ logical_type = '::Logical::Naf::LogParser::';
237
+ if('<%= record_type %>' == 'machine'){
238
+ logical_type += 'Machine';
239
+ }
240
+ else if('<%= record_type %>' == 'runner'){
241
+ logical_type += 'Runner';
242
+ }
243
+ else if('<%= record_type %>' == 'job'){
244
+ logical_type += 'Job';
245
+ }
246
+ }
247
+
248
+ function setAutoScrollOn(){
249
+ jQuery('#auto_scroll').text('Auto Scroll (ON)');
250
+ jQuery('#auto_scroll').removeClass('auto_scroll_off');
251
+ }
252
+
253
+ function setAutoScrollOff(){
254
+ jQuery('#auto_scroll').text('Auto Scroll (OFF)');
255
+ jQuery('#auto_scroll').addClass('auto_scroll_off');
256
+ }
257
+
258
+ </script>
259
+ <% end %>