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
5 include PipelineComponentsHelper
9 @object.components.each do |cname, component|
17 @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
18 if (components = @updates[:components])
19 components.each do |cname, component|
20 if component[:script_parameters]
21 component[:script_parameters].each do |param, value_info|
22 if value_info.is_a? Hash
23 if resource_class_for_uuid(value_info[:value]) == Link
24 # Use the link target, not the link itself, as script
25 # parameter; but keep the link info around as well.
26 link = Link.find value_info[:value]
27 value_info[:value] = link.head_uuid
28 value_info[:link_uuid] = link.uuid
29 value_info[:link_name] = link.name
31 # Delete stale link_uuid and link_name data.
32 value_info[:link_uuid] = nil
33 value_info[:link_name] = nil
44 return nil, nil if params['tab_pane'] != "Graph"
54 p.components.each do |k, v|
57 uuid = j[:uuid].intern
59 pips[uuid] = 0 unless pips[uuid] != nil
62 collections << j[:output]
63 ProvenanceHelper::find_collections(j[:script_parameters]).each do |k|
67 uuid = j[:script_version].intern
68 provenance[uuid] = {:uuid => uuid}
69 pips[uuid] = 0 unless pips[uuid] != nil
73 Collection.where(uuid: collections.compact).each do |c|
76 pips[uuid] = 0 unless pips[uuid] != nil
83 return provenance, pips
87 @pipelines = [@object]
90 PipelineInstance.where(uuid: params[:compare]).each do |p|
95 provenance, pips = graph(@pipelines)
97 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
99 :all_script_parameters => true,
100 :combine_jobs => :script_and_version,
101 :script_version_nodes => true,
109 @breadcrumb_page_name = 'compare'
111 @rows = [] # each is {name: S, components: [...]}
113 if params['tab_pane'] == "Compare" or params['tab_pane'].nil?
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))
169 if params['tab_pane'] == "Graph"
170 provenance, pips = graph(@objects)
172 @pipelines = @objects
175 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
177 :all_script_parameters => true,
178 :combine_jobs => :script_and_version,
179 :script_version_nodes => true,
184 @object = @objects.first
190 panes = %w(Components Log Graph Advanced)
191 if @object and @object.state.in? ['New', 'Ready']
192 panes = %w(Inputs) + panes - %w(Log)
194 if not @object.components.values.any? { |x| x[:job] rescue false }
200 def compare_pane_list
211 if v.is_a? Hash or v.is_a? Array
218 def find_objects_by_uuid
219 @objects = model_class.where(uuid: params[:uuids])