[ARVADOS] updated: b29ca38e4409fe0149aea28a0e26a84d56ccca17

Git user git at public.curoverse.com
Mon May 8 10:53:41 EDT 2017


Summary of changes:
 .../controllers/container_requests_controller.rb   |   8 +-
 apps/workbench/app/helpers/provenance_helper.rb    | 150 +++++++++++++--------
 2 files changed, 97 insertions(+), 61 deletions(-)

       via  b29ca38e4409fe0149aea28a0e26a84d56ccca17 (commit)
       via  b20770d7e5a4ba0a974a7b98fce87b81aead95d9 (commit)
      from  4259263d270a5e377009d20835a463551c708d82 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit b29ca38e4409fe0149aea28a0e26a84d56ccca17
Author: Lucas Di Pentima <lucas at curoverse.com>
Date:   Mon May 8 11:52:55 2017 -0300

    10111: When dealing with output collection nodes, render the specific collection url instead of use its pdh

diff --git a/apps/workbench/app/helpers/provenance_helper.rb b/apps/workbench/app/helpers/provenance_helper.rb
index d65bc2b..3567cba 100644
--- a/apps/workbench/app/helpers/provenance_helper.rb
+++ b/apps/workbench/app/helpers/provenance_helper.rb
@@ -37,9 +37,15 @@ module ProvenanceHelper
           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
@@ -250,8 +256,14 @@ module ProvenanceHelper
               if cr_node[:output_uuid] and output_cols[cr_node[:output_uuid]]
                 c = output_cols[cr_node[:output_uuid]]
                 visited_pdhs << c[:portable_data_hash]
-                gr += describe_node(c[:portable_data_hash], {label: c[:name]})
-                gr += edge(cr_node[:uuid], c[:portable_data_hash], {label: 'output'})
+                gr += describe_node(c[:portable_data_hash],
+                                    {
+                                      label: c[:name],
+                                      col_uuid: c[:uuid],
+                                    })
+                gr += edge(cr_node[:uuid],
+                           c[:portable_data_hash],
+                           {label: 'output'})
               end
             end
 

commit b20770d7e5a4ba0a974a7b98fce87b81aead95d9
Author: Lucas Di Pentima <lucas at curoverse.com>
Date:   Mon May 8 11:31:06 2017 -0300

    10111: Refactored the graph creation code to minimize the amount of API calls neeeded.

diff --git a/apps/workbench/app/controllers/container_requests_controller.rb b/apps/workbench/app/controllers/container_requests_controller.rb
index fd29cd3..d45e572 100644
--- a/apps/workbench/app/controllers/container_requests_controller.rb
+++ b/apps/workbench/app/controllers/container_requests_controller.rb
@@ -7,13 +7,7 @@ class ContainerRequestsController < ApplicationController
   def generate_provenance(cr)
     return if params['tab_pane'] != "Provenance"
 
-    nodes = {}
-    nodes[cr[:uuid]] = cr
-    if cr[:container_uuid]
-      ContainerRequest.where(requesting_container_uuid: cr[:container_uuid]).each do |child|
-        nodes[child[:uuid]] = child
-      end
-    end
+    nodes = {cr[:uuid] => cr}
     @svg = ProvenanceHelper::create_provenance_graph nodes,
                                                      "provenance_svg",
                                                      {
diff --git a/apps/workbench/app/helpers/provenance_helper.rb b/apps/workbench/app/helpers/provenance_helper.rb
index 3833243..d65bc2b 100644
--- a/apps/workbench/app/helpers/provenance_helper.rb
+++ b/apps/workbench/app/helpers/provenance_helper.rb
@@ -104,55 +104,17 @@ module ProvenanceHelper
       gr
     end
 
-    def col_name_for_project(col_pdh, project_uuid)
-      [
-        # Search for collections within the same project first.
-        {portable_data_hash: col_pdh, owner_uuid: project_uuid},
-        # then, earch for collections in any project.
-        {portable_data_hash: col_pdh},
-      ].each do |query_args|
-        col = Collection.where(query_args).limit(1)
-        if col.results.any?
-          if col.items_available == 1
-            return col.results.first.name
-          else
-            return "#{col.results.first.name} + #{col.items_available - 1} more"
-          end
-        end
-      end
-
-      # No collections found with this pdh
-      col_pdh
-    end
-
-    def cr_edges cr
-      uuid = cr[:uuid]
-      gr = ""
-
-      # Search for input mounts
-      input_obj = cr[:mounts].andand[:"/var/lib/cwl/cwl.input.json"].andand[:content] || cr[:mounts] || {}
+    def cr_input_pdhs cr
+      pdhs = []
+      input_obj = cr[:mounts].andand[:"/var/lib/cwl/cwl.input.json"].andand[:content] || cr[:mounts]
       if input_obj
-        ProvenanceHelper::find_collections input_obj, 'input' do |col_hash, col_uuid, key|
-          # Only include input PDHs
+        ProvenanceHelper::find_collections input_obj do |col_hash, col_uuid, key|
           if col_hash
-            gr += describe_node(col_hash,
-                                {label: col_name_for_project(col_hash, cr[:owner_uuid])})
-            gr += edge(col_hash, uuid, {:label => key})
+            pdhs << col_hash
           end
         end
       end
-
-      # Add CR outputs by PDH so they connect with the child CR's inputs.
-      if cr[:output_uuid]
-        output_col = Collection.find(cr[:output_uuid])
-        if output_col
-          gr += describe_node(output_col[:portable_data_hash],
-                              {label: output_col[:name]})
-          gr += edge(uuid, output_col[:portable_data_hash], {label: 'output'})
-        end
-      end
-
-      gr
+      pdhs
     end
 
     def job_edges job, edge_opts={}
@@ -238,17 +200,85 @@ module ProvenanceHelper
         elsif rsc == ContainerRequest
           cr = @pdata[uuid]
           if cr
-            gr += cr_edges cr
-            gr += describe_node(uuid, {href: {controller: 'container_requests',
-                                              id: uuid},
-                                       label: @pdata[uuid][:name],
-                                       shape: 'oval'})
+            child_crs = []
+            col_uuids = []
+            col_pdhs = []
+            col_uuids << cr[:output_uuid] if cr[:output_uuid]
+            col_pdhs += cr_input_pdhs(cr)
             # Search for child CRs
             if cr[:container_uuid]
               child_crs = ContainerRequest.where(requesting_container_uuid: cr[:container_uuid])
               child_crs.each do |child|
-                gr += generate_provenance_edges(child[:uuid])
-                gr += edge(child[:uuid], uuid, {label: 'child'})
+                col_uuids << child[:output_uuid] if child[:output_uuid]
+                col_pdhs += cr_input_pdhs(child)
+              end
+            end
+
+            output_cols = {} # Indexed by UUID
+            input_cols = {} # Indexed by PDH
+
+            # Batch requests to get all related collections
+            Collection.filter([['uuid', 'in', col_uuids.uniq]]).each do |c|
+              output_cols[c[:uuid]] = c
+            end
+            output_pdhs = output_cols.values.map{|c| c[:portable_data_hash]}.uniq
+            Collection.filter([['portable_data_hash', 'in',  col_pdhs - output_pdhs]]).each do |c|
+              if input_cols[c[:portable_data_hash]]
+                input_cols[c[:portable_data_hash]] << c
+              else
+                input_cols[c[:portable_data_hash]] = [c]
+              end
+            end
+
+            # Make the graph
+            visited_pdhs = []
+            all_cr_nodes = [cr] + child_crs.results
+
+            # First pass: add the CR nodes with their outputs, because they're
+            # referenced by UUID.
+            all_cr_nodes.each do |cr_node|
+              # CR node
+              gr += describe_node(cr_node[:uuid], {href: {controller: 'container_requests',
+                                                          id: cr_node[:uuid]},
+                                                   label: cr_node[:name],
+                                                   shape: 'oval'})
+              # Connect child CRs with the main one
+              if cr_node != cr
+                gr += edge(cr_node[:uuid], cr[:uuid], {label: 'child'})
+              end
+              # Output collection node
+              if cr_node[:output_uuid] and output_cols[cr_node[:output_uuid]]
+                c = output_cols[cr_node[:output_uuid]]
+                visited_pdhs << c[:portable_data_hash]
+                gr += describe_node(c[:portable_data_hash], {label: c[:name]})
+                gr += edge(cr_node[:uuid], c[:portable_data_hash], {label: 'output'})
+              end
+            end
+
+            # Second pass: add the input collection nodes.
+            all_cr_nodes.each do |cr_node|
+              cr_input_pdhs(cr_node).each do |pdh|
+                if not visited_pdhs.include?(pdh)
+                  visited_pdhs << pdh
+                  if input_cols[pdh]
+                    # First search for collections within the CR project
+                    cols = input_cols[pdh].select{|x| x[:owner_uuid] == cr_node[:owner_uuid]}
+                    if cols.empty?
+                      # Search for any collection with this PDH
+                      cols = input_cols[pdh]
+                    end
+                    names = cols.collect{|x| x[:name]}.uniq
+                    input_name = names.first
+                    if names.length > 1
+                      input_name += " + #{names.length - 1} others"
+                    end
+                  else
+                    # No collection found by this PDH
+                    input_name = pdh
+                  end
+                  gr += describe_node(pdh, {label: input_name})
+                end
+                gr += edge(pdh, cr_node[:uuid], {label: 'input'})
               end
             end
           end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list