@opts = opts
@visited = {}
@jobs = {}
+ @node_extra = {}
end
-
+
def self.collection_uuid(uuid)
m = CollectionsHelper.match(uuid)
if m
else
return m[1]
end
- # Collection.where(uuid: ['contains', m[1]]).each do |u|
- # puts "fixup #{uuid} to #{u.uuid}"
- # return u.uuid
- # end
- #end
else
nil
end
end
+ def url_for u
+ p = { :host => @opts[:request].host,
+ :port => @opts[:request].port,
+ :protocol => @opts[:request].protocol }
+ p.merge! u
+ Rails.application.routes.url_helpers.url_for (p)
+ end
+
def determine_fillcolor(n)
fillcolor = %w(aaaaaa aaffaa aaaaff aaaaaa ffaaaa)[n || 0] || 'aaaaaa'
"style=filled,fillcolor=\"##{fillcolor}\""
def describe_node(uuid)
uuid = uuid.to_sym
- bgcolor = determine_fillcolor @opts[:pips][uuid] if @opts[:pips]
+ bgcolor = determine_fillcolor @opts[:pips].andand[uuid]
rsc = ArvadosBase::resource_class_for_uuid uuid.to_s
if rsc
- href = Rails.application.routes.url_helpers.url_for ({:controller => rsc.to_s.tableize,
- :action => :show,
- :id => uuid.to_s,
- :host => @opts[:request].host,
- :port => @opts[:request].port})
-
+ href = url_for ({:controller => rsc.to_s.tableize,
+ :action => :show,
+ :id => uuid.to_s })
+
#"\"#{uuid}\" [label=\"#{rsc}\\n#{uuid}\",href=\"#{href}\"];\n"
if rsc == Collection
- #puts uuid
- if uuid == :"d41d8cd98f00b204e9800998ecf8427e+0"
+ if Collection.is_empty_blob_locator? uuid.to_s
# special case
- #puts "empty!"
return "\"#{uuid}\" [label=\"(empty collection)\"];\n"
end
- puts "#{uuid.class} #{@pdata[uuid]}"
- if @pdata[uuid]
- #puts @pdata[uuid]
+ if @pdata[uuid]
if @pdata[uuid][:name]
return "\"#{uuid}\" [label=\"#{@pdata[uuid][:name]}\",href=\"#{href}\",shape=oval,#{bgcolor}];\n"
- else
+ else
files = nil
if @pdata[uuid].respond_to? :files
files = @pdata[uuid].files
elsif @pdata[uuid][:files]
files = @pdata[uuid][:files]
end
-
+
if files
i = 0
label = ""
if i < files.length
label += "\\n⋮"
end
- #puts "#{uuid} #{label} #{files}"
- return "\"#{uuid}\" [label=\"#{label}\",href=\"#{href}\",shape=oval,#{bgcolor}];\n"
+ extra_s = @node_extra[uuid].andand.map { |k,v|
+ "#{k}=\"#{v}\""
+ }.andand.join ","
+ return "\"#{uuid}\" [label=\"#{label}\",href=\"#{href}\",shape=oval,#{bgcolor},#{extra_s}];\n"
end
- end
+ end
end
- return "\"#{uuid}\" [label=\"#{rsc}\",href=\"#{href}\",#{bgcolor}];\n"
end
+ return "\"#{uuid}\" [label=\"#{rsc}\",href=\"#{href}\",#{bgcolor}];\n"
end
"\"#{uuid}\" [#{bgcolor}];\n"
end
def job_uuid(job)
+ d = Digest::MD5.hexdigest(job[:script_parameters].to_json)
if @opts[:combine_jobs] == :script_only
- uuid = "#{job[:script]}"
+ uuid = "#{job[:script]}_#{d}"
elsif @opts[:combine_jobs] == :script_and_version
- uuid = "#{job[:script]}_#{job[:script_version]}"
+ uuid = "#{job[:script]}_#{job[:script_version]}_#{d}"
else
uuid = "#{job[:uuid]}"
end
when Array
i = 0
node = ""
+ count = 0
sp.each do |v|
if GenerateGraph::collection_uuid(v)
gr += script_param_edges(job, "#{prefix}[#{i}]", v)
elsif @opts[:all_script_parameters]
- node += "', '" unless node == ""
+ t = "#{v}"
+ nl = (if (count+t.length) > 60 then "\\n" else " " end)
+ count = 0 if (count+t.length) > 60
+ node += "',#{nl}'" unless node == ""
node = "['" if node == ""
- node += "#{v}"
+ node += t
+ count += t.length
end
i += 1
end
unless node == ""
node += "']"
- #puts node
- #id = "#{job[:uuid]}_#{prefix}"
- gr += "\"#{node}\" [label=\"#{node}\"];\n"
- gr += edge(job_uuid(job), node, {:label => prefix})
+ node_value = encode_quotes node
+ gr += "\"#{node_value}\" [label=\"#{node_value}\"];\n"
+ gr += edge(job_uuid(job), node_value, {:label => prefix})
end
when String
return '' if sp.empty?
m = GenerateGraph::collection_uuid(sp)
- #puts "#{m} pdata is #{@pdata[m.intern]}"
if m and (@pdata[m.intern] or (not @opts[:pdata_only]))
gr += edge(job_uuid(job), m, {:label => prefix})
gr += generate_provenance_edges(m)
elsif @opts[:all_script_parameters]
- #id = "#{job[:uuid]}_#{prefix}"
- gr += "\"#{sp}\" [label=\"#{sp}\"];\n"
- gr += edge(job_uuid(job), sp, {:label => prefix})
+ sp_value = encode_quotes sp
+ gr += "\"#{sp_value}\" [label=\"#{sp_value}\"];\n"
+ gr += edge(job_uuid(job), sp_value, {:label => prefix})
end
end
gr
uuid = uuid.intern if uuid
if (not uuid) or uuid.empty? or @visited[uuid]
-
- #puts "already @visited #{uuid}"
return ""
end
- if not @pdata[uuid] then
+ if not @pdata[uuid] then
return describe_node(uuid)
else
@visited[uuid] = true
end
- #puts "visiting #{uuid}"
-
- if m
+ if m
# uuid is a collection
- gr += describe_node(uuid)
-
- if m == :"d41d8cd98f00b204e9800998ecf8427e+0"
- # empty collection, don't follow any further
- return gr
- end
-
- @pdata.each do |k, job|
- if job[:output] == uuid.to_s
- gr += edge(uuid, job_uuid(job), {:label => "output"})
- gr += generate_provenance_edges(job[:uuid])
- end
- if job[:log] == uuid.to_s
- gr += edge(uuid, job_uuid(job), {:label => "log"})
- gr += generate_provenance_edges(job[:uuid])
+ if not Collection.is_empty_blob_locator? uuid.to_s
+ @pdata.each do |k, job|
+ if job[:output] == uuid.to_s
+ extra = { label: 'output' }
+ gr += edge(uuid, job_uuid(job), extra)
+ gr += generate_provenance_edges(job[:uuid])
+ end
+ if job[:log] == uuid.to_s
+ gr += edge(uuid, job_uuid(job), {:label => "log"})
+ gr += generate_provenance_edges(job[:uuid])
+ end
end
end
+ gr += describe_node(uuid)
else
# uuid is something else
rsc = ArvadosBase::resource_class_for_uuid uuid.to_s
@pdata.each do |k, link|
if link[:head_uuid] == uuid.to_s and link[:link_class] == "provenance"
- href = Rails.application.routes.url_helpers.url_for ({:controller => Link.to_s.tableize,
- :action => :show,
- :id => link[:uuid],
- :host => @opts[:request].host,
- :port => @opts[:request].port})
+ href = url_for ({:controller => Link.to_s.tableize,
+ :action => :show,
+ :id => link[:uuid] })
gr += describe_node(link[:tail_uuid])
- gr += edge(link[:head_uuid], link[:tail_uuid], {:label => link[:name], :href => href})
+ gr += edge(link[:head_uuid], link[:tail_uuid], {:label => link[:name], :href => href})
gr += generate_provenance_edges(link[:tail_uuid])
end
end
- #puts "finished #{uuid}"
-
gr
end
def describe_jobs
gr = ""
@jobs.each do |k, v|
- href = Rails.application.routes.url_helpers.url_for ({:controller => Job.to_s.tableize,
- :action => :index,
- :host => @opts[:request].host,
- :port => @opts[:request].port})
+ href = url_for ({:controller => Job.to_s.tableize,
+ :action => :index })
gr += "\"#{k}\" [href=\"#{href}?"
-
+
n = 0
v.each do |u|
gr += "uuid%5b%5d=#{u[:uuid]}&"
end
gr += "\",label=\""
-
+
if @opts[:combine_jobs] == :script_only
gr += "#{v[0][:script]}"
elsif @opts[:combine_jobs] == :script_and_version
gr
end
+ def encode_quotes value
+ value.andand.gsub("\"", "\\\"")
+ end
end
def self.create_provenance_graph(pdata, svgId, opts={})
unless pdata.is_a? Hash
raise "create_provenance_graph accepts Array or Hash for pdata only, pdata is #{pdata.class}"
end
-
+
gr = """strict digraph {
node [fontsize=10,shape=box];
edge [fontsize=10];
gr += "edge [dir=back];"
end
- #puts "@pdata is #{pdata}"
-
g = GenerateGraph.new(pdata, opts)
pdata.each do |k, v|
gr += "}"
svg = ""
- puts gr
-
require 'open3'
Open3.popen2("dot", "-Tsvg") do |stdin, stdout, wait_thr|