1 class ContainerWorkUnit < ProxyWorkUnit
2 attr_accessor :container
3 attr_accessor :child_proxies
5 def initialize proxied, label, parent, child_objects=nil
6 super proxied, label, parent
7 if @proxied.is_a?(ContainerRequest)
8 container_uuid = get(:container_uuid)
10 @container = Container.find(container_uuid)
13 @child_proxies = child_objects
17 return @my_children if @my_children
20 container_uuid = if @proxied.is_a?(Container) then uuid else get(:container_uuid) end
22 cols = ContainerRequest.columns.map(&:name) - %w(id updated_at mounts)
23 my_children = @child_proxies || ContainerRequest.select(cols).where(requesting_container_uuid: container_uuid).results if !my_children
24 my_child_containers = my_children.map(&:container_uuid).compact.uniq
26 my_child_containers.each { |c| grandchildren[c] = []} if my_child_containers.any?
27 reqs = ContainerRequest.select(cols).where(requesting_container_uuid: my_child_containers).results if my_child_containers.any?
28 reqs.each {|cr| grandchildren[cr.requesting_container_uuid] << cr} if reqs
30 my_children.each do |cr|
31 items << cr.work_unit(cr.name || 'this container', child_objects=grandchildren[cr.container_uuid])
35 @child_proxies = nil #no need of this any longer
46 return nil unless uuid
48 if @proxied.class.respond_to? :table_name
49 "/#{@proxied.class.table_name}/#{uuid}"
51 resource_class = ArvadosBase.resource_class_for_uuid(uuid)
52 "#{resource_class.table_name}/#{uuid}" if resource_class
57 @proxied.is_a?(ContainerRequest) && @proxied.state == "Committed" && @proxied.priority > 0 && @proxied.editable?
64 def requesting_container_uuid
65 get(:requesting_container_uuid)
72 # For the following properties, use value from the @container if exists
73 # This applies to a ContainerRequest with container_uuid
76 t = get_combined(:started_at)
77 t = Time.parse(t) if (t.is_a? String)
82 t = get_combined(:modified_at)
83 t = Time.parse(t) if (t.is_a? String)
88 t = get_combined(:finished_at)
89 t = Time.parse(t) if (t.is_a? String)
95 return "Failed" if (ec && ec != 0)
97 state = get_combined(:state)
99 return "Queued" if state == "Locked"
100 return "Cancelled" if ((priority == 0) and (state == "Queued"))
105 get_combined(:exit_code)
109 get_combined(:container_image)
112 def runtime_constraints
113 get_combined(:runtime_constraints)
117 if @proxied.is_a?(ContainerRequest)
126 if @proxied.is_a?(ContainerRequest)
127 out = get(:output_uuid)
136 get_combined(:command)
144 env = get_combined(:environment)
145 env = nil if env.andand.empty?
150 mnt = get_combined(:mounts)
151 mnt = nil if mnt.andand.empty?
156 get_combined(:output_path)
160 [get(:uuid, @container), get(:uuid, @proxied)].compact
164 collection = Collection.find(log_collection) rescue nil
166 return {log: collection, partial: 'collections/show_files', locals: {object: collection, no_checkboxes: true}}
171 properties = get(:properties)
173 properties[:template_uuid]
177 # End combined properties
181 from_container = get(key, @container)
182 from_proxied = get(key, @proxied)
184 if from_container.is_a? Hash or from_container.is_a? Array
185 if from_container.any? then from_container else from_proxied end
187 from_container || from_proxied