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 = 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 "/var/lib/cwl/cwl.input.json" => {
88 "path" => "/var/spool/cwl/cwl.output.json"
91 "kind" => "collection",
96 mounts["/var/lib/cwl/workflow.json"] = {
101 attrs['mounts'] = mounts
103 # runtime constriants
104 runtime_constraints = {
109 attrs['runtime_constraints'] = runtime_constraints
111 raise ArgumentError, "Unsupported template uuid: #{template_uuid}"
114 attrs['owner_uuid'] = params['work_unit']['owner_uuid']
115 @object ||= model_class.new attrs
120 render_error status: 422
124 def find_object_by_uuid
125 if params['object_type']
126 @object = params['object_type'].constantize.find(params['uuid'])
132 def show_child_component
133 data = JSON.load(params[:action_data])
136 current_obj_uuid = data['current_obj_uuid']
137 current_obj_name = data['current_obj_name']
138 current_obj_type = data['current_obj_type']
139 current_obj_parent = data['current_obj_parent']
141 resource_class = resource_class_for_uuid current_obj_uuid
142 obj = object_for_dataclass(resource_class, current_obj_uuid)
143 current_obj = obj if obj
146 if current_obj.is_a?(Hash) and !current_obj.any?
147 if current_obj_parent
148 resource_class = resource_class_for_uuid current_obj_parent
149 parent = object_for_dataclass(resource_class, current_obj_parent)
150 parent_wu = parent.work_unit
151 children = parent_wu.children
153 wu = children.select {|c| c.uuid == current_obj_uuid}.first
154 else current_obj_name
155 wu = children.select {|c| c.label.to_s == current_obj_name}.first
159 if current_obj_type == JobWorkUnit.to_s
160 wu = JobWorkUnit.new(current_obj, current_obj_name, current_obj_parent)
161 elsif current_obj_type == PipelineInstanceWorkUnit.to_s
162 wu = PipelineInstanceWorkUnit.new(current_obj, current_obj_name, current_obj_parent)
163 elsif current_obj_type == ContainerWorkUnit.to_s
164 wu = ContainerWorkUnit.new(current_obj, current_obj_name, current_obj_parent)
169 f.html { render(partial: "show_component", locals: {wu: wu}) }