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