From 8c4542afc387211a36cc90f8085f229ff314854e Mon Sep 17 00:00:00 2001 From: radhika Date: Fri, 24 Jun 2016 17:16:12 -0400 Subject: [PATCH] 9407: container log view --- .../assets/javascripts/pipeline_instances.js | 2 +- .../app/models/container_work_unit.rb | 14 +++++++++++ apps/workbench/app/models/work_unit.rb | 8 +++++++ .../views/collections/_show_files.html.erb | 22 +++++++++-------- .../container_requests/_show_log.html.erb | 1 + .../app/views/containers/_show_log.html.erb | 1 + .../app/views/work_unit/_show_log.html.erb | 24 +++++++++++++++++++ .../container_requests_controller_test.rb | 17 +++++++++++++ .../controllers/containers_controller_test.rb | 15 ++++++++++++ .../test/integration/websockets_test.rb | 9 ++++--- services/api/test/fixtures/containers.yml | 1 + 11 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 apps/workbench/app/views/container_requests/_show_log.html.erb create mode 100644 apps/workbench/app/views/containers/_show_log.html.erb create mode 100644 apps/workbench/app/views/work_unit/_show_log.html.erb create mode 100644 apps/workbench/test/controllers/container_requests_controller_test.rb create mode 100644 apps/workbench/test/controllers/containers_controller_test.rb diff --git a/apps/workbench/app/assets/javascripts/pipeline_instances.js b/apps/workbench/app/assets/javascripts/pipeline_instances.js index 8bb25c13c0..1617a92992 100644 --- a/apps/workbench/app/assets/javascripts/pipeline_instances.js +++ b/apps/workbench/app/assets/javascripts/pipeline_instances.js @@ -108,7 +108,7 @@ $(document).on('arv-log-event', '.arv-log-event-handler-append-logs', function(e } var wasatbottom = ($(this).scrollTop() + $(this).height() >= this.scrollHeight); - if (eventData.event_type == "stderr" || eventData.event_type == "stdout") { + if (eventData.properties != null && eventData.properties.text != null) { if( eventData.prepend ) { $(this).prepend(eventData.properties.text); } else { diff --git a/apps/workbench/app/models/container_work_unit.rb b/apps/workbench/app/models/container_work_unit.rb index 037a6e53ee..f9159231a0 100644 --- a/apps/workbench/app/models/container_work_unit.rb +++ b/apps/workbench/app/models/container_work_unit.rb @@ -124,6 +124,20 @@ 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 + collection = Collection.find(log_collection) rescue nil + if collection + return {log: collection, partial: 'collections/show_files', locals: {object: collection, no_checkboxes: true}} + end + end + # End combined propeties protected diff --git a/apps/workbench/app/models/work_unit.rb b/apps/workbench/app/models/work_unit.rb index 1c2d02fa96..dee6a609c8 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 + # 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 e3c79f143b..a21a514c47 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 %> +
<% if Collection.creatable? and (!defined? no_checkboxes or !no_checkboxes) %>
@@ -19,7 +21,7 @@
  • <%= 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 @@

    <% end %> - <% file_tree = @object.andand.files_tree %> + <% file_tree = object.andand.files_tree %> <% if file_tree.nil? or file_tree.empty? %>

    This collection is empty.

    <% else %> @@ -59,8 +61,8 @@
      <% else %> <% link_params = {controller: 'collections', action: 'show_file', - uuid: @object.portable_data_hash, file: file_path, size: size} %> -
      + uuid: object.portable_data_hash, file: file_path, size: size} %> +
      <%= raw(human_readable_bytes_html(size)) %> <%= link_to(raw(''), @@ -73,27 +75,27 @@
      <% 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}", } %>   <% end %> <% if CollectionsHelper::is_image(filename) %> <%= filename %>
      - <%= 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}) %>
      <% else %> - <%= filename %>
      + <%= filename %>
  • <% end %> 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 0000000000..4126f12a5d --- /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 0000000000..4126f12a5d --- /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 0000000000..566da5ba86 --- /dev/null +++ b/apps/workbench/app/views/work_unit/_show_log.html.erb @@ -0,0 +1,24 @@ +<% wu = obj.work_unit(name) %> + +<% render_log = wu.render_log %> +<% if render_log %> +
    + <% log_url = url_for render_log[:log] %> +

    Download the log

    + <%= render(partial: render_log[:partial], locals: render_log[:locals]) %> +
    +<% end %> + +<%# Show log in terminal window %> +

    Recent logs

    +
    <%= wu.live_log_lines(Rails.configuration.running_job_log_records_to_fetch).join("\n") %> +
    + +<%# Applying a long throttle suppresses the auto-refresh of this + partial that would normally be triggered by arv-log-event. %> +
    > +
    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 0000000000..c738343dcb --- /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_select "a", {:href=>"/collections/#{container['log']}", :text=>"Download the log"} + assert_select "a", {: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 0000000000..ce37239c00 --- /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_select "a", {:href=>"/collections/#{container['log']}", :text=>"Download the log"} + assert_select "a", {: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 655ad92c94..bc8b5cd0f7 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 1796e498f4..79e472b097 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"] -- 2.39.5