1 class PipelineInstancesController < ApplicationController
2 skip_before_filter :find_object_by_uuid, only: :compare
3 before_filter :find_objects_by_uuid, only: :compare
4 skip_around_filter :require_thread_api_token, if: proc { |ctrl|
5 Rails.configuration.anonymous_user_token and
6 'show' == ctrl.action_name
9 include PipelineInstancesHelper
10 include PipelineComponentsHelper
13 template = PipelineTemplate.find?(@object.pipeline_template_uuid)
16 @object = PipelineInstance.new
17 @object.pipeline_template_uuid = source.pipeline_template_uuid
19 if params['components'] == 'use_latest' and template
20 @object.components = template.components.deep_dup
21 @object.components.each do |cname, component|
22 # Go through the script parameters of each component
23 # that are marked as user input and copy them over.
24 # Skip any components that are not present in the
25 # source instance (there's nothing to copy)
26 if source.components.include? cname
27 component[:script_parameters].each do |pname, val|
28 if val.is_a? Hash and val[:dataclass]
29 # this is user-inputtable, so check the value from the source pipeline
30 srcvalue = source.components[cname][:script_parameters][pname]
32 component[:script_parameters][pname] = srcvalue
39 @object.components = source.components.deep_dup
42 if params['script'] == 'use_same'
43 # Go through each component and copy the script_version from each job.
44 @object.components.each do |cname, component|
45 if source.components.include? cname and source.components[cname][:job]
46 component[:script_version] = source.components[cname][:job][:script_version]
51 @object.components.each do |cname, component|
56 # set owner_uuid to that of source, provided it is a project and wriable by current user
57 current_project = Group.find(source.owner_uuid) rescue nil
58 if (current_project && current_project.writable_by.andand.include?(current_user.uuid))
59 @object.owner_uuid = source.owner_uuid
66 @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
67 if (components = @updates[:components])
68 components.each do |cname, component|
69 if component[:script_parameters]
70 component[:script_parameters].each do |param, value_info|
71 if value_info.is_a? Hash
72 value_info_partitioned = value_info[:value].partition('/') if value_info[:value].andand.class.eql?(String)
73 value_info_value = value_info_partitioned ? value_info_partitioned[0] : value_info[:value]
74 value_info_class = resource_class_for_uuid value_info_value
75 if value_info_class == Link
76 # Use the link target, not the link itself, as script
77 # parameter; but keep the link info around as well.
78 link = Link.find value_info[:value]
79 value_info[:value] = link.head_uuid
80 value_info[:link_uuid] = link.uuid
81 value_info[:link_name] = link.name
83 # Delete stale link_uuid and link_name data.
84 value_info[:link_uuid] = nil
85 value_info[:link_name] = nil
87 if value_info_class == Collection
88 # to ensure reproducibility, the script_parameter for a
89 # collection should be the portable_data_hash
90 # keep the collection name and uuid for human-readability
91 obj = Collection.find value_info_value
92 if value_info_partitioned
93 value_info[:value] = obj.portable_data_hash + value_info_partitioned[1] + value_info_partitioned[2]
94 value_info[:selection_name] = obj.name ? obj.name + value_info_partitioned[1] + value_info_partitioned[2] : obj.name
96 value_info[:value] = obj.portable_data_hash
97 value_info[:selection_name] = obj.name
99 value_info[:selection_uuid] = obj.uuid
110 return nil, nil if params['tab_pane'] != "Graph"
116 # When comparing more than one pipeline, "pips" stores bit fields that
117 # indicates which objects are part of which pipelines.
119 pipelines.each do |p|
124 p[:components].each do |k, v|
125 provenance["component_#{p[:uuid]}_#{k}"] = v
127 collections << v[:output_uuid] if v[:output_uuid]
128 jobs << v[:job][:uuid] if v[:job]
131 jobs = jobs.compact.uniq
133 Job.where(uuid: jobs).each do |j|
136 provenance[job_uuid] = j
137 pips[job_uuid] = 0 unless pips[job_uuid] != nil
140 hashes << j[:output] if j[:output]
141 ProvenanceHelper::find_collections(j) do |hash, uuid|
142 collections << uuid if uuid
143 hashes << hash if hash
146 if j[:script_version]
147 script_uuid = j[:script_version]
148 provenance[script_uuid] = {:uuid => script_uuid}
149 pips[script_uuid] = 0 unless pips[script_uuid] != nil
150 pips[script_uuid] |= n
155 hashes = hashes.compact.uniq
157 Collection.where(portable_data_hash: hashes).each do |c|
158 hash_uuid = c.portable_data_hash
159 provenance[hash_uuid] = c
160 pips[hash_uuid] = 0 unless pips[hash_uuid] != nil
165 collections = collections.compact.uniq
167 Collection.where(uuid: collections).each do |c|
168 collection_uuid = c.uuid
169 provenance[collection_uuid] = c
170 pips[collection_uuid] = 0 unless pips[collection_uuid] != nil
171 pips[collection_uuid] |= n
178 return provenance, pips
182 # the #show action can also be called by #compare, which does its own work to set up @pipelines
183 unless defined? @pipelines
184 @pipelines = [@object]
187 provenance, pips = graph(@pipelines)
189 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
191 :all_script_parameters => true,
192 :combine_jobs => :script_and_version,
194 :only_components => true,
203 @breadcrumb_page_name = 'compare'
205 @rows = [] # each is {name: S, components: [...]}
207 if params['tab_pane'] == "Compare" or params['tab_pane'].nil?
208 # Build a table: x=pipeline y=component
209 @objects.each_with_index do |pi, pi_index|
210 pipeline_jobs(pi).each do |component|
211 # Find a cell with the same name as this component but no
212 # entry for this pipeline
214 @rows.each_with_index do |row, row_index|
215 if row[:name] == component[:name] and !row[:components][pi_index]
220 target_row = {name: component[:name], components: []}
223 target_row[:components][pi_index] = component
228 # Build a "normal" pseudo-component for this row by picking the
229 # most common value for each attribute. If all values are
230 # equally common, there is no "normal".
231 normal = {} # attr => most common value
232 highscore = {} # attr => how common "normal" is
233 score = {} # attr => { value => how common }
234 row[:components].each do |pj|
237 vstr = for_comparison v
239 score[k][vstr] = (score[k][vstr] || 0) + 1
241 if score[k][vstr] == highscore[k]
242 # tie for first place = no "normal"
244 elsif score[k][vstr] == highscore[k] + 1
245 # more pipelines have v than anything else
246 highscore[k] = score[k][vstr]
252 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
253 row[:components].each do |pj|
257 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
263 if params['tab_pane'] == "Graph"
264 @pipelines = @objects
267 @object = @objects.first
273 panes = %w(Components Log Graph Advanced)
274 if @object and @object.state.in? ['New', 'Ready']
275 panes = %w(Inputs) + panes - %w(Log)
277 if not @object.components.values.any? { |x| x[:job] rescue false }
283 def compare_pane_list
287 helper_method :unreadable_inputs_present?
288 def unreadable_inputs_present?
289 unless @unreadable_inputs_present.nil?
290 return @unreadable_inputs_present
295 @object.components.each do |k, component|
297 component[:script_parameters].andand.each do |p, tv|
298 if (tv.is_a? Hash) and ((tv[:dataclass] == "Collection") || (tv[:dataclass] == "File"))
307 split = value.split '/'
308 if CollectionsHelper.match(split[0])
309 input_pdhs << split[0]
311 input_uuids << split[0]
318 input_pdhs = input_pdhs.uniq
319 input_uuids = input_uuids.uniq
321 preload_collections_for_objects input_uuids if input_uuids.any?
322 preload_for_pdhs input_pdhs if input_pdhs.any?
324 @unreadable_inputs_present = false
325 input_uuids.each do |uuid|
326 if !collections_for_object(uuid).any?
327 @unreadable_inputs_present = true
331 if !@unreadable_inputs_present
332 input_pdhs.each do |pdh|
333 if !collection_for_pdh(pdh).any?
334 @unreadable_inputs_present = true
340 @unreadable_inputs_present
345 if v.is_a? Hash or v.is_a? Array
352 def load_filters_and_paging_params
357 def find_objects_by_uuid
358 @objects = model_class.where(uuid: params[:uuids])