1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class ContainerRequestsController < ApplicationController
6 skip_around_filter :require_thread_api_token, if: proc { |ctrl|
7 Rails.configuration.anonymous_user_token and
8 'show' == ctrl.action_name
11 def generate_provenance(cr)
12 return if params['tab_pane'] != "Provenance"
14 nodes = {cr[:uuid] => cr}
18 col_uuids << cr[:output_uuid] if cr[:output_uuid]
19 col_pdhs += ProvenanceHelper::cr_input_pdhs(cr)
21 # Search for child CRs
22 if cr[:container_uuid]
23 child_crs = ContainerRequest.where(requesting_container_uuid: cr[:container_uuid])
25 child_crs.each do |child|
26 nodes[child[:uuid]] = child
27 col_uuids << child[:output_uuid] if child[:output_uuid]
28 col_pdhs += ProvenanceHelper::cr_input_pdhs(child)
32 output_cols = {} # Indexed by UUID
33 input_cols = {} # Indexed by PDH
36 # Batch requests to get all related collections
37 # First fetch output collections by UUID.
38 Collection.filter([['uuid', 'in', col_uuids.uniq]]).each do |c|
39 output_cols[c[:uuid]] = c
40 output_pdhs << c[:portable_data_hash]
42 # Then, get only input collections by PDH. There could be more than one collection
43 # per PDH: the number of collections is used on the collection node label.
45 [['portable_data_hash', 'in', col_pdhs - output_pdhs]]).each do |c|
46 if input_cols[c[:portable_data_hash]]
47 input_cols[c[:portable_data_hash]] << c
49 input_cols[c[:portable_data_hash]] = [c]
53 @svg = ProvenanceHelper::create_provenance_graph(
54 nodes, "provenance_svg",
57 :direction => :top_down,
58 :output_collections => output_cols,
59 :input_collections => input_cols,
61 cr[:uuid] => child_crs.select{|child| child[:uuid]},
67 panes = %w(Status Log Provenance Advanced)
68 if @object.andand.state == 'Uncommitted'
69 panes = %w(Inputs) + panes - %w(Log Provenance)
75 generate_provenance(@object)
80 @object.update_attributes! priority: 0
82 redirect_to params[:return_to]
89 @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
90 input_obj = @updates[:mounts].andand[:"/var/lib/cwl/cwl.input.json"].andand[:content]
92 workflow = @object.mounts[:"/var/lib/cwl/workflow.json"][:content]
93 get_cwl_inputs(workflow).each do |input_schema|
94 if not input_obj.include? cwl_shortname(input_schema[:id])
97 required, primary_type, param_id = cwl_input_info(input_schema)
98 if input_obj[param_id] == ""
99 input_obj[param_id] = nil
100 elsif primary_type == "boolean"
101 input_obj[param_id] = input_obj[param_id] == "true"
102 elsif ["int", "long"].include? primary_type
103 input_obj[param_id] = input_obj[param_id].to_i
104 elsif ["float", "double"].include? primary_type
105 input_obj[param_id] = input_obj[param_id].to_f
106 elsif ["File", "Directory"].include? primary_type
107 re = CollectionsHelper.match_uuid_with_optional_filepath(input_obj[param_id])
109 c = Collection.find(re[1])
110 input_obj[param_id] = {"class" => primary_type,
111 "location" => "keep:#{c.portable_data_hash}#{re[4]}",
112 "arv:collection" => input_obj[param_id]}
117 params[:merge] = true
121 flash[:error] = e.to_s
129 @object = ContainerRequest.new
131 # By default the copied CR won't be reusing containers, unless use_existing=true
133 command = src.command
134 if params[:use_existing]
135 @object.use_existing = true
136 # Pass the correct argument to arvados-cwl-runner command.
137 if src.command[0] == 'arvados-cwl-runner'
138 command = src.command - ['--disable-reuse']
139 command.insert(1, '--enable-reuse')
142 @object.use_existing = false
143 # Pass the correct argument to arvados-cwl-runner command.
144 if src.command[0] == 'arvados-cwl-runner'
145 command = src.command - ['--enable-reuse']
146 command.insert(1, '--disable-reuse')
150 @object.command = command
151 @object.container_image = src.container_image
152 @object.cwd = src.cwd
153 @object.description = src.description
154 @object.environment = src.environment
155 @object.mounts = src.mounts
156 @object.name = src.name
157 @object.output_path = src.output_path
159 @object.properties[:template_uuid] = src.properties[:template_uuid]
160 @object.runtime_constraints = src.runtime_constraints
161 @object.scheduling_parameters = src.scheduling_parameters
162 @object.state = 'Uncommitted'
164 # set owner_uuid to that of source, provided it is a project and writable by current user
165 current_project = Group.find(src.owner_uuid) rescue nil
166 if (current_project && current_project.writable_by.andand.include?(current_user.uuid))
167 @object.owner_uuid = src.owner_uuid