X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e7b46691f98bf4e7edcf1ea3b98a677273d70b3b..5338c3fe0abbc6599aa290085be13eecfb0044e9:/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 75bcebd63f..8ce068198e 100644 --- a/apps/workbench/app/controllers/container_requests_controller.rb +++ b/apps/workbench/app/controllers/container_requests_controller.rb @@ -1,18 +1,88 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# 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 = {} + child_crs = [] + col_uuids = [] + col_pdhs = [] + col_uuids << cr[:output_uuid] if cr[:output_uuid] + col_pdhs += ProvenanceHelper::cr_input_pdhs(cr) + + # Search for child CRs + if 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 + col_uuids << child[:output_uuid] if child[:output_uuid] + col_pdhs += ProvenanceHelper::cr_input_pdhs(child) + end + end + + 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]]).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 + # Next, get input collections by PDH. + Collection.filter( + [['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, + :pdh_to_uuid => pdh_to_col, + } + ) + 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 + if @object.container_uuid + 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 + # the container (even if no other requests are giving it + # priority). To avoid showing this container request as "on + # hold" after hitting the Cancel button, set state=Final too. + @object.state = 'Final' + end + end @object.update_attributes! priority: 0 if params[:return_to] redirect_to params[:return_to] @@ -45,7 +115,7 @@ 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 @@ -64,12 +134,23 @@ class ContainerRequestsController < ApplicationController @object = ContainerRequest.new - # If "no reuse" requested, pass the correct argument to arvados-cwl-runner command. - if params[:no_reuse] and src.command[0] == 'arvados-cwl-runner' - command = src.command - ['--enable-reuse'] - command.insert(1, '--disable-reuse') + # 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 - command = src.command + @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 @@ -85,7 +166,6 @@ class ContainerRequestsController < ApplicationController @object.runtime_constraints = src.runtime_constraints @object.scheduling_parameters = src.scheduling_parameters @object.state = 'Uncommitted' - @object.use_existing = false # 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 @@ -95,4 +175,10 @@ class ContainerRequestsController < ApplicationController super end + + def index + @limit = 20 + super + end + end