X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cdd94fae8d40ad6dcee3de5d36de2d89921fd12d..d13ad5bbb7f5e74cb43d0570d9d1a8159237f5ff:/services/api/app/models/job.rb diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb index 8bd308d14b..9fc58a6806 100644 --- a/services/api/app/models/job.rb +++ b/services/api/app/models/job.rb @@ -6,11 +6,10 @@ class Job < ArvadosModel serialize :script_parameters, Hash serialize :runtime_constraints, Hash serialize :tasks_summary, Hash - before_validation :find_docker_image_locator before_create :ensure_unique_submit_id - before_create :ensure_script_version_is_commit - before_update :ensure_script_version_is_commit after_commit :trigger_crunch_dispatch_if_cancelled, :on => :update + validate :ensure_script_version_is_commit + validate :find_docker_image_locator has_many :commit_ancestors, :foreign_key => :descendant, :primary_key => :script_version @@ -29,7 +28,6 @@ class Job < ArvadosModel t.add :started_at t.add :finished_at t.add :output - t.add :output_is_persistent t.add :success t.add :running t.add :is_locked_by_uuid @@ -87,7 +85,8 @@ class Job < ArvadosModel self.supplied_script_version = self.script_version if self.supplied_script_version.nil? or self.supplied_script_version.empty? self.script_version = sha1 else - raise ArgumentError.new("Specified script_version does not resolve to a commit") + self.errors.add :script_version, "#{self.script_version} does not resolve to a commit" + return false end end end @@ -104,12 +103,22 @@ class Job < ArvadosModel def find_docker_image_locator # Find the Collection that holds the Docker image specified in the # runtime constraints, and store its locator in docker_image_locator. + unless runtime_constraints.is_a? Hash + # We're still in validation stage, so we can't assume + # runtime_constraints isn't something horrible like an array or + # a string. Treat those cases as "no docker image supplied"; + # other validations will fail anyway. + self.docker_image_locator = nil + return true + end image_search = runtime_constraints['docker_image'] image_tag = runtime_constraints['docker_image_tag'] if image_search.nil? self.docker_image_locator = nil + true elsif coll = Collection.for_latest_docker_image(image_search, image_tag) - self.docker_image_locator = coll.uuid + self.docker_image_locator = coll.portable_data_hash + true else errors.add(:docker_image_locator, "not found for #{image_search}") false @@ -181,7 +190,7 @@ class Job < ArvadosModel if self.cancelled_at and not self.cancelled_at_was self.cancelled_at = Time.now self.cancelled_by_user_uuid = current_user.uuid - self.cancelled_by_client_uuid = current_api_client.uuid + self.cancelled_by_client_uuid = current_api_client.andand.uuid @need_crunch_dispatch_trigger = true else self.cancelled_at = self.cancelled_at_was