<% if @object.log and !@object.log.empty? %>
<% logcollection = Collection.find @object.log %>
<% if logcollection %>
- log_size = <%= logcollection.files[0][2] %>
- log_maxbytes = <%= Rails.configuration.log_viewer_max_bytes %>;
- logcollection_url = '<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>';
+ var log_size = <%= logcollection.files[0][2] %>
+ var log_maxbytes = <%= Rails.configuration.log_viewer_max_bytes %>;
+ var logcollection_url = '<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>';
$("#log-viewer-download-url").attr('href', logcollection_url);
$("#log-viewer-download-pane").show();
+ var headers = {};
if (log_size > log_maxbytes) {
- range_header = { 'Range': 'bytes=0-' + log_maxbytes };
- } else {
- range_header = null;
+ headers['Range'] = 'bytes=0-' + log_maxbytes;
}
- $.ajax(logcollection_url, { headers: range_header }).
- done(function(data, status, jqxhr) {
- logViewer.filter();
- addToLogViewer(logViewer, data.split("\n"), taskState);
- logViewer.filter(makeFilter());
- content_range_hdr = jqxhr.getResponseHeader('Content-Range');
- var v = content_range_hdr && content_range_hdr.match(/bytes \d+-(\d+)\/(.+)/);
- short_log = v && (v[2] == '*' || parseInt(v[1]) + 1 < v[2]);
- if (jqxhr.status == 206 && short_log) {
- $("#log-viewer-overview").html(
- '<p>Showing only ' + data.length + ' bytes of this log.' +
- ' Timing information is unavailable since' +
- ' the full log was not retrieved.</p>'
- );
- } else {
- generateJobOverview("#log-viewer-overview", logViewer, taskState);
+ var ajax_opts = { dataType: 'text', headers: headers };
+ load_log();
+
+ function load_log() {
+ $.ajax(logcollection_url, ajax_opts).done(done).fail(fail);
+ }
+ function done(data, status, jqxhr) {
+ if (jqxhr.getResponseHeader('Content-Type').indexOf('application/json') === 0) {
+ // The browser won't allow a redirect-with-cookie response
+ // because keep-web isn't same-origin with us. Instead, we
+ // assure keep-web it's OK to respond with the content
+ // immediately by setting the token in the request body
+ // instead and adding disposition=attachment.
+ logcollection_url = JSON.parse(data).href;
+ var queryAt = logcollection_url.indexOf('?api_token=');
+ if (queryAt >= 0) {
+ ajax_opts.method = 'POST';
+ ajax_opts.data = {
+ api_token: logcollection_url.slice(queryAt+11),
+ disposition: 'attachment',
+ };
+ logcollection_url = logcollection_url.slice(0, queryAt);
}
- $("#log-viewer .spinner").detach();
- }).
- fail(function(jqxhr, status, error) {
- $("#log-viewer .spinner").detach();
- });
+ return load_log();
+ }
+ logViewer.filter();
+ addToLogViewer(logViewer, data.split("\n"), taskState);
+ logViewer.filter(makeFilter());
+ content_range_hdr = jqxhr.getResponseHeader('Content-Range');
+ var v = content_range_hdr && content_range_hdr.match(/bytes \d+-(\d+)\/(.+)/);
+ short_log = v && (v[2] == '*' || parseInt(v[1]) + 1 < v[2]);
+ if (jqxhr.status == 206 && short_log) {
+ $("#log-viewer-overview").html(
+ '<p>Showing only ' + data.length + ' bytes of this log.' +
+ ' Timing information is unavailable since' +
+ ' the full log was not retrieved.</p>'
+ );
+ } else {
+ generateJobOverview("#log-viewer-overview", logViewer, taskState);
+ }
+ $("#log-viewer .spinner").detach();
+ }
+ function fail(jqxhr, status, error) {
+ // TODO: tell the user about the error
+ console.log('load_log failed: status='+status+' error='+error);
+ $("#log-viewer .spinner").detach();
+ }
<% end %>
<% else %>
<%# Live log loading not implemented yet. %>
require 'integration_helper'
class JobsTest < ActionDispatch::IntegrationTest
+ include KeepWebConfig
+
setup do
need_javascript
end
assert page.has_text? 'Showing only 100 bytes of this log'
end
+ test 'view log via keep-web redirect' do
+ use_keep_web_config
+
+ token = api_fixture('api_client_authorizations')['active']['api_token']
+ logdata = fakepipe_with_log_data.read
+ logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
+ assert $?.success?, $?
+
+ job = nil
+ use_token 'active' do
+ job = Job.find api_fixture('jobs')['running']['uuid']
+ mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
+ logcollection = Collection.create(manifest_text: mtxt)
+ job.update_attributes log: logcollection.portable_data_hash
+ end
+ visit page_with_token 'active', '/jobs/'+job.uuid
+ find('a[href="#Log"]').click
+ assert_text 'log message 1'
+ end
+
[
['foobar', false, false],
['job_with_latest_version', true, false],