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