1 class ContainerRequestsController < ApplicationController
2 skip_around_filter :require_thread_api_token, if: proc { |ctrl|
3 Rails.configuration.anonymous_user_token and
4 'show' == ctrl.action_name
7 def generate_provenance(cr)
8 return if params['tab_pane'] != "Provenance"
10 nodes = {cr[:uuid] => cr}
14 col_uuids << cr[:output_uuid] if cr[:output_uuid]
15 col_pdhs += ProvenanceHelper::cr_input_pdhs(cr)
17 # Search for child CRs
18 if cr[:container_uuid]
19 child_crs = ContainerRequest.where(requesting_container_uuid: cr[:container_uuid])
21 child_crs.each do |child|
22 nodes[child[:uuid]] = child
23 col_uuids << child[:output_uuid] if child[:output_uuid]
24 col_pdhs += ProvenanceHelper::cr_input_pdhs(child)
28 output_cols = {} # Indexed by UUID
29 input_cols = {} # Indexed by PDH
32 # Batch requests to get all related collections
33 # First fetch output collections by UUID.
34 Collection.filter([['uuid', 'in', col_uuids.uniq]]).each do |c|
35 output_cols[c[:uuid]] = c
36 output_pdhs << c[:portable_data_hash]
38 # Then, get only input collections by PDH. There could be more than one collection
39 # per PDH: the number of collections is used on the collection node label.
41 [['portable_data_hash', 'in', col_pdhs - output_pdhs]]).each do |c|
42 if input_cols[c[:portable_data_hash]]
43 input_cols[c[:portable_data_hash]] << c
45 input_cols[c[:portable_data_hash]] = [c]
49 @svg = ProvenanceHelper::create_provenance_graph(
50 nodes, "provenance_svg",
53 :direction => :top_down,
54 :output_collections => output_cols,
55 :input_collections => input_cols,
57 cr[:uuid] => child_crs.select{|child| child[:uuid]},
63 panes = %w(Status Log Provenance Advanced)
64 if @object.andand.state == 'Uncommitted'
65 panes = %w(Inputs) + panes - %w(Log Provenance)
71 generate_provenance(@object)
76 @object.update_attributes! priority: 0
78 redirect_to params[:return_to]
85 @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
86 input_obj = @updates[:mounts].andand[:"/var/lib/cwl/cwl.input.json"].andand[:content]
88 workflow = @object.mounts[:"/var/lib/cwl/workflow.json"][:content]
89 get_cwl_inputs(workflow).each do |input_schema|
90 if not input_obj.include? cwl_shortname(input_schema[:id])
93 required, primary_type, param_id = cwl_input_info(input_schema)
94 if input_obj[param_id] == ""
95 input_obj[param_id] = nil
96 elsif primary_type == "boolean"
97 input_obj[param_id] = input_obj[param_id] == "true"
98 elsif ["int", "long"].include? primary_type
99 input_obj[param_id] = input_obj[param_id].to_i
100 elsif ["float", "double"].include? primary_type
101 input_obj[param_id] = input_obj[param_id].to_f
102 elsif ["File", "Directory"].include? primary_type
103 re = CollectionsHelper.match_uuid_with_optional_filepath(input_obj[param_id])
105 c = Collection.find(re[1])
106 input_obj[param_id] = {"class" => primary_type,
107 "location" => "keep:#{c.portable_data_hash}#{re[4]}",
108 "arv:collection" => input_obj[param_id]}
113 params[:merge] = true
117 flash[:error] = e.to_s
125 @object = ContainerRequest.new
127 # By default the copied CR won't be reusing containers, unless use_existing=true
129 command = src.command
130 if params[:use_existing]
131 @object.use_existing = true
132 # Pass the correct argument to arvados-cwl-runner command.
133 if src.command[0] == 'arvados-cwl-runner'
134 command = src.command - ['--disable-reuse']
135 command.insert(1, '--enable-reuse')
138 @object.use_existing = false
139 # Pass the correct argument to arvados-cwl-runner command.
140 if src.command[0] == 'arvados-cwl-runner'
141 command = src.command - ['--enable-reuse']
142 command.insert(1, '--disable-reuse')
146 @object.command = command
147 @object.container_image = src.container_image
148 @object.cwd = src.cwd
149 @object.description = src.description
150 @object.environment = src.environment
151 @object.mounts = src.mounts
152 @object.name = src.name
153 @object.output_path = src.output_path
155 @object.properties[:template_uuid] = src.properties[:template_uuid]
156 @object.runtime_constraints = src.runtime_constraints
157 @object.scheduling_parameters = src.scheduling_parameters
158 @object.state = 'Uncommitted'
160 # set owner_uuid to that of source, provided it is a project and writable by current user
161 current_project = Group.find(src.owner_uuid) rescue nil
162 if (current_project && current_project.writable_by.andand.include?(current_user.uuid))
163 @object.owner_uuid = src.owner_uuid