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