4233: unused variable removed
[arvados.git] / apps / workbench / app / views / jobs / _show_log.html.erb
1 <% if !@object.log %>
2
3 <div id="log_graph_div"
4      class="arv-log-event-listener"
5      data-object-uuid="<%= @object.uuid %>"></div>
6
7 <% log_history = stderr_log_history([@object.uuid]) %>
8
9 <div id="event_log_div"
10      class="arv-log-event-listener arv-log-event-handler-append-logs arv-job-log-window"
11      data-object-uuid="<%= @object.uuid %>"
12      ><%= log_history.join("\n") %></div>
13
14 <%# Applying a long throttle suppresses the auto-refresh of this
15     partial that would normally be triggered by arv-log-event. %>
16 <div class="arv-log-refresh-control"
17      data-load-throttle="86486400000" <%# 1001 nights %>
18      ></div>
19
20 <%= javascript_tag do %>
21   window.jobGraphData = [];
22   window.jobGraphSeries = [];
23   window.jobGraphMaxima = {};
24   <% stderr_log_records([@object.uuid],[['properties','~','crunchstat:.*-- interval']])
25         .each do |log_record| %>
26     processLogLineForChart( '<%=j log_record.properties[:text] %>' );
27   <% end %>
28   createJobGraph('log_graph_div');
29 <% end %>
30
31 <% else %>
32
33 <script>
34 (function() {
35 var pagesize = 1000;
36 var logViewer = new List('log-viewer', {
37   valueNames: [ 'id', 'timestamp', 'taskid', 'message', 'type'],
38   page: pagesize
39 });
40
41 logViewer.page_offset = 0;
42 logViewer.on("updated", function() { updatePaging(".log-viewer-paging", logViewer, pagesize) } );
43 $(".log-viewer-page-up").on("click", function() { prevPage(logViewer, pagesize, ".log-viewer-paging"); return false; });
44 $(".log-viewer-page-down").on("click", function() { nextPage(logViewer, pagesize, ".log-viewer-paging"); return false; });
45
46 var taskState = newTaskState();
47
48 var makeFilter = function() {
49   var pass = [];
50   $(".toggle-filter, .radio-filter").each(function(i, e) {
51     if (e.checked) {
52       pass.push(e.id.substr(5));
53     }
54   });
55
56   return (function(item) {
57     var v = false;
58     if (item.values().taskid !== "") {
59       for (a in pass) {
60         if (pass[a] == "all-tasks") { v = true; }
61         else if (pass[a] == "successful-tasks" && taskState[item.values().taskid].outcome == "success") { v = true; }
62         else if (pass[a] == "failed-tasks" && taskState[item.values().taskid].outcome == "failure") { v = true; }
63       }
64     } else {
65       v = true;
66     }
67     for (a in pass) {
68       if (pass[a] == item.values().type) { return v; }
69     }
70     return false;
71   });
72 }
73
74 <% if @object.log %>
75   <% logcollection = Collection.find @object.log %>
76   <% if logcollection %>
77     log_size = <%= logcollection.files[0][2] %>
78     log_maxbytes = <%= Rails.configuration.log_viewer_max_bytes %>;
79     logcollection_url = '<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>';
80     $("#log-viewer-download-url").attr('href', logcollection_url);
81     $("#log-viewer-download-pane").show();
82     if (log_size > log_maxbytes) {
83       range_header = { 'Range': 'bytes=0-' + log_maxbytes };
84     } else {
85       range_header = null;
86     }
87     $.ajax(logcollection_url, { headers: range_header }).
88         done(function(data, status, jqxhr) {
89             logViewer.filter();
90             addToLogViewer(logViewer, data.split("\n"), taskState);
91             logViewer.filter(makeFilter());
92             content_range_hdr = jqxhr.getResponseHeader('Content-Range');
93             var v = content_range_hdr && content_range_hdr.match(/bytes \d+-(\d+)\/(.+)/);
94             short_log = v && (v[2] == '*' || parseInt(v[1]) + 1 < v[2]);
95             if (jqxhr.status == 206 && short_log) {
96               $("#log-viewer-overview").html(
97                 '<p>Showing only ' + data.length + ' bytes of this log.' +
98                 ' Timing information is unavailable since' +
99                 ' the full log was not retrieved.</p>'
100               );
101             } else {
102               generateJobOverview("#log-viewer-overview", logViewer, taskState);
103             }
104             $("#log-viewer .spinner").detach();
105         }).
106         fail(function(jqxhr, status, error) {
107             $("#log-viewer .spinner").detach();
108         });
109   <% end %>
110 <% else %>
111   <%# Live log loading not implemented yet. %>
112 <% end %>
113
114 $(".toggle-filter, .radio-filter").on("change", function() {
115   logViewer.filter(makeFilter());
116 });
117
118 $("#filter-all").on("click", function() {
119   $(".toggle-filter").each(function(i, f) { f.checked = true; });
120   logViewer.filter(makeFilter());
121 });
122
123 $("#filter-none").on("click", function() {
124   $(".toggle-filter").each(function(i, f) { f.checked = false; console.log(f); });
125   logViewer.filter(makeFilter());
126 });
127
128 $("#sort-by-time").on("change", function() {
129   logViewer.sort("id", {sortFunction: sortById});
130 });
131
132 $("#sort-by-task").on("change", function() {
133   logViewer.sort("taskid", {sortFunction: sortByTask});
134 });
135
136 $("#sort-by-node").on("change", function() {
137   logViewer.sort("node", {sortFunction: sortByNode});
138 });
139
140 $("#set-show-failed-only").on("click", function() {
141   $("#sort-by-task").prop("checked", true);
142   $("#show-failed-tasks").prop("checked", true);
143   $("#show-crunch").prop("checked", false);
144   $("#show-task-dispatch").prop("checked", true);
145   $("#show-script-print").prop("checked", true);
146   $("#show-crunchstat").prop("checked", false);
147   logViewer.filter(makeFilter());
148   logViewer.sort("taskid", {sortFunction: sortByTask});
149 });
150
151 })();
152
153 </script>
154
155 <div id="log-viewer">
156
157   <h3>Summary</h3>
158   <p id="log-viewer-overview">
159     <% if !logcollection %>
160       The collection containing the job log was not found.
161     <% end %>
162   </p>
163
164   <p id="log-viewer-download-pane" style="display:none">
165     <a id="log-viewer-download-url" href="">Download the full log</a>
166   </p>
167
168   <div class="h3">Log
169
170     <span class="pull-right">
171       <% if @object.andand.tasks_summary.andand[:failed] and @object.tasks_summary[:failed] > 0 %>
172         <button id="set-show-failed-only" class="btn btn-danger">
173           Show failed task diagnostics only
174         </button>
175       <% end %>
176
177       <button id="filter-all" class="btn">
178         Select all
179       </button>
180       <button id="filter-none" class="btn">
181         Select none
182       </button>
183     </span>
184   </div>
185
186   <input class="search pull-right" style="margin-top: 1em" placeholder="Search" />
187
188   <div>
189     <div class="radio-inline log-viewer-button" style="margin-left: 10px">
190       <label><input id="sort-by-time" type="radio" name="sort-radio" checked> Sort by time</label>
191     </div>
192     <div class="radio-inline log-viewer-button">
193       <label><input id="sort-by-node" type="radio" name="sort-radio" > Sort by node</label>
194     </div>
195
196     <div class="radio-inline log-viewer-button">
197       <label><input id="sort-by-task" type="radio" name="sort-radio" > Sort by task</label>
198     </div>
199   </div>
200
201   <div>
202     <div class="radio-inline log-viewer-button" style="margin-left: 10px">
203       <label><input id="show-all-tasks" type="radio" name="show-tasks-group" checked="true" class="radio-filter"> Show all tasks</label>
204     </div>
205     <div class="radio-inline log-viewer-button">
206       <label><input id="show-successful-tasks" type="radio" name="show-tasks-group" class="radio-filter"> Only successful tasks</label>
207     </div>
208     <div class="radio-inline log-viewer-button">
209       <label><input id="show-failed-tasks" type="radio" name="show-tasks-group" class="radio-filter"> Only failed tasks</label>
210     </div>
211   </div>
212
213   <div>
214     <div class="checkbox-inline log-viewer-button" style="margin-left: 10px">
215       <label><input id="show-crunch" type="checkbox" checked="true" class="toggle-filter"> Show crunch diagnostics</label>
216     </div>
217     <div class="checkbox-inline log-viewer-button">
218       <label><input id="show-task-dispatch" type="checkbox" checked="true" class="toggle-filter"> Show task dispatch</label>
219     </div>
220     <div class="checkbox-inline log-viewer-button">
221       <label><input id="show-task-print" type="checkbox" checked="true" class="toggle-filter"> Show task diagnostics</label>
222     </div>
223     <div class="checkbox-inline log-viewer-button">
224       <label><input id="show-crunchstat" type="checkbox" checked="true" class="toggle-filter"> Show compute usage</label>
225     </div>
226
227   </div>
228
229   <div class="smart-scroll" data-smart-scroll-padding-bottom="50" style="margin-bottom: 0px">
230     <table class="log-viewer-table">
231       <thead>
232         <tr>
233           <th class="id" data-sort="id"></th>
234           <th class="timestamp" data-sort="timestamp">Timestamp</th>
235           <th class="node"  data-sort="node">Node</th>
236           <th class="slot"  data-sort="slot">Slot</th>
237           <th class="type" data-sort="type">Log type</th>
238           <th class="taskid"  data-sort="taskid">Task</th>
239           <th class="message" data-sort="message">Message</th>
240         </tr>
241       </thead>
242       <tbody class="list">
243         <tr>
244           <td class="id"></td>
245           <td class="timestamp"></td>
246           <td class="node"></td>
247           <td class="slot"></td>
248           <td class="type"></td>
249           <td class="taskid"></td>
250           <td class="message"></td>
251         </tr>
252       </tbody>
253     </table>
254
255     <% if @object.log and logcollection %>
256       <div class="spinner spinner-32px"></div>
257     <% end %>
258
259   </div>
260
261   <div class="log-viewer-paging-div" style="margin-bottom: -15px">
262     <a href="#" class="log-viewer-page-up"><span class='glyphicon glyphicon-arrow-up'></span></a>
263     <span class="log-viewer-paging"></span>
264     <a href="#" class="log-viewer-page-down"><span class='glyphicon glyphicon-arrow-down'></span></a>
265   </div>
266
267 </div>
268
269 <% end %>