1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class WorkUnitsController < ApplicationController
6 skip_around_filter :require_thread_api_token, if: proc { |ctrl|
7 Rails.configuration.anonymous_user_token and
8 'show_child_component' == ctrl.action_name
11 def find_objects_for_index
12 # If it's not the index rows partial display, just return
13 # The /index request will again be invoked to display the
14 # partial at which time, we will be using the objects found.
15 return if !params[:partial]
18 @filters = @filters || []
23 # get next page of pipeline_instances
24 if PipelineInstance.api_exists?(:index)
25 filters = @filters + [["uuid", "is_a", ["arvados#pipelineInstance"]]]
26 pipelines = PipelineInstance.limit(@limit).order(["created_at desc"]).filter(filters)
29 if params[:show_children]
30 # get next page of jobs
31 if Job.api_exists?(:index)
32 filters = @filters + [["uuid", "is_a", ["arvados#job"]]]
33 jobs = Job.limit(@limit).order(["created_at desc"]).filter(filters)
37 # get next page of container_requests
38 filters = @filters + [["uuid", "is_a", ["arvados#containerRequest"]]]
39 if !params[:show_children]
40 filters << ["requesting_container_uuid", "=", nil]
42 crs = ContainerRequest.limit(@limit).order(["created_at desc"]).filter(filters)
43 @objects = (jobs.to_a + pipelines.to_a + crs.to_a).sort_by(&:created_at).reverse.first(@limit)
46 @next_page_filters = next_page_filters('<=')
47 @next_page_href = url_for(partial: :all_processes_rows,
48 filters: @next_page_filters.to_json,
49 show_children: params[:show_children])
50 preload_links_for_objects(@objects.to_a)
56 def next_page_href with_params={}
61 template_uuid = params['work_unit']['template_uuid']
64 rc = resource_class_for_uuid(template_uuid)
65 if rc == PipelineTemplate
66 model_class = PipelineInstance
67 attrs['pipeline_template_uuid'] = template_uuid
70 workflow = Workflow.find? template_uuid
71 if workflow.definition
73 wf_json = ActiveSupport::HashWithIndifferentAccess.new YAML::load(workflow.definition)
75 logger.error "Error converting definition yaml to json: #{e.message}"
76 raise ArgumentError, "Error converting definition yaml to json: #{e.message}"
80 model_class = ContainerRequest
82 attrs['name'] = "#{workflow['name']} container" if workflow['name'].present?
83 attrs['properties'] = {'template_uuid' => template_uuid}
85 attrs['state'] = "Uncommitted"
88 attrs['command'] = ["arvados-cwl-runner",
91 "--project-uuid=#{params['work_unit']['owner_uuid']}",
92 "/var/lib/cwl/workflow.json#main",
93 "/var/lib/cwl/cwl.input.json"]
94 attrs['container_image'] = "arvados/jobs"
95 attrs['cwd'] = "/var/spool/cwl"
96 attrs['output_path'] = "/var/spool/cwl"
99 runtime_constraints = {
101 "ram" => 1024 * 1024 * 1024,
107 main = get_cwl_main(wf_json)
108 main[:inputs].each do |input|
110 input_defaults[cwl_shortname(input[:id])] = input[:default]
114 main[:hints].each do |hint|
115 if hint[:class] == "http://arvados.org/cwl#WorkflowRunnerResources"
117 runtime_constraints["vcpus"] = hint[:coresMin]
120 runtime_constraints["ram"] = hint[:ramMin] * 1024 * 1024
129 "/var/lib/cwl/cwl.input.json" => {
131 "content" => input_defaults
135 "path" => "/var/spool/cwl/cwl.output.json"
137 "/var/spool/cwl" => {
138 "kind" => "collection",
143 mounts["/var/lib/cwl/workflow.json"] = {
148 attrs['mounts'] = mounts
150 attrs['runtime_constraints'] = runtime_constraints
152 raise ArgumentError, "Unsupported template uuid: #{template_uuid}"
155 attrs['owner_uuid'] = params['work_unit']['owner_uuid']
156 @object ||= model_class.new attrs
161 render_error status: 422
165 def find_object_by_uuid
166 if params['object_type']
167 @object = params['object_type'].constantize.find(params['uuid'])
173 def show_child_component
174 data = JSON.load(params[:action_data])
177 current_obj_uuid = data['current_obj_uuid']
178 current_obj_name = data['current_obj_name']
179 current_obj_type = data['current_obj_type']
180 current_obj_parent = data['current_obj_parent']
182 resource_class = resource_class_for_uuid current_obj_uuid
183 obj = object_for_dataclass(resource_class, current_obj_uuid)
184 current_obj = obj if obj
187 if current_obj.is_a?(Hash) and !current_obj.any?
188 if current_obj_parent
189 resource_class = resource_class_for_uuid current_obj_parent
190 parent = object_for_dataclass(resource_class, current_obj_parent)
191 parent_wu = parent.work_unit
192 children = parent_wu.children
194 wu = children.select {|c| c.uuid == current_obj_uuid}.first
195 else current_obj_name
196 wu = children.select {|c| c.label.to_s == current_obj_name}.first
200 if current_obj_type == JobWorkUnit.to_s
201 wu = JobWorkUnit.new(current_obj, current_obj_name, current_obj_parent)
202 elsif current_obj_type == PipelineInstanceWorkUnit.to_s
203 wu = PipelineInstanceWorkUnit.new(current_obj, current_obj_name, current_obj_parent)
204 elsif current_obj_type == ContainerWorkUnit.to_s
205 wu = ContainerWorkUnit.new(current_obj, current_obj_name, current_obj_parent)
210 f.html { render(partial: "show_component", locals: {wu: wu}) }