[ARVADOS] updated: 521df5cd1e19a671a4f940128c5c61930df9c8bb

git at public.curoverse.com git at public.curoverse.com
Mon Sep 29 18:02:23 EDT 2014


Summary of changes:
 .../app/controllers/collections_controller.rb      | 30 ++++++++++++++--------
 apps/workbench/app/views/jobs/_show_log.html.erb   | 20 +++++++++++++--
 apps/workbench/config/application.default.yml      |  3 +++
 3 files changed, 40 insertions(+), 13 deletions(-)

       via  521df5cd1e19a671a4f940128c5c61930df9c8bb (commit)
      from  641a04fc2dd876440ed983a4cdf0e03f188040c1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 521df5cd1e19a671a4f940128c5c61930df9c8bb
Author: Tim Pierce <twp at curoverse.com>
Date:   Mon Sep 29 17:55:17 2014 -0400

    3782: keep log viewer code in _show_log.html.erb
    
    Keep log-related restrictions in the log viewer and not in general
    purpose workbench code:
    
    * Add Rails.configuration.log_viewer_max_bytes to specify the maximum
      number of log bytes to display
    * The log viewer specifies a byte limit via the HTTP Range header. The
      Content-Length of the response is set to the minimum of the 'size'
      query parameter and the byte range. If the log appears to have been
      truncated, the viewer reports it in the 'log_viewer_overview' pane.
    * CollectionsController.FileStreamer either delivers the entire file
      or exactly opts[:maxbytes] bytes, whichever comes first.  It does not
      add any log-specific message.

diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index bdfa832..baa7661 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -148,11 +148,24 @@ class CollectionsController < ApplicationController
     elsif params[:file].nil? or not coll.manifest.has_file?(params[:file])
       return render_not_found
     end
+
     opts = params.merge(arvados_api_token: usable_token)
+    if request.headers.include? 'HTTP_RANGE'
+      # Currently only 'bytes=0-....' is supported.
+      if m = /^bytes=0-(\d+)/.match(request.headers['HTTP_RANGE'])
+        opts[:maxbytes] = m[1]
+      end
+    end
     ext = File.extname(params[:file])
     self.response.headers['Content-Type'] =
       Rack::Mime::MIME_TYPES[ext] || 'application/octet-stream'
-    self.response.headers['Content-Length'] = params[:size] if params[:size]
+    if params[:size]
+      size = params[:size].to_i
+      if opts[:maxbytes]
+        size = [size, opts[:maxbytes].to_i].min
+      end
+      self.response.headers['Content-Length'] = size.to_s
+    end
     self.response.headers['Content-Disposition'] = params[:disposition] if params[:disposition]
     self.response_body = file_enumerator opts
   end
@@ -297,25 +310,20 @@ class CollectionsController < ApplicationController
       env['ARVADOS_API_TOKEN'] = @opts[:arvados_api_token]
       env['ARVADOS_API_HOST_INSECURE'] = "true" if Rails.configuration.arvados_insecure_https
 
-      bytesleft = @opts[:size].andand.to_i || 2**16
+      bytesleft = @opts[:maxbytes].andand.to_i || 2**16
+      Rails.logger.warn "@opts[:maxbytes] = #{@opts[:maxbytes]}, bytesleft = #{bytesleft}"
       IO.popen([env, 'arv-get', "#{@opts[:uuid]}/#{@opts[:file]}"],
                'rb') do |io|
+        bytecount = 0
         while bytesleft > 0 && buf = io.read(bytesleft)
           # shrink the bytesleft count, if we were given a
           # maximum byte count to read
-          if @opts.include? :size
+          if @opts.include? :maxbytes
             bytesleft = bytesleft - buf.length
+            Rails.logger.warn "bytesleft now #{bytesleft}"
           end
           yield buf
         end
-        if buf and @opts.include? :size and bytesleft == 0 then
-          unless buf[-1] == "\n"
-            yield "\n"
-          end
-          # This line should match the regex in
-          # app/assets/javascripts/log_viewer.js:addToLogViewer()
-          yield Time.now.strftime("%F_%T zzzzz-zzzzz-zzzzzzzzzzzzzzz 0  File truncated (exceeded #{@opts[:size]} bytes). To retrieve the full file: arv-get #{@opts[:uuid]}/#{@opts[:file]}\n")
-        end
       end
       Rails.logger.warn("#{@opts[:uuid]}/#{@opts[:file]}: #{$?}") if $? != 0
     end
diff --git a/apps/workbench/app/views/jobs/_show_log.html.erb b/apps/workbench/app/views/jobs/_show_log.html.erb
index 377eba0..aaae89a 100644
--- a/apps/workbench/app/views/jobs/_show_log.html.erb
+++ b/apps/workbench/app/views/jobs/_show_log.html.erb
@@ -53,12 +53,27 @@ var makeFilter = function() {
 <% if @object.log %>
   <% logcollection = Collection.find @object.log %>
   <% if logcollection %>
-    $.ajax('<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>?size=1000000').
+    var log_maxbytes = <%= Rails.configuration.log_viewer_max_bytes %>
+    $.ajax('<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>',
+	   {
+	     headers: {'Range': 'bytes=0-' + log_maxbytes}
+	   }).
 	done(function(data, status, jqxhr) {
 	    logViewer.filter();
 	    addToLogViewer(logViewer, data.split("\n"), taskState);
 	    logViewer.filter(makeFilter());
-	    generateJobOverview("#log-viewer-overview", logViewer, taskState);
+	    if (data.length == log_maxbytes) {
+	      $("#log-viewer-overview").html(
+		'<p>The log was truncated after ' + log_maxbytes +
+		' bytes. To view the entire log, run this command' +
+		' from an Arvados shell VM:</p>' +
+		' <p><span style="font-family:monospace">arv-get' +
+		' <%=j logcollection.uuid %>/<%=j logcollection.files[0][1] %>' +
+		'</p>'
+	      );
+            } else {
+	      generateJobOverview("#log-viewer-overview", logViewer, taskState);
+	    }
 	    $("#log-viewer .spinner").detach();
 	}).
 	fail(function(jqxhr, status, error) {
@@ -217,6 +232,7 @@ $("#set-show-failed-only").on("click", function() {
     <span class="log-viewer-paging"></span>
     <a href="#" class="log-viewer-page-down"><span class='glyphicon glyphicon-arrow-down'></span></a>
   </div>
+
 </div>
 
 <% end %>
diff --git a/apps/workbench/config/application.default.yml b/apps/workbench/config/application.default.yml
index e43d94b..7eb6c8b 100644
--- a/apps/workbench/config/application.default.yml
+++ b/apps/workbench/config/application.default.yml
@@ -170,3 +170,6 @@ common:
 
   # filename suffixes for which view icon would be shown in collection show page
   filename_suffixes_with_view_icon: [txt, gif, jpeg, jpg, png, html, htm, pdf]
+
+  # the maximum number of bytes to load in the log viewer
+  log_viewer_max_bytes: 1000000

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list