X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e768a05df9fd75cee3724e6b68cb65beeebaaa38..4dd3d867e590ff54b9e2c1abeea879bcdf87c529:/services/api/app/models/container.rb diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb index edcb8501a4..cff0658ee7 100644 --- a/services/api/app/models/container.rb +++ b/services/api/app/models/container.rb @@ -20,6 +20,7 @@ class Container < ArvadosModel serialize :runtime_constraints, Hash serialize :command, Array serialize :scheduling_parameters, Hash + serialize :secret_mounts, Hash before_validation :fill_field_defaults, :if => :new_record? before_validation :set_timestamps @@ -31,6 +32,8 @@ class Container < ArvadosModel validate :validate_output after_validation :assign_auth before_save :sort_serialized_attrs + before_save :update_secret_mounts_md5 + before_save :scrub_secret_mounts after_save :handle_completed after_save :propagate_priority @@ -79,6 +82,18 @@ class Container < ArvadosModel ["mounts"] end + def self.full_text_searchable_columns + super - ["secret_mounts", "secret_mounts_md5"] + end + + def self.searchable_columns *args + super - ["secret_mounts_md5"] + end + + def logged_attributes + super.except('secret_mounts') + end + def state_transitions State_transitions end @@ -90,7 +105,7 @@ class Container < ArvadosModel self.priority = ContainerRequest. where(container_uuid: uuid, state: ContainerRequest::Committed). - maximum('priority') + maximum('priority') || 0 self.save! end end @@ -121,6 +136,7 @@ class Container < ArvadosModel mounts: resolve_mounts(req.mounts), runtime_constraints: resolve_runtime_constraints(req.runtime_constraints), scheduling_parameters: req.scheduling_parameters, + secret_mounts: req.secret_mounts, } act_as_system_user do if req.use_existing && (reusable = find_reusable(c_attrs)) @@ -217,6 +233,9 @@ class Container < ArvadosModel candidates = candidates.where_serialized(:mounts, resolve_mounts(attrs[:mounts])) log_reuse_info(candidates) { "after filtering on mounts #{attrs[:mounts].inspect}" } + candidates = candidates.where('secret_mounts_md5 = ?', Digest::MD5.hexdigest(SafeJSON.dump(self.deep_sort_hash(attrs[:secret_mounts] || {})))) + log_reuse_info(candidates) { "after filtering on mounts #{attrs[:mounts].inspect}" } + candidates = candidates.where_serialized(:runtime_constraints, resolve_runtime_constraints(attrs[:runtime_constraints])) log_reuse_info(candidates) { "after filtering on runtime_constraints #{attrs[:runtime_constraints].inspect}" } @@ -378,7 +397,8 @@ class Container < ArvadosModel if self.new_record? permitted.push(:owner_uuid, :command, :container_image, :cwd, :environment, :mounts, :output_path, :priority, - :runtime_constraints, :scheduling_parameters) + :runtime_constraints, :scheduling_parameters, + :secret_mounts) end case self.state @@ -487,6 +507,22 @@ class Container < ArvadosModel end end + def update_secret_mounts_md5 + if self.secret_mounts_changed? + self.secret_mounts_md5 = Digest::MD5.hexdigest( + SafeJSON.dump(self.class.deep_sort_hash(self.secret_mounts))) + end + end + + def scrub_secret_mounts + # this runs after update_secret_mounts_md5, so the + # secret_mounts_md5 will still reflect the secrets that are being + # scrubbed here. + if self.state_changed? && self.final? + self.secret_mounts = {} + end + end + def handle_completed # This container is finished so finalize any associated container requests # that are associated with this container. @@ -515,7 +551,7 @@ class Container < ArvadosModel cr.with_lock do # Use row locking because this increments container_count cr.container_uuid = c.uuid - cr.save + cr.save! end end end @@ -526,11 +562,21 @@ class Container < ArvadosModel cr.finalize! end - # Try to cancel any outstanding container requests made by this container. - ContainerRequest.where(requesting_container_uuid: uuid, - state: ContainerRequest::Committed).each do |cr| - cr.priority = 0 - cr.save + # Cancel outstanding container requests made by this container. + ContainerRequest. + includes(:container). + where(requesting_container_uuid: uuid, + state: ContainerRequest::Committed).each do |cr| + cr.update_attributes!(priority: 0) + cr.container.reload + if cr.container.state == Container::Queued || cr.container.state == Container::Locked + # If the child container hasn't started yet, finalize the + # child CR now instead of leaving it "on hold", i.e., + # Queued with priority 0. (OTOH, if the child is already + # running, leave it alone so it can get cancelled the + # usual way, get a copy of the log collection, etc.) + cr.update_attributes!(state: ContainerRequest::Final) + end end end end