X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/dfda2d511b5581968c5fa456c78776ac453dedd9..6c0bf267d795a3ca49c3258c9490714c9e18d333:/services/api/app/models/container.rb diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb index c1c3eae94b..a60ea427b7 100644 --- a/services/api/app/models/container.rb +++ b/services/api/app/models/container.rb @@ -5,6 +5,7 @@ class Container < ArvadosModel include KindAndEtag include CommonApiTemplate include WhitelistUpdate + extend CurrentApiClient serialize :environment, Hash serialize :mounts, Hash @@ -87,10 +88,34 @@ class Container < ArvadosModel where('mounts = ?', self.deep_sort_hash(attrs[:mounts]).to_yaml). where('runtime_constraints = ?', self.deep_sort_hash(attrs[:runtime_constraints]).to_yaml) - # Check for Completed candidates that only had consistent outputs. + # Check for Completed candidates that had consistent outputs. completed = candidates.where(state: Complete).where(exit_code: 0) - if completed.select("output").group('output').limit(2).length == 1 - return completed.order('finished_at asc').limit(1).first + outputs = completed.select('output').group('output').limit(2) + if outputs.count.count != 1 + Rails.logger.debug("Found #{outputs.count.length} different outputs") + elsif Collection. + readable_by(current_user). + where(portable_data_hash: outputs.first.output). + count < 1 + Rails.logger.info("Found reusable container(s) " + + "but output #{outputs.first} is not readable " + + "by user #{current_user.uuid}") + else + # Return the oldest eligible container whose log is still + # present and readable by current_user. + readable_pdh = Collection. + readable_by(current_user). + select('portable_data_hash') + completed = completed. + where("log in (#{readable_pdh.to_sql})"). + order('finished_at asc'). + limit(1) + if completed.first + return completed.first + else + Rails.logger.info("Found reusable container(s) but none with a log " + + "readable by user #{current_user.uuid}") + end end # Check for Running candidates and return the most likely to finish sooner. @@ -284,13 +309,13 @@ class Container < ArvadosModel act_as_system_user do # Notify container requests associated with this container ContainerRequest.where(container_uuid: uuid, - :state => ContainerRequest::Committed).each do |cr| + state: ContainerRequest::Committed).each do |cr| cr.container_completed! end # Try to cancel any outstanding container requests made by this container. ContainerRequest.where(requesting_container_uuid: uuid, - :state => ContainerRequest::Committed).each do |cr| + state: ContainerRequest::Committed).each do |cr| cr.priority = 0 cr.save end