1 class PipelineInstancesController < ApplicationController
2 skip_before_filter :find_object_by_uuid, only: :compare
3 before_filter :find_objects_by_uuid, only: :compare
4 include PipelineInstancesHelper
8 @object.components.each do |cname, component|
16 @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
17 if (components = @updates[:components])
18 components.each do |cname, component|
19 if component[:script_parameters]
20 component[:script_parameters].each do |param, value_info|
21 if value_info.is_a? Hash
22 if resource_class_for_uuid(value_info[:value]) == Link
23 # Use the link target, not the link itself, as script
24 # parameter; but keep the link info around as well.
25 link = Link.find value_info[:value]
26 value_info[:value] = link.head_uuid
27 value_info[:link_uuid] = link.uuid
28 value_info[:link_name] = link.name
30 # Delete stale link_uuid and link_name data.
31 value_info[:link_uuid] = nil
32 value_info[:link_name] = nil
51 p.components.each do |k, v|
54 # The graph is interested in whether the component is
55 # indicated as persistent, more than whether the job
56 # satisfying it (which could have been reused, or someone
58 j[:output_is_persistent] = v[:output_is_persistent]
60 uuid = j[:uuid].intern
62 pips[uuid] = 0 unless pips[uuid] != nil
65 collections << j[:output]
66 ProvenanceHelper::find_collections(j[:script_parameters]).each do |k|
70 uuid = j[:script_version].intern
71 provenance[uuid] = {:uuid => uuid}
72 pips[uuid] = 0 unless pips[uuid] != nil
76 Collection.where(uuid: collections.compact).each do |c|
79 pips[uuid] = 0 unless pips[uuid] != nil
86 return provenance, pips
90 @pipelines = [@object]
93 PipelineInstance.where(uuid: params[:compare]).each do |p|
98 provenance, pips = graph(@pipelines)
100 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
102 :all_script_parameters => true,
103 :combine_jobs => :script_and_version,
104 :script_version_nodes => true,
110 @breadcrumb_page_name = 'compare'
112 @rows = [] # each is {name: S, components: [...]}
114 # Build a table: x=pipeline y=component
115 @objects.each_with_index do |pi, pi_index|
116 pipeline_jobs(pi).each do |component|
117 # Find a cell with the same name as this component but no
118 # entry for this pipeline
120 @rows.each_with_index do |row, row_index|
121 if row[:name] == component[:name] and !row[:components][pi_index]
126 target_row = {name: component[:name], components: []}
129 target_row[:components][pi_index] = component
134 # Build a "normal" pseudo-component for this row by picking the
135 # most common value for each attribute. If all values are
136 # equally common, there is no "normal".
137 normal = {} # attr => most common value
138 highscore = {} # attr => how common "normal" is
139 score = {} # attr => { value => how common }
140 row[:components].each do |pj|
143 vstr = for_comparison v
145 score[k][vstr] = (score[k][vstr] || 0) + 1
147 if score[k][vstr] == highscore[k]
148 # tie for first place = no "normal"
150 elsif score[k][vstr] == highscore[k] + 1
151 # more pipelines have v than anything else
152 highscore[k] = score[k][vstr]
158 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
159 row[:components].each do |pj|
163 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
168 provenance, pips = graph(@objects)
170 @pipelines = @objects
172 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
174 :all_script_parameters => true,
175 :combine_jobs => :script_and_version,
176 :script_version_nodes => true,
178 @object = @objects.first
182 panes = %w(Components Graph Advanced)
183 if @object and @object.state.in? ['New', 'Ready']
184 panes = %w(Inputs) + panes
186 if not @object.components.values.collect { |x| x['job'] }.compact.any?
192 def compare_pane_list
203 if v.is_a? Hash or v.is_a? Array
210 def find_objects_by_uuid
211 @objects = model_class.where(uuid: params[:uuids])