X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/16f704326f44fd1e5e5e60b936c9b5895d6a6ff8..ad2fd38b6c67f72c6eb9426f1a320d9517b694cd:/apps/workbench/app/controllers/container_requests_controller.rb diff --git a/apps/workbench/app/controllers/container_requests_controller.rb b/apps/workbench/app/controllers/container_requests_controller.rb index 783cafa117..be463b022c 100644 --- a/apps/workbench/app/controllers/container_requests_controller.rb +++ b/apps/workbench/app/controllers/container_requests_controller.rb @@ -3,15 +3,15 @@ # SPDX-License-Identifier: AGPL-3.0 class ContainerRequestsController < ApplicationController - skip_around_filter :require_thread_api_token, if: proc { |ctrl| - Rails.configuration.anonymous_user_token and + skip_around_action :require_thread_api_token, if: proc { |ctrl| + !Rails.configuration.Users.AnonymousUserToken.empty? and 'show' == ctrl.action_name } def generate_provenance(cr) return if params['tab_pane'] != "Provenance" - nodes = {cr[:uuid] => cr} + nodes = {} child_crs = [] col_uuids = [] col_pdhs = [] @@ -20,7 +20,7 @@ class ContainerRequestsController < ApplicationController # Search for child CRs if cr[:container_uuid] - child_crs = ContainerRequest.where(requesting_container_uuid: cr[:container_uuid]) + child_crs = ContainerRequest.where(requesting_container_uuid: cr[:container_uuid]).with_count("none") child_crs.each do |child| nodes[child[:uuid]] = child @@ -29,38 +29,33 @@ class ContainerRequestsController < ApplicationController end end - output_cols = {} # Indexed by UUID - input_cols = {} # Indexed by PDH + if nodes.length == 0 + nodes[cr[:uuid]] = cr + end + + pdh_to_col = {} # Indexed by PDH output_pdhs = [] # Batch requests to get all related collections # First fetch output collections by UUID. - Collection.filter([['uuid', 'in', col_uuids.uniq]]).each do |c| - output_cols[c[:uuid]] = c + Collection.filter([['uuid', 'in', col_uuids.uniq]]).with_count("none").each do |c| output_pdhs << c[:portable_data_hash] + pdh_to_col[c[:portable_data_hash]] = c + nodes[c[:uuid]] = c end - # Then, get only input collections by PDH. There could be more than one collection - # per PDH: the number of collections is used on the collection node label. + # Next, get input collections by PDH. 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 + [['portable_data_hash', 'in', col_pdhs - output_pdhs]]).with_count("none").each do |c| + nodes[c[:portable_data_hash]] = c end @svg = ProvenanceHelper::create_provenance_graph( nodes, "provenance_svg", { :request => request, - :direction => :top_down, - :output_collections => output_cols, - :input_collections => input_cols, - :cr_children_of => { - cr[:uuid] => child_crs.select{|child| child[:uuid]}, - }, - }) + :pdh_to_uuid => pdh_to_col, + } + ) end def show_pane_list @@ -78,7 +73,7 @@ class ContainerRequestsController < ApplicationController def cancel if @object.container_uuid - c = Container.select(['state']).where(uuid: @object.container_uuid).first + c = Container.select(['state']).where(uuid: @object.container_uuid).with_count("none").first if c && c.state != 'Running' # If the container hasn't started yet, setting priority=0 # leaves our request in "Committed" state and doesn't cancel @@ -120,12 +115,27 @@ class ContainerRequestsController < ApplicationController c = Collection.find(re[1]) input_obj[param_id] = {"class" => primary_type, "location" => "keep:#{c.portable_data_hash}#{re[4]}", - "arv:collection" => input_obj[param_id]} + "http://arvados.org/cwl#collectionUUID" => re[1]} end end end end params[:merge] = true + + if !@updates[:reuse_steps].nil? + if @updates[:reuse_steps] == "false" + @updates[:reuse_steps] = false + end + @updates[:command] ||= @object.command + @updates[:command] -= ["--disable-reuse", "--enable-reuse"] + if @updates[:reuse_steps] + @updates[:command].insert(1, "--enable-reuse") + else + @updates[:command].insert(1, "--disable-reuse") + end + @updates.delete(:reuse_steps) + end + begin super rescue => e @@ -139,21 +149,47 @@ class ContainerRequestsController < ApplicationController @object = ContainerRequest.new - # By default the copied CR won't be reusing containers, unless use_existing=true - # param is passed. + # set owner_uuid to that of source, provided it is a project and writable by current user + if params[:work_unit].andand[:owner_uuid] + @object.owner_uuid = src.owner_uuid = params[:work_unit][:owner_uuid] + else + 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 + end + command = src.command - if params[:use_existing] - @object.use_existing = true + if command[0] == 'arvados-cwl-runner' + command.each_with_index do |arg, i| + if arg.start_with? "--project-uuid=" + command[i] = "--project-uuid=#{@object.owner_uuid}" + end + end + command -= ["--disable-reuse", "--enable-reuse"] + command.insert(1, '--enable-reuse') + end + + if params[:use_existing] == "false" + params[:use_existing] = false + elsif params[:use_existing] == "true" + params[:use_existing] = true + end + + if params[:use_existing] || params[:use_existing].nil? + # If nil, reuse workflow steps but not the workflow runner. + @object.use_existing = !!params[:use_existing] + # Pass the correct argument to arvados-cwl-runner command. - if src.command[0] == 'arvados-cwl-runner' - command = src.command - ['--disable-reuse'] + if command[0] == 'arvados-cwl-runner' + command -= ["--disable-reuse", "--enable-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'] + if command[0] == 'arvados-cwl-runner' + command -= ["--disable-reuse", "--enable-reuse"] command.insert(1, '--disable-reuse') end end @@ -172,12 +208,6 @@ class ContainerRequestsController < ApplicationController @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