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|
51 # set owner_uuid to that of source, provided it is a project and wriable by current user
52 current_project = Group.find(source.owner_uuid) rescue nil
53 if (current_project && current_project.writable_by.andand.include?(current_user.uuid))
54 @object.owner_uuid = source.owner_uuid
61 @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
62 if (components = @updates[:components])
63 components.each do |cname, component|
64 if component[:script_parameters]
65 component[:script_parameters].each do |param, value_info|
66 if value_info.is_a? Hash
67 if resource_class_for_uuid(value_info[:value]) == Link
68 # Use the link target, not the link itself, as script
69 # parameter; but keep the link info around as well.
70 link = Link.find value_info[:value]
71 value_info[:value] = link.head_uuid
72 value_info[:link_uuid] = link.uuid
73 value_info[:link_name] = link.name
75 # Delete stale link_uuid and link_name data.
76 value_info[:link_uuid] = nil
77 value_info[:link_name] = nil
88 return nil, nil if params['tab_pane'] != "Graph"
94 # When comparing more than one pipeline, "pips" stores bit fields that
95 # indicates which objects are part of which pipelines.
102 p[:components].each do |k, v|
103 provenance["component_#{p[:uuid]}_#{k}"] = v
105 collections << v[:output_uuid] if v[:output_uuid]
106 jobs << v[:job][:uuid] if v[:job]
109 jobs = jobs.compact.uniq
111 Job.where(uuid: jobs).each do |j|
114 provenance[job_uuid] = j
115 pips[job_uuid] = 0 unless pips[job_uuid] != nil
118 hashes << j[:output] if j[:output]
119 ProvenanceHelper::find_collections(j) do |hash, uuid|
120 collections << uuid if uuid
121 hashes << hash if hash
124 if j[:script_version]
125 script_uuid = j[:script_version]
126 provenance[script_uuid] = {:uuid => script_uuid}
127 pips[script_uuid] = 0 unless pips[script_uuid] != nil
128 pips[script_uuid] |= n
133 hashes = hashes.compact.uniq
135 Collection.where(portable_data_hash: hashes).each do |c|
136 hash_uuid = c.portable_data_hash
137 provenance[hash_uuid] = c
138 pips[hash_uuid] = 0 unless pips[hash_uuid] != nil
143 collections = collections.compact.uniq
145 Collection.where(uuid: collections).each do |c|
146 collection_uuid = c.uuid
147 provenance[collection_uuid] = c
148 pips[collection_uuid] = 0 unless pips[collection_uuid] != nil
149 pips[collection_uuid] |= n
156 return provenance, pips
160 @pipelines = [@object]
163 PipelineInstance.where(uuid: params[:compare]).each do |p|
168 provenance, pips = graph(@pipelines)
170 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
172 :all_script_parameters => true,
173 :combine_jobs => :script_and_version,
175 :only_components => true,
184 @breadcrumb_page_name = 'compare'
186 @rows = [] # each is {name: S, components: [...]}
188 if params['tab_pane'] == "Compare" or params['tab_pane'].nil?
189 # Build a table: x=pipeline y=component
190 @objects.each_with_index do |pi, pi_index|
191 pipeline_jobs(pi).each do |component|
192 # Find a cell with the same name as this component but no
193 # entry for this pipeline
195 @rows.each_with_index do |row, row_index|
196 if row[:name] == component[:name] and !row[:components][pi_index]
201 target_row = {name: component[:name], components: []}
204 target_row[:components][pi_index] = component
209 # Build a "normal" pseudo-component for this row by picking the
210 # most common value for each attribute. If all values are
211 # equally common, there is no "normal".
212 normal = {} # attr => most common value
213 highscore = {} # attr => how common "normal" is
214 score = {} # attr => { value => how common }
215 row[:components].each do |pj|
218 vstr = for_comparison v
220 score[k][vstr] = (score[k][vstr] || 0) + 1
222 if score[k][vstr] == highscore[k]
223 # tie for first place = no "normal"
225 elsif score[k][vstr] == highscore[k] + 1
226 # more pipelines have v than anything else
227 highscore[k] = score[k][vstr]
233 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
234 row[:components].each do |pj|
238 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
244 if params['tab_pane'] == "Graph"
245 provenance, pips = graph(@objects)
247 @pipelines = @objects
250 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
252 :all_script_parameters => true,
253 :combine_jobs => :script_and_version,
254 :script_version_nodes => true,
259 @object = @objects.first
265 panes = %w(Components Log Graph Advanced)
266 if @object and @object.state.in? ['New', 'Ready']
267 panes = %w(Inputs) + panes - %w(Log)
269 if not @object.components.values.any? { |x| x[:job] rescue false }
275 def compare_pane_list
286 if v.is_a? Hash or v.is_a? Array
293 def find_objects_by_uuid
294 @objects = model_class.where(uuid: params[:uuids])