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
8 template = PipelineTemplate.find?(@object.pipeline_template_uuid)
11 @object = PipelineInstance.new
12 @object.pipeline_template_uuid = source.pipeline_template_uuid
14 if params['components'] == 'use_latest' and template
15 @object.components = template.components.deep_dup
16 @object.components.each do |cname, component|
17 # Go through the script parameters of each component
18 # that are marked as user input and copy them over.
19 component[:script_parameters].each do |pname, val|
20 if val.is_a? Hash and val[:dataclass]
21 # this is user-inputtable, so check the value from the source pipeline
22 srcvalue = source.components[cname][:script_parameters][pname]
24 component[:script_parameters][pname] = srcvalue
30 @object.components = source.components.deep_dup
33 if params['script'] == 'use_same'
34 # Go through each component and copy the script_version from each job.
35 @object.components.each do |cname, component|
36 if source.components[cname][:job]
37 component[:script_version] = source.components[cname][:job][:script_version]
42 @object.components.each do |cname, component|
50 @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
51 if (components = @updates[:components])
52 components.each do |cname, component|
53 if component[:script_parameters]
54 component[:script_parameters].each do |param, value_info|
55 if value_info.is_a? Hash
56 if resource_class_for_uuid(value_info[:value]) == Link
57 # Use the link target, not the link itself, as script
58 # parameter; but keep the link info around as well.
59 link = Link.find value_info[:value]
60 value_info[:value] = link.head_uuid
61 value_info[:link_uuid] = link.uuid
62 value_info[:link_name] = link.name
64 # Delete stale link_uuid and link_name data.
65 value_info[:link_uuid] = nil
66 value_info[:link_name] = nil
77 return nil, nil if params['tab_pane'] != "Graph"
87 p.components.each do |k, v|
90 uuid = j[:uuid].intern
92 pips[uuid] = 0 unless pips[uuid] != nil
95 collections << j[:output]
96 ProvenanceHelper::find_collections(j[:script_parameters]).each do |k|
100 uuid = j[:script_version].intern
101 provenance[uuid] = {:uuid => uuid}
102 pips[uuid] = 0 unless pips[uuid] != nil
106 Collection.where(uuid: collections.compact).each do |c|
109 pips[uuid] = 0 unless pips[uuid] != nil
116 return provenance, pips
120 @pipelines = [@object]
123 PipelineInstance.where(uuid: params[:compare]).each do |p|
128 provenance, pips = graph(@pipelines)
130 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
132 :all_script_parameters => true,
133 :combine_jobs => :script_and_version,
134 :script_version_nodes => true,
142 @breadcrumb_page_name = 'compare'
144 @rows = [] # each is {name: S, components: [...]}
146 if params['tab_pane'] == "Compare" or params['tab_pane'].nil?
147 # Build a table: x=pipeline y=component
148 @objects.each_with_index do |pi, pi_index|
149 pipeline_jobs(pi).each do |component|
150 # Find a cell with the same name as this component but no
151 # entry for this pipeline
153 @rows.each_with_index do |row, row_index|
154 if row[:name] == component[:name] and !row[:components][pi_index]
159 target_row = {name: component[:name], components: []}
162 target_row[:components][pi_index] = component
167 # Build a "normal" pseudo-component for this row by picking the
168 # most common value for each attribute. If all values are
169 # equally common, there is no "normal".
170 normal = {} # attr => most common value
171 highscore = {} # attr => how common "normal" is
172 score = {} # attr => { value => how common }
173 row[:components].each do |pj|
176 vstr = for_comparison v
178 score[k][vstr] = (score[k][vstr] || 0) + 1
180 if score[k][vstr] == highscore[k]
181 # tie for first place = no "normal"
183 elsif score[k][vstr] == highscore[k] + 1
184 # more pipelines have v than anything else
185 highscore[k] = score[k][vstr]
191 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
192 row[:components].each do |pj|
196 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
202 if params['tab_pane'] == "Graph"
203 provenance, pips = graph(@objects)
205 @pipelines = @objects
208 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
210 :all_script_parameters => true,
211 :combine_jobs => :script_and_version,
212 :script_version_nodes => true,
217 @object = @objects.first
223 panes = %w(Components Log Graph Advanced)
224 if @object and @object.state.in? ['New', 'Ready']
225 panes = %w(Inputs) + panes - %w(Log)
227 if not @object.components.values.any? { |x| x[:job] rescue false }
233 def compare_pane_list
244 if v.is_a? Hash or v.is_a? Array
251 def find_objects_by_uuid
252 @objects = model_class.where(uuid: params[:uuids])