Merge branch '8784-dir-listings'
[arvados.git] / apps / workbench / app / controllers / jobs_controller.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class JobsController < ApplicationController
6   skip_around_filter :require_thread_api_token, if: proc { |ctrl|
7     Rails.configuration.anonymous_user_token and
8     'show' == ctrl.action_name
9   }
10
11   def generate_provenance(jobs)
12     return if params['tab_pane'] != "Provenance"
13
14     nodes = {}
15     collections = []
16     hashes = []
17     jobs.each do |j|
18       nodes[j[:uuid]] = j
19       hashes << j[:output]
20       ProvenanceHelper::find_collections(j[:script_parameters]) do |hash, uuid|
21         collections << uuid if uuid
22         hashes << hash if hash
23       end
24       nodes[j[:script_version]] = {:uuid => j[:script_version]}
25     end
26
27     Collection.where(uuid: collections).each do |c|
28       nodes[c[:portable_data_hash]] = c
29     end
30
31     Collection.where(portable_data_hash: hashes).each do |c|
32       nodes[c[:portable_data_hash]] = c
33     end
34
35     @svg = ProvenanceHelper::create_provenance_graph nodes, "provenance_svg", {
36       :request => request,
37       :direction => :top_down,
38       :all_script_parameters => true,
39       :script_version_nodes => true}
40   end
41
42   def index
43     @svg = ""
44     if params[:uuid]
45       @objects = Job.where(uuid: params[:uuid])
46       generate_provenance(@objects)
47       render_index
48     else
49       @limit = 20
50       super
51     end
52   end
53
54   def cancel
55     @object.cancel
56     if params[:return_to]
57       redirect_to params[:return_to]
58     else
59       redirect_to @object
60     end
61   end
62
63   def show
64     generate_provenance([@object])
65     super
66   end
67
68   def logs
69     @logs = @object.
70       stderr_log_query(Rails.configuration.running_job_log_records_to_fetch).
71       map { |e| e.serializable_hash.merge({ 'prepend' => true }) }
72     respond_to do |format|
73       format.json { render json: @logs }
74     end
75   end
76
77   def index_pane_list
78     if params[:uuid]
79       %w(Recent Provenance)
80     else
81       %w(Recent)
82     end
83   end
84
85   def show_pane_list
86     %w(Status Log Details Provenance Advanced)
87   end
88 end