+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
module ProvenanceHelper
class GenerateGraph
return "\"#{uuid}\" [label=\"(empty collection)\"];\n"
end
- href = url_for ({:controller => Collection.to_s.tableize,
- :action => :show,
- :id => uuid.to_s })
+ if describe_opts[:col_uuid]
+ href = url_for ({:controller => Collection.to_s.tableize,
+ :action => :show,
+ :id => describe_opts[:col_uuid].to_s })
+ else
+ href = url_for ({:controller => Collection.to_s.tableize,
+ :action => :show,
+ :id => uuid.to_s })
+ end
return "\"#{uuid}\" [label=\"#{encode_quotes(describe_opts[:label] || (@pdata[uuid] and @pdata[uuid][:name]) || uuid)}\",shape=box,href=\"#{href}\",#{bgcolor}];\n"
else
gr
end
- def cr_edges cr
- uuid = cr[:uuid]
- gr = ""
-
- ProvenanceHelper::find_collections cr[:mounts], 'mounts' do |col_hash, col_uuid, key|
- if col_uuid
- gr += describe_node(col_uuid)
- gr += edge(col_uuid, uuid, {:label => key})
- else
- gr += describe_node(col_hash)
- gr += edge(col_hash, uuid, {:label => key})
- end
- end
-
- [
- [true, :requesting_container_uuid, 'requesting_container'],
- [true, :container_image, 'container_image'],
- [false, :output_uuid, 'output'],
- [false, :log_uuid, 'log']
- ].each do |is_input, attr, label|
- if cr[attr]
- if attr == :container_image && cr[:container_uuid]
- # Extract the container_image's UUID from the CR's container
- cont = Container.find(cr[:container_uuid])
- gr += describe_node(cont[:container_image], {label: cr[attr]})
- # If container_image, then is_input is true
- edge_from = cont[:container_image]
- edge_to = uuid
- else
- # Default case
- gr += describe_node(cr[attr])
-
- if is_input
- edge_from = cr[attr]
- edge_to = uuid
- else
- edge_from = uuid
- edge_to = cr[attr]
- end
- end
- gr += edge(edge_from, edge_to, {label: label})
- end
- end
-
- gr
- end
-
def job_edges job, edge_opts={}
uuid = job_uuid(job)
gr = ""
gr += job_edges job if job
elsif rsc == ContainerRequest
cr = @pdata[uuid]
- gr += cr_edges cr if cr
- gr += describe_node(uuid, {href: {controller: 'container_requests',
- id: uuid},
- label: @pdata[uuid][:name],
- shape: 'oval'})
+ if cr
+ gr += describe_node(cr[:uuid], {href: {controller: 'container_requests',
+ id: cr[:uuid]},
+ label: cr[:name],
+ shape: 'oval'})
+ # Connect child CRs
+ children = @opts[:cr_children_of].andand[cr[:uuid]]
+ if children
+ children.each do |child|
+ gr += edge(child[:uuid], cr[:uuid], {label: 'child'})
+ end
+ end
+ # Output collection node
+ if cr[:output_uuid] and @opts[:output_collections][cr[:output_uuid]]
+ c = @opts[:output_collections][cr[:output_uuid]]
+ gr += describe_node(c[:portable_data_hash],
+ {
+ label: c[:name],
+ col_uuid: c[:uuid],
+ })
+ gr += edge(cr[:uuid],
+ c[:portable_data_hash],
+ {label: 'output'})
+ end
+ # Input collection nodes
+ output_pdhs = @opts[:output_collections].values.collect{|c|
+ c[:portable_data_hash]}
+ ProvenanceHelper::cr_input_pdhs(cr).each do |pdh|
+ if not output_pdhs.include?(pdh)
+ # Search for collections on the same project first
+ cols = @opts[:input_collections][pdh].andand.select{|c|
+ c[:owner_uuid] == cr[:owner_uuid]}
+ if not cols or cols.empty?
+ # Search for any collection with this PDH
+ cols = @opts[:input_collections][pdh]
+ end
+ if cols
+ names = cols.collect{|x| x[:name]}.uniq
+ else
+ names = ['(collection not found)']
+ end
+ input_name = names.first
+ if names.length > 1
+ input_name += " + #{names.length - 1} more"
+ end
+ gr += describe_node(pdh, {label: input_name})
+ end
+ gr += edge(pdh, cr[:uuid], {label: 'input'})
+ end
+ end
end
end
end
end
end
+
+ def self.cr_input_pdhs cr
+ pdhs = []
+ input_obj = cr[:mounts].andand[:"/var/lib/cwl/cwl.input.json"].andand[:content] || cr[:mounts]
+ if input_obj
+ find_collections input_obj do |col_hash, col_uuid, key|
+ if col_hash
+ pdhs << col_hash
+ end
+ end
+ end
+ pdhs
+ end
end