1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class ContainerWorkUnit < ProxyWorkUnit
6 attr_accessor :container
7 attr_accessor :child_proxies
9 def initialize proxied, label, parent, child_objects=nil
10 super proxied, label, parent
11 if @proxied.is_a?(ContainerRequest)
12 container_uuid = get(:container_uuid)
14 @container = Container.find(container_uuid)
17 @child_proxies = child_objects
21 return @my_children if @my_children
24 container_uuid = if @proxied.is_a?(Container) then uuid else get(:container_uuid) end
26 cols = ContainerRequest.columns.map(&:name) - %w(id updated_at mounts)
27 my_children = @child_proxies || ContainerRequest.select(cols).where(requesting_container_uuid: container_uuid).results if !my_children
28 my_child_containers = my_children.map(&:container_uuid).compact.uniq
30 my_child_containers.each { |c| grandchildren[c] = []} if my_child_containers.any?
31 reqs = ContainerRequest.select(cols).where(requesting_container_uuid: my_child_containers).results if my_child_containers.any?
32 reqs.each {|cr| grandchildren[cr.requesting_container_uuid] << cr} if reqs
34 my_children.each do |cr|
35 items << cr.work_unit(cr.name || 'this container', child_objects=grandchildren[cr.container_uuid])
39 @child_proxies = nil #no need of this any longer
50 return nil unless uuid
52 if @proxied.class.respond_to? :table_name
53 "/#{@proxied.class.table_name}/#{uuid}"
55 resource_class = ArvadosBase.resource_class_for_uuid(uuid)
56 "#{resource_class.table_name}/#{uuid}" if resource_class
61 @proxied.is_a?(ContainerRequest) && @proxied.state == "Committed" && @proxied.priority > 0 && @proxied.editable?
68 def requesting_container_uuid
69 get(:requesting_container_uuid)
76 # For the following properties, use value from the @container if exists
77 # This applies to a ContainerRequest with container_uuid
80 t = get_combined(:started_at)
81 t = Time.parse(t) if (t.is_a? String)
86 t = get_combined(:modified_at)
87 t = Time.parse(t) if (t.is_a? String)
92 t = get_combined(:finished_at)
93 t = Time.parse(t) if (t.is_a? String)
99 return "Failed" if (ec && ec != 0)
101 state = get_combined(:state)
103 return "Queued" if state == "Locked"
104 return "Cancelled" if ((priority == 0) and (state == "Queued"))
109 get_combined(:exit_code)
113 get_combined(:container_image)
116 def runtime_constraints
117 get_combined(:runtime_constraints)
121 if @proxied.is_a?(ContainerRequest)
130 if @proxied.is_a?(ContainerRequest)
131 out = get(:output_uuid)
140 get_combined(:command)
148 env = get_combined(:environment)
149 env = nil if env.andand.empty?
154 mnt = get_combined(:mounts)
155 mnt = nil if mnt.andand.empty?
160 get_combined(:output_path)
164 [get(:uuid, @container), get(:uuid, @proxied)].compact
168 collection = Collection.find(log_collection) rescue nil
170 return {log: collection, partial: 'collections/show_files', locals: {object: collection, no_checkboxes: true}}
175 properties = get(:properties)
177 properties[:template_uuid]
181 # End combined properties
185 from_container = get(key, @container)
186 from_proxied = get(key, @proxied)
188 if from_container.is_a? Hash or from_container.is_a? Array
189 if from_container.any? then from_container else from_proxied end
191 from_container || from_proxied