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 filters = @filters + [["uuid", "is_a", ["arvados#pipelineInstance"]]]
18 pipelines = PipelineInstance.limit(@limit).order(["created_at desc"]).filter(filters)
20 # get next page of jobs
21 filters = @filters + [["uuid", "is_a", ["arvados#job"]]]
22 jobs = Job.limit(@limit).order(["created_at desc"]).filter(filters)
24 # get next page of container_requests
25 filters = @filters + [["uuid", "is_a", ["arvados#containerRequest"]]]
26 crs = ContainerRequest.limit(@limit).order(["created_at desc"]).filter(filters)
27 @objects = (jobs.to_a + pipelines.to_a + crs.to_a).sort_by(&:created_at).reverse.first(@limit)
30 @next_page_filters = next_page_filters('<=')
31 @next_page_href = url_for(partial: :all_processes_rows,
32 filters: @next_page_filters.to_json)
33 preload_links_for_objects(@objects.to_a)
39 def next_page_href with_params={}
44 template_uuid = params['work_unit']['template_uuid']
47 rc = resource_class_for_uuid(template_uuid)
48 if rc == PipelineTemplate
49 model_class = PipelineInstance
50 attrs['pipeline_template_uuid'] = template_uuid
53 workflow = Workflow.find? template_uuid
54 if workflow.definition
56 wf_json = YAML::load(workflow.definition)
58 logger.error "Error converting definition yaml to json: #{e.message}"
59 raise ArgumentError, "Error converting definition yaml to json: #{e.message}"
63 model_class = ContainerRequest
65 attrs['name'] = "#{workflow['name']} container" if workflow['name'].present?
66 attrs['properties'] = {'template_uuid' => template_uuid}
68 attrs['state'] = "Uncommitted"
71 attrs['command'] = ["arvados-cwl-runner", "--local", "--api=containers", "/var/lib/cwl/workflow.json#main", "/var/lib/cwl/cwl.input.json"]
72 attrs['container_image'] = "arvados/jobs"
73 attrs['cwd'] = "/var/spool/cwl"
74 attrs['output_path'] = "/var/spool/cwl"
78 "/var/lib/cwl/cwl.input.json" => {
84 "path" => "/var/spool/cwl/cwl.output.json"
87 "kind" => "collection",
92 mounts["/var/lib/cwl/workflow.json"] = {
97 attrs['mounts'] = mounts
100 runtime_constraints = {
105 attrs['runtime_constraints'] = runtime_constraints
107 raise ArgumentError, "Unsupported template uuid: #{template_uuid}"
110 attrs['owner_uuid'] = params['work_unit']['owner_uuid']
111 @object ||= model_class.new attrs
116 render_error status: 422
120 def find_object_by_uuid
121 if params['object_type']
122 @object = params['object_type'].constantize.find(params['uuid'])
128 def show_child_component
129 data = JSON.load(params[:action_data])
131 current_obj = data['current_obj']
132 current_obj_type = data['current_obj_type']
133 current_obj_name = data['current_obj_name']
134 if current_obj['uuid']
135 resource_class = resource_class_for_uuid current_obj['uuid']
136 obj = object_for_dataclass(resource_class, current_obj['uuid'])
137 current_obj = obj if obj
140 if current_obj_type == JobWorkUnit.to_s
141 wu = JobWorkUnit.new(current_obj, current_obj_name)
142 elsif current_obj_type == PipelineInstanceWorkUnit.to_s
143 wu = PipelineInstanceWorkUnit.new(current_obj, current_obj_name)
144 elsif current_obj_type == ContainerWorkUnit.to_s
145 wu = ContainerWorkUnit.new(current_obj, current_obj_name)
149 f.html { render(partial: "show_component", locals: {wu: wu}) }