1 class WorkUnitsController < ApplicationController
2 skip_around_filter :require_thread_api_token, if: proc { |ctrl|
3 Rails.configuration.anonymous_user_token and
4 'show_child_component' == ctrl.action_name
7 def find_objects_for_index
8 # If it's not the index rows partial display, just return
9 # The /index request will again be invoked to display the
10 # partial at which time, we will be using the objects found.
11 return if !params[:partial]
14 @filters = @filters || []
16 # get next page of pipeline_instances
17 if PipelineInstance.api_exists?(:index)
18 filters = @filters + [["uuid", "is_a", ["arvados#pipelineInstance"]]]
19 pipelines = PipelineInstance.limit(@limit).order(["created_at desc"]).filter(filters)
22 # get next page of jobs
23 if Job.api_exists?(:index)
24 filters = @filters + [["uuid", "is_a", ["arvados#job"]]]
25 jobs = Job.limit(@limit).order(["created_at desc"]).filter(filters)
28 # get next page of container_requests
29 filters = @filters + [["uuid", "is_a", ["arvados#containerRequest"]]]
30 crs = ContainerRequest.limit(@limit).order(["created_at desc"]).filter(filters)
31 @objects = (jobs.to_a + pipelines.to_a + crs.to_a).sort_by(&:created_at).reverse.first(@limit)
34 @next_page_filters = next_page_filters('<=')
35 @next_page_href = url_for(partial: :all_processes_rows,
36 filters: @next_page_filters.to_json)
37 preload_links_for_objects(@objects.to_a)
43 def next_page_href with_params={}
48 template_uuid = params['work_unit']['template_uuid']
51 rc = resource_class_for_uuid(template_uuid)
52 if rc == PipelineTemplate
53 model_class = PipelineInstance
54 attrs['pipeline_template_uuid'] = template_uuid
57 workflow = Workflow.find? template_uuid
58 if workflow.definition
60 wf_json = ActiveSupport::HashWithIndifferentAccess.new YAML::load(workflow.definition)
62 logger.error "Error converting definition yaml to json: #{e.message}"
63 raise ArgumentError, "Error converting definition yaml to json: #{e.message}"
67 model_class = ContainerRequest
69 attrs['name'] = "#{workflow['name']} container" if workflow['name'].present?
70 attrs['properties'] = {'template_uuid' => template_uuid}
72 attrs['state'] = "Uncommitted"
75 attrs['command'] = ["arvados-cwl-runner", "--local", "--api=containers", "/var/lib/cwl/workflow.json#main", "/var/lib/cwl/cwl.input.json"]
76 attrs['container_image'] = "arvados/jobs"
77 attrs['cwd'] = "/var/spool/cwl"
78 attrs['output_path'] = "/var/spool/cwl"
82 inputs = get_cwl_inputs(wf_json)
83 inputs.each do |input|
85 input_defaults[cwl_shortname(input[:id])] = input[:default]
92 "/var/lib/cwl/cwl.input.json" => {
94 "content" => input_defaults
98 "path" => "/var/spool/cwl/cwl.output.json"
100 "/var/spool/cwl" => {
101 "kind" => "collection",
106 mounts["/var/lib/cwl/workflow.json"] = {
111 attrs['mounts'] = mounts
113 # runtime constriants
114 runtime_constraints = {
119 attrs['runtime_constraints'] = runtime_constraints
121 raise ArgumentError, "Unsupported template uuid: #{template_uuid}"
124 attrs['owner_uuid'] = params['work_unit']['owner_uuid']
125 @object ||= model_class.new attrs
130 render_error status: 422
134 def find_object_by_uuid
135 if params['object_type']
136 @object = params['object_type'].constantize.find(params['uuid'])
142 def show_child_component
143 data = JSON.load(params[:action_data])
146 current_obj_uuid = data['current_obj_uuid']
147 current_obj_name = data['current_obj_name']
148 current_obj_type = data['current_obj_type']
149 current_obj_parent = data['current_obj_parent']
151 resource_class = resource_class_for_uuid current_obj_uuid
152 obj = object_for_dataclass(resource_class, current_obj_uuid)
153 current_obj = obj if obj
156 if current_obj.is_a?(Hash) and !current_obj.any?
157 if current_obj_parent
158 resource_class = resource_class_for_uuid current_obj_parent
159 parent = object_for_dataclass(resource_class, current_obj_parent)
160 parent_wu = parent.work_unit
161 children = parent_wu.children
163 wu = children.select {|c| c.uuid == current_obj_uuid}.first
164 else current_obj_name
165 wu = children.select {|c| c.label.to_s == current_obj_name}.first
169 if current_obj_type == JobWorkUnit.to_s
170 wu = JobWorkUnit.new(current_obj, current_obj_name, current_obj_parent)
171 elsif current_obj_type == PipelineInstanceWorkUnit.to_s
172 wu = PipelineInstanceWorkUnit.new(current_obj, current_obj_name, current_obj_parent)
173 elsif current_obj_type == ContainerWorkUnit.to_s
174 wu = ContainerWorkUnit.new(current_obj, current_obj_name, current_obj_parent)
179 f.html { render(partial: "show_component", locals: {wu: wu}) }