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