[ARVADOS] created: c9edd85708b7991c21284d93a6cfc497dd3f3975

Git user git at public.curoverse.com
Fri Jun 24 17:16:36 EDT 2016


        at  c9edd85708b7991c21284d93a6cfc497dd3f3975 (commit)


commit c9edd85708b7991c21284d93a6cfc497dd3f3975
Author: radhika <radhika at curoverse.com>
Date:   Fri Jun 24 17:16:12 2016 -0400

    9407: container log view

diff --git a/apps/workbench/app/models/container_work_unit.rb b/apps/workbench/app/models/container_work_unit.rb
index 037a6e5..ed7ae7e 100644
--- a/apps/workbench/app/models/container_work_unit.rb
+++ b/apps/workbench/app/models/container_work_unit.rb
@@ -124,6 +124,17 @@ class ContainerWorkUnit < ProxyWorkUnit
     get_combined(:output_path)
   end
 
+  def live_log_lines(limit=2000)
+    event_types = ["stdout", "stderr", "arv-mount", "crunch-run"]
+    log_lines = Log.where(event_type: event_types, object_uuid: uuid).order("id DESC").limit(limit)
+    log_lines.results.reverse.
+      flat_map { |log| log.properties[:text].split("\n") rescue [] }
+  end
+
+  def render_log(log)
+    ['collections/show_files', {object: log, no_checkboxes: true}]
+  end
+
   # End combined propeties
 
   protected
diff --git a/apps/workbench/app/models/work_unit.rb b/apps/workbench/app/models/work_unit.rb
index 1c2d02f..e630835 100644
--- a/apps/workbench/app/models/work_unit.rb
+++ b/apps/workbench/app/models/work_unit.rb
@@ -179,4 +179,12 @@ class WorkUnit
   def container_uuid
     # container_uuid of a container_request
   end
+
+  def live_log_lines(limit)
+    # fetch log entries from logs table for @proxied
+  end
+
+  def render_log(log)
+    # return partial and locals to be rendered
+  end
 end
diff --git a/apps/workbench/app/views/collections/_show_files.html.erb b/apps/workbench/app/views/collections/_show_files.html.erb
index e3c79f1..a21a514 100644
--- a/apps/workbench/app/views/collections/_show_files.html.erb
+++ b/apps/workbench/app/views/collections/_show_files.html.erb
@@ -9,6 +9,8 @@
   end
 %>
 
+<% object = @object unless object %>
+
 <div class="selection-action-container" style="padding-left: <%=padding_left%>">
   <% if Collection.creatable? and (!defined? no_checkboxes or !no_checkboxes) %>
     <div class="row">
@@ -19,7 +21,7 @@
             <li><%= link_to "Create new collection with selected files", '#',
                     method: :post,
                     'data-href' => combine_selected_path(
-                      action_data: {current_project_uuid: @object.owner_uuid}.to_json
+                      action_data: {current_project_uuid: object.owner_uuid}.to_json
                     ),
                     'data-selection-param-name' => 'selection[]',
                     'data-selection-action' => 'combine-collections',
@@ -39,7 +41,7 @@
     <p/>
   <% end %>
 
-  <% file_tree = @object.andand.files_tree %>
+  <% file_tree = object.andand.files_tree %>
   <% if file_tree.nil? or file_tree.empty? %>
     <p>This collection is empty.</p>
   <% else %>
@@ -59,8 +61,8 @@
         <ul class="collection_files">
       <% else %>
         <% link_params = {controller: 'collections', action: 'show_file',
-                          uuid: @object.portable_data_hash, file: file_path, size: size} %>
-         <div class="collection_files_row filterable <%=preview_selectable%>" href="<%=@object.uuid%>/<%=file_path%>">
+                          uuid: object.portable_data_hash, file: file_path, size: size} %>
+         <div class="collection_files_row filterable <%=preview_selectable%>" href="<%=object.uuid%>/<%=file_path%>">
           <div class="collection_files_buttons pull-right">
             <%= raw(human_readable_bytes_html(size)) %>
             <%= link_to(raw('<i class="fa fa-search"></i>'),
@@ -73,27 +75,27 @@
 
           <div class="collection_files_name">
             <% if (!defined? no_checkboxes or !no_checkboxes) and current_user %>
-            <%= check_box_tag 'uuids[]', "#{@object.uuid}/#{file_path}", false, {
+            <%= check_box_tag 'uuids[]', "#{object.uuid}/#{file_path}", false, {
                   :class => "persistent-selection",
                   :friendly_type => "File",
-                  :friendly_name => "#{@object.uuid}/#{file_path}",
+                  :friendly_name => "#{object.uuid}/#{file_path}",
                   :href => url_for(controller: 'collections', action: 'show_file',
-                                   uuid: @object.portable_data_hash, file: file_path),
+                                   uuid: object.portable_data_hash, file: file_path),
                   :title => "Include #{file_path} in your selections",
-                  :id => "#{@object.uuid}_file_#{index}",
+                  :id => "#{object.uuid}_file_#{index}",
                 } %>
             <span> </span>
             <% end %>
         <% if CollectionsHelper::is_image(filename) %>
             <i class="fa fa-fw fa-bar-chart-o"></i> <%= filename %></div>
           <div class="collection_files_inline">
-            <%= link_to(image_tag("#{url_for @object}/#{file_path}"),
+            <%= link_to(image_tag("#{url_for object}/#{file_path}"),
                         link_params.merge(disposition: 'inline'),
                         {title: file_path}) %>
           </div>
          </div>
         <% else %>
-            <i class="fa fa-fw fa-file" href="<%=@object.uuid%>/<%=file_path%>" ></i> <%= filename %></div>
+            <i class="fa fa-fw fa-file" href="<%=object.uuid%>/<%=file_path%>" ></i> <%= filename %></div>
          </div>
         <% end %>
         </li>
diff --git a/apps/workbench/app/views/container_requests/_show_log.html.erb b/apps/workbench/app/views/container_requests/_show_log.html.erb
new file mode 100644
index 0000000..4126f12
--- /dev/null
+++ b/apps/workbench/app/views/container_requests/_show_log.html.erb
@@ -0,0 +1 @@
+<%= render(partial: 'work_unit/show_log', locals: {obj: @object, name: @object[:name] || 'this container'}) %>
diff --git a/apps/workbench/app/views/containers/_show_log.html.erb b/apps/workbench/app/views/containers/_show_log.html.erb
new file mode 100644
index 0000000..4126f12
--- /dev/null
+++ b/apps/workbench/app/views/containers/_show_log.html.erb
@@ -0,0 +1 @@
+<%= render(partial: 'work_unit/show_log', locals: {obj: @object, name: @object[:name] || 'this container'}) %>
diff --git a/apps/workbench/app/views/work_unit/_show_log.html.erb b/apps/workbench/app/views/work_unit/_show_log.html.erb
new file mode 100644
index 0000000..12a96c4
--- /dev/null
+++ b/apps/workbench/app/views/work_unit/_show_log.html.erb
@@ -0,0 +1,29 @@
+<% wu = obj.work_unit(name) %>
+
+<% if !wu.log_collection %>
+  <%# Still running. Show running log. %>
+  <div id="event_log_div"
+       class="arv-log-event-listener arv-log-event-handler-append-logs arv-job-log-window"
+       data-object-uuid="<%= wu.uuid %>"
+    ><%= wu.live_log_lines(Rails.configuration.running_job_log_records_to_fetch).join("\n") %>
+  </div>
+
+  <%# Applying a long throttle suppresses the auto-refresh of this
+      partial that would normally be triggered by arv-log-event. %>
+  <div class="arv-log-refresh-control"
+       data-load-throttle="86486400000" <%# 1001 nights %>>
+  </div>
+
+<% else %>
+  <%# Finished running. Show log if exists. %>
+  <% log = Collection.find wu.log_collection rescue nil %>
+  <% if log %>
+    <div>
+      <% log_url = url_for log %>
+      <p> <a href="<%= log_url %>">Download the full log</a> </p>
+      <%= render(partial: wu.render_log(log)[0], locals: wu.render_log(log)[1]) %>
+    </div>
+  <% else %>
+    <div> Log not accessible </div>
+  <% end %>
+<% end %>
diff --git a/apps/workbench/test/controllers/container_requests_controller_test.rb b/apps/workbench/test/controllers/container_requests_controller_test.rb
new file mode 100644
index 0000000..77c5d1c
--- /dev/null
+++ b/apps/workbench/test/controllers/container_requests_controller_test.rb
@@ -0,0 +1,17 @@
+require 'test_helper'
+
+class ContainerRequestsControllerTest < ActionController::TestCase
+  test "visit container_request log" do
+    use_token 'active'
+
+    cr = api_fixture('container_requests')['completed']
+    container_uuid = cr['container_uuid']
+    container = Container.find(container_uuid)
+
+    get :show, {id: cr['uuid'], tab_pane: 'Log'}, session_for(:active)
+    assert_response :success
+
+    assert_includes @response.body, "<a href=\"/collections/#{container['log']}\">Download the full log</a>"
+    assert_includes @response.body, "<div class=\"collection_files_row filterable \" href=\"#{container['log']}/baz\">"
+  end
+end
diff --git a/apps/workbench/test/controllers/containers_controller_test.rb b/apps/workbench/test/controllers/containers_controller_test.rb
new file mode 100644
index 0000000..92407af
--- /dev/null
+++ b/apps/workbench/test/controllers/containers_controller_test.rb
@@ -0,0 +1,15 @@
+require 'test_helper'
+
+class ContainersControllerTest < ActionController::TestCase
+  test "visit container log" do
+    use_token 'active'
+
+    container = api_fixture('containers')['completed']
+
+    get :show, {id: container['uuid'], tab_pane: 'Log'}, session_for(:active)
+    assert_response :success
+
+    assert_includes @response.body, "<a href=\"/collections/#{container['log']}\">Download the full log</a>"
+    assert_includes @response.body, "<div class=\"collection_files_row filterable \" href=\"#{container['log']}/baz\">"
+  end
+end
diff --git a/apps/workbench/test/integration/websockets_test.rb b/apps/workbench/test/integration/websockets_test.rb
index 655ad92..bc8b5cd 100644
--- a/apps/workbench/test/integration/websockets_test.rb
+++ b/apps/workbench/test/integration/websockets_test.rb
@@ -27,9 +27,12 @@ class WebsocketTest < ActionDispatch::IntegrationTest
     assert_text '123 hello'
   end
 
-
-  [["pipeline_instances", api_fixture("pipeline_instances")['pipeline_with_newer_template']['uuid']],
-   ["jobs", api_fixture("jobs")['running']['uuid']]].each do |c|
+  [
+   ["pipeline_instances", api_fixture("pipeline_instances")['pipeline_with_newer_template']['uuid']],
+   ["jobs", api_fixture("jobs")['running']['uuid']],
+   ["containers", api_fixture("containers")['running']['uuid']],
+   ["container_requests", api_fixture("container_requests")['running']['uuid']],
+  ].each do |c|
     test "test live logging scrolling #{c[0]}" do
 
       controller = c[0]
diff --git a/services/api/test/fixtures/containers.yml b/services/api/test/fixtures/containers.yml
index 1796e49..79e472b 100644
--- a/services/api/test/fixtures/containers.yml
+++ b/services/api/test/fixtures/containers.yml
@@ -76,6 +76,7 @@ completed:
   finished_at: 2016-01-12 11:12:13.111111111 Z
   container_image: test
   cwd: test
+  log: ea10d51bcf88862dbcc36eb292017dfd+45
   output: zzzzz-4zz18-znfnqtbbv4spc3w
   output_path: test
   command: ["echo", "hello"]

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list