11185: Merge branch 'master' into 11185-wb-disable-reuse
[arvados.git] / apps / workbench / app / controllers / container_requests_controller.rb
index 54e59144e7873648ac149d4c4898905e9bd260b2..fd29cd3f7088b5ab2ca4011d7d6d8b9ab26b6182 100644 (file)
@@ -4,14 +4,37 @@ class ContainerRequestsController < ApplicationController
     'show' == ctrl.action_name
   }
 
+  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
+    @svg = ProvenanceHelper::create_provenance_graph nodes,
+                                                     "provenance_svg",
+                                                     {
+                                                       :request => request,
+                                                       :direction => :top_down,
+                                                     }
+  end
+
   def show_pane_list
-    panes = %w(Status Log Advanced)
+    panes = %w(Status Log Provenance Advanced)
     if @object.andand.state == 'Uncommitted'
-      panes = %w(Inputs) + panes - %w(Log)
+      panes = %w(Inputs) + panes - %w(Log Provenance)
     end
     panes
   end
 
+  def show
+    generate_provenance(@object)
+    super
+  end
+
   def cancel
     @object.update_attributes! priority: 0
     if params[:return_to]
@@ -26,8 +49,8 @@ class ContainerRequestsController < ApplicationController
     input_obj = @updates[:mounts].andand[:"/var/lib/cwl/cwl.input.json"].andand[:content]
     if input_obj
       workflow = @object.mounts[:"/var/lib/cwl/workflow.json"][:content]
-      workflow[:inputs].each do |input_schema|
-        if not input_obj.include? input_schema[:id]
+      get_cwl_inputs(workflow).each do |input_schema|
+        if not input_obj.include? cwl_shortname(input_schema[:id])
           next
         end
         required, primary_type, param_id = cwl_input_info(input_schema)
@@ -51,7 +74,58 @@ class ContainerRequestsController < ApplicationController
       end
     end
     params[:merge] = true
-    super
+    begin
+      super
+    rescue => e
+      flash[:error] = e.to_s
+      show
+    end
   end
 
+  def copy
+    src = @object
+
+    @object = ContainerRequest.new
+
+    # By default the copied CR won't be reusing containers, unless use_existing=true
+    # param is passed.
+    command = src.command
+    if params[:use_existing]
+      @object.use_existing = true
+      # Pass the correct argument to arvados-cwl-runner command.
+      if src.command[0] == 'arvados-cwl-runner'
+        command = src.command - ['--disable-reuse']
+        command.insert(1, '--enable-reuse')
+      end
+    else
+      @object.use_existing = false
+      # Pass the correct argument to arvados-cwl-runner command.
+      if src.command[0] == 'arvados-cwl-runner'
+        command = src.command - ['--enable-reuse']
+        command.insert(1, '--disable-reuse')
+      end
+    end
+
+    @object.command = command
+    @object.container_image = src.container_image
+    @object.cwd = src.cwd
+    @object.description = src.description
+    @object.environment = src.environment
+    @object.mounts = src.mounts
+    @object.name = src.name
+    @object.output_path = src.output_path
+    @object.priority = 1
+    @object.properties[:template_uuid] = src.properties[:template_uuid]
+    @object.runtime_constraints = src.runtime_constraints
+    @object.scheduling_parameters = src.scheduling_parameters
+    @object.state = 'Uncommitted'
+
+    # set owner_uuid to that of source, provided it is a project and writable by current user
+    current_project = Group.find(src.owner_uuid) rescue nil
+    if (current_project && current_project.writable_by.andand.include?(current_user.uuid))
+      @object.owner_uuid = src.owner_uuid
+    end
+
+    super
+  end
 end