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 # Skip any components that are not present in the
20 # source instance (there's nothing to copy)
21 if source.components.include? cname
22 component[:script_parameters].each do |pname, val|
23 if val.is_a? Hash and val[:dataclass]
24 # this is user-inputtable, so check the value from the source pipeline
25 srcvalue = source.components[cname][:script_parameters][pname]
27 component[:script_parameters][pname] = srcvalue
34 @object.components = source.components.deep_dup
37 if params['script'] == 'use_same'
38 # Go through each component and copy the script_version from each job.
39 @object.components.each do |cname, component|
40 if source.components.include? cname and source.components[cname][:job]
41 component[:script_version] = source.components[cname][:job][:script_version]
46 @object.components.each do |cname, component|
54 @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
55 if (components = @updates[:components])
56 components.each do |cname, component|
57 if component[:script_parameters]
58 component[:script_parameters].each do |param, value_info|
59 if value_info.is_a? Hash
60 if resource_class_for_uuid(value_info[:value]) == Link
61 # Use the link target, not the link itself, as script
62 # parameter; but keep the link info around as well.
63 link = Link.find value_info[:value]
64 value_info[:value] = link.head_uuid
65 value_info[:link_uuid] = link.uuid
66 value_info[:link_name] = link.name
68 # Delete stale link_uuid and link_name data.
69 value_info[:link_uuid] = nil
70 value_info[:link_name] = nil
81 return nil, nil if params['tab_pane'] != "Graph"
91 p.components.each do |k, v|
94 uuid = j[:uuid].intern
96 pips[uuid] = 0 unless pips[uuid] != nil
99 collections << j[:output]
100 ProvenanceHelper::find_collections(j[:script_parameters]).each do |k|
104 uuid = j[:script_version].intern
105 provenance[uuid] = {:uuid => uuid}
106 pips[uuid] = 0 unless pips[uuid] != nil
110 Collection.where(uuid: collections.compact).each do |c|
113 pips[uuid] = 0 unless pips[uuid] != nil
120 return provenance, pips
124 @pipelines = [@object]
127 PipelineInstance.where(uuid: params[:compare]).each do |p|
132 provenance, pips = graph(@pipelines)
134 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
136 :all_script_parameters => true,
137 :combine_jobs => :script_and_version,
138 :script_version_nodes => true,
146 @breadcrumb_page_name = 'compare'
148 @rows = [] # each is {name: S, components: [...]}
150 if params['tab_pane'] == "Compare" or params['tab_pane'].nil?
151 # Build a table: x=pipeline y=component
152 @objects.each_with_index do |pi, pi_index|
153 pipeline_jobs(pi).each do |component|
154 # Find a cell with the same name as this component but no
155 # entry for this pipeline
157 @rows.each_with_index do |row, row_index|
158 if row[:name] == component[:name] and !row[:components][pi_index]
163 target_row = {name: component[:name], components: []}
166 target_row[:components][pi_index] = component
171 # Build a "normal" pseudo-component for this row by picking the
172 # most common value for each attribute. If all values are
173 # equally common, there is no "normal".
174 normal = {} # attr => most common value
175 highscore = {} # attr => how common "normal" is
176 score = {} # attr => { value => how common }
177 row[:components].each do |pj|
180 vstr = for_comparison v
182 score[k][vstr] = (score[k][vstr] || 0) + 1
184 if score[k][vstr] == highscore[k]
185 # tie for first place = no "normal"
187 elsif score[k][vstr] == highscore[k] + 1
188 # more pipelines have v than anything else
189 highscore[k] = score[k][vstr]
195 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
196 row[:components].each do |pj|
200 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
206 if params['tab_pane'] == "Graph"
207 provenance, pips = graph(@objects)
209 @pipelines = @objects
212 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
214 :all_script_parameters => true,
215 :combine_jobs => :script_and_version,
216 :script_version_nodes => true,
221 @object = @objects.first
227 panes = %w(Components Log Graph Advanced)
228 if @object and @object.state.in? ['New', 'Ready']
229 panes = %w(Inputs) + panes - %w(Log)
231 if not @object.components.values.any? { |x| x[:job] rescue false }
237 def compare_pane_list
248 if v.is_a? Hash or v.is_a? Array
255 def find_objects_by_uuid
256 @objects = model_class.where(uuid: params[:uuids])