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 @container = nil if !defined?(@container)
18 @child_proxies = child_objects
22 return @my_children if @my_children
25 container_uuid = if @proxied.is_a?(Container) then uuid else get(:container_uuid) end
27 cols = ContainerRequest.columns.map(&:name) - %w(id updated_at mounts secret_mounts runtime_token)
28 my_children = @child_proxies || ContainerRequest.select(cols).where(requesting_container_uuid: container_uuid).with_count("none").results if !my_children
29 my_child_containers = my_children.map(&:container_uuid).compact.uniq
31 my_child_containers.each { |c| grandchildren[c] = []} if my_child_containers.any?
32 reqs = ContainerRequest.select(cols).where(requesting_container_uuid: my_child_containers).with_count("none").results if my_child_containers.any?
33 reqs.each {|cr| grandchildren[cr.requesting_container_uuid] << cr} if reqs
35 my_children.each do |cr|
36 items << cr.work_unit(cr.name || 'this container', child_objects=grandchildren[cr.container_uuid])
40 @child_proxies = nil #no need of this any longer
51 return nil unless uuid
53 if @proxied.class.respond_to? :table_name
54 "/#{@proxied.class.table_name}/#{uuid}"
56 resource_class = ArvadosBase.resource_class_for_uuid(uuid)
57 "#{resource_class.table_name}/#{uuid}" if resource_class
62 @proxied.is_a?(ContainerRequest) &&
63 @proxied.state == "Committed" &&
64 (@proxied.priority > 0 || get(:state, @container) != 'Running') &&
72 def requesting_container_uuid
73 get(:requesting_container_uuid)
80 # For the following properties, use value from the @container if exists
81 # This applies to a ContainerRequest with container_uuid
84 t = get_combined(:started_at)
85 t = Time.parse(t) if (t.is_a? String)
90 t = get_combined(:modified_at)
91 t = Time.parse(t) if (t.is_a? String)
96 t = get_combined(:finished_at)
97 t = Time.parse(t) if (t.is_a? String)
102 if get(:state) == 'Final' && get(:state, @container) != 'Complete'
103 # Request was finalized before its container started (or the
104 # container was cancelled)
107 state = get(:state, @container) || get(:state, @proxied)
109 when 'Locked', 'Queued'
122 if runtime_status[:error]
124 elsif runtime_status[:warning]
130 # Cancelled, or Uncommitted (no container assigned)
136 return get(:runtime_status, @container) || get(:runtime_status, @proxied)
139 def state_bootstrap_class
151 get_combined(:exit_code)
155 get_combined(:container_image)
158 def runtime_constraints
159 get_combined(:runtime_constraints)
163 if @proxied.is_a?(ContainerRequest)
172 if @proxied.is_a?(ContainerRequest)
173 out = get(:output_uuid)
182 get_combined(:command)
190 env = get_combined(:environment)
191 env = nil if env.andand.empty?
196 mnt = get_combined(:mounts)
197 mnt = nil if mnt.andand.empty?
202 get_combined(:output_path)
206 [get(:uuid, @container), get(:uuid, @proxied)].compact
210 collection = Collection.find(log_collection) rescue nil
212 return {log: collection, partial: 'collections/show_files', locals: {object: collection, no_checkboxes: true}}
217 properties = get(:properties)
219 properties[:template_uuid]
223 # End combined properties
227 from_container = get(key, @container)
228 from_proxied = get(key, @proxied)
230 if from_container.is_a? Hash or from_container.is_a? Array
231 if from_container.any? then from_container else from_proxied end
233 from_container || from_proxied