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) &&
62 @proxied.state == "Committed" &&
63 (@proxied.priority > 0 || get(:state, @container) != 'Running') &&
71 def requesting_container_uuid
72 get(:requesting_container_uuid)
79 # For the following properties, use value from the @container if exists
80 # This applies to a ContainerRequest with container_uuid
83 t = get_combined(:started_at)
84 t = Time.parse(t) if (t.is_a? String)
89 t = get_combined(:modified_at)
90 t = Time.parse(t) if (t.is_a? String)
95 t = get_combined(:finished_at)
96 t = Time.parse(t) if (t.is_a? String)
101 if get(:state) == 'Final' && get(:state, @container) != 'Complete'
102 # Request was finalized before its container started (or the
103 # container was cancelled)
106 state = get(:state, @container) || get(:state, @proxied)
108 when 'Locked', 'Queued'
121 # Cancelled, Running, or Uncommitted (no container assigned)
127 get_combined(:exit_code)
131 get_combined(:container_image)
134 def runtime_constraints
135 get_combined(:runtime_constraints)
139 if @proxied.is_a?(ContainerRequest)
148 if @proxied.is_a?(ContainerRequest)
149 out = get(:output_uuid)
158 get_combined(:command)
166 env = get_combined(:environment)
167 env = nil if env.andand.empty?
172 mnt = get_combined(:mounts)
173 mnt = nil if mnt.andand.empty?
178 get_combined(:output_path)
182 [get(:uuid, @container), get(:uuid, @proxied)].compact
186 collection = Collection.find(log_collection) rescue nil
188 return {log: collection, partial: 'collections/show_files', locals: {object: collection, no_checkboxes: true}}
193 properties = get(:properties)
195 properties[:template_uuid]
199 # End combined properties
203 from_container = get(key, @container)
204 from_proxied = get(key, @proxied)
206 if from_container.is_a? Hash or from_container.is_a? Array
207 if from_container.any? then from_container else from_proxied end
209 from_container || from_proxied