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
7 @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
8 if (components = @updates[:components])
9 components.each do |cname, component|
10 if component[:script_parameters]
11 component[:script_parameters].each do |param, value_info|
12 if value_info.is_a? Hash
13 if resource_class_for_uuid(value_info[:value]) == Link
14 # Use the link target, not the link itself, as script
15 # parameter; but keep the link info around as well.
16 link = Link.find value_info[:value]
17 value_info[:value] = link.head_uuid
18 value_info[:link_uuid] = link.uuid
19 value_info[:link_name] = link.name
21 # Delete stale link_uuid and link_name data.
22 value_info[:link_uuid] = nil
23 value_info[:link_name] = nil
42 p.components.each do |k, v|
45 # The graph is interested in whether the component is
46 # indicated as persistent, more than whether the job
47 # satisfying it (which could have been reused, or someone
49 j[:output_is_persistent] = v[:output_is_persistent]
51 uuid = j[:uuid].intern
53 pips[uuid] = 0 unless pips[uuid] != nil
56 collections << j[:output]
57 ProvenanceHelper::find_collections(j[:script_parameters]).each do |k|
61 uuid = j[:script_version].intern
62 provenance[uuid] = {:uuid => uuid}
63 pips[uuid] = 0 unless pips[uuid] != nil
67 Collection.where(uuid: collections.compact).each do |c|
70 pips[uuid] = 0 unless pips[uuid] != nil
77 return provenance, pips
81 @pipelines = [@object]
84 PipelineInstance.where(uuid: params[:compare]).each do |p|
89 provenance, pips = graph(@pipelines)
91 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
93 :all_script_parameters => true,
94 :combine_jobs => :script_and_version,
95 :script_version_nodes => true,
101 @breadcrumb_page_name = 'compare'
103 @rows = [] # each is {name: S, components: [...]}
105 # Build a table: x=pipeline y=component
106 @objects.each_with_index do |pi, pi_index|
107 pipeline_jobs(pi).each do |component|
108 # Find a cell with the same name as this component but no
109 # entry for this pipeline
111 @rows.each_with_index do |row, row_index|
112 if row[:name] == component[:name] and !row[:components][pi_index]
117 target_row = {name: component[:name], components: []}
120 target_row[:components][pi_index] = component
125 # Build a "normal" pseudo-component for this row by picking the
126 # most common value for each attribute. If all values are
127 # equally common, there is no "normal".
128 normal = {} # attr => most common value
129 highscore = {} # attr => how common "normal" is
130 score = {} # attr => { value => how common }
131 row[:components].each do |pj|
134 vstr = for_comparison v
136 score[k][vstr] = (score[k][vstr] || 0) + 1
138 if score[k][vstr] == highscore[k]
139 # tie for first place = no "normal"
141 elsif score[k][vstr] == highscore[k] + 1
142 # more pipelines have v than anything else
143 highscore[k] = score[k][vstr]
149 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
150 row[:components].each do |pj|
154 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
159 provenance, pips = graph(@objects)
161 @pipelines = @objects
163 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
165 :all_script_parameters => true,
166 :combine_jobs => :script_and_version,
167 :script_version_nodes => true,
172 panes = %w(Components Graph Advanced)
173 if @object and @object.state.in? ['New', 'Ready']
174 panes = %w(Inputs) + panes
176 if not @object.components.values.collect { |x| x['job'] }.compact.any?
182 def compare_pane_list
193 if v.is_a? Hash or v.is_a? Array
200 def find_objects_by_uuid
201 @objects = model_class.where(uuid: params[:uuids])