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
43 return nil, nil if params['tab_pane'] != "Graph"
53 p.components.each do |k, v|
56 # The graph is interested in whether the component is
57 # indicated as persistent, more than whether the job
58 # satisfying it (which could have been reused, or someone
60 j[:output_is_persistent] = v[:output_is_persistent]
62 uuid = j[:uuid].intern
64 pips[uuid] = 0 unless pips[uuid] != nil
67 collections << j[:output]
68 ProvenanceHelper::find_collections(j[:script_parameters]).each do |k|
72 uuid = j[:script_version].intern
73 provenance[uuid] = {:uuid => uuid}
74 pips[uuid] = 0 unless pips[uuid] != nil
78 Collection.where(uuid: collections.compact).each do |c|
81 pips[uuid] = 0 unless pips[uuid] != nil
88 return provenance, pips
92 @pipelines = [@object]
95 PipelineInstance.where(uuid: params[:compare]).each do |p|
100 provenance, pips = graph(@pipelines)
102 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
104 :all_script_parameters => true,
105 :combine_jobs => :script_and_version,
106 :script_version_nodes => true,
114 @breadcrumb_page_name = 'compare'
116 @rows = [] # each is {name: S, components: [...]}
118 if params['tab_pane'] == "Compare" or params['tab_pane'].nil?
119 # Build a table: x=pipeline y=component
120 @objects.each_with_index do |pi, pi_index|
121 pipeline_jobs(pi).each do |component|
122 # Find a cell with the same name as this component but no
123 # entry for this pipeline
125 @rows.each_with_index do |row, row_index|
126 if row[:name] == component[:name] and !row[:components][pi_index]
131 target_row = {name: component[:name], components: []}
134 target_row[:components][pi_index] = component
139 # Build a "normal" pseudo-component for this row by picking the
140 # most common value for each attribute. If all values are
141 # equally common, there is no "normal".
142 normal = {} # attr => most common value
143 highscore = {} # attr => how common "normal" is
144 score = {} # attr => { value => how common }
145 row[:components].each do |pj|
148 vstr = for_comparison v
150 score[k][vstr] = (score[k][vstr] || 0) + 1
152 if score[k][vstr] == highscore[k]
153 # tie for first place = no "normal"
155 elsif score[k][vstr] == highscore[k] + 1
156 # more pipelines have v than anything else
157 highscore[k] = score[k][vstr]
163 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
164 row[:components].each do |pj|
168 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
174 if params['tab_pane'] == "Graph"
175 provenance, pips = graph(@objects)
177 @pipelines = @objects
180 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
182 :all_script_parameters => true,
183 :combine_jobs => :script_and_version,
184 :script_version_nodes => true,
189 @object = @objects.first
195 panes = %w(Components Graph Advanced)
196 if @object and @object.state.in? ['New', 'Ready']
197 panes = %w(Inputs) + panes
199 if not @object.components.values.collect { |x| x[:job] }.compact.any?
205 def compare_pane_list
216 if v.is_a? Hash or v.is_a? Array
223 def find_objects_by_uuid
224 @objects = model_class.where(uuid: params[:uuids])