X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9ac2a7d67db543a0356bdcc7c3ca37920086eae1..d940d88f991c14785110855ba0ee79ea5f401276:/services/api/app/models/pipeline_instance.rb diff --git a/services/api/app/models/pipeline_instance.rb b/services/api/app/models/pipeline_instance.rb index bc10523a36..0b0af8b87d 100644 --- a/services/api/app/models/pipeline_instance.rb +++ b/services/api/app/models/pipeline_instance.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class PipelineInstance < ArvadosModel include HasUuid include KindAndEtag @@ -5,13 +9,19 @@ class PipelineInstance < ArvadosModel serialize :components, Hash serialize :properties, Hash serialize :components_summary, Hash - belongs_to :pipeline_template, :foreign_key => :pipeline_template_uuid, :primary_key => :uuid + belongs_to :pipeline_template, + foreign_key: 'pipeline_template_uuid', + primary_key: 'uuid', + optional: true before_validation :bootstrap_components before_validation :update_state before_validation :verify_status + before_validation :update_timestamps_when_state_changes before_create :set_state_before_save before_save :set_state_before_save + before_create :create_disabled + before_update :update_disabled api_accessible :user, extend: :common do |t| t.add :pipeline_template_uuid @@ -37,6 +47,10 @@ class PipelineInstance < ArvadosModel (Complete = 'Complete'), ] + def self.limit_index_columns_read + ["components"] + end + # if all components have input, the pipeline is Ready def components_look_ready? if !self.components || self.components.empty? @@ -99,6 +113,10 @@ class PipelineInstance < ArvadosModel self.where("state = 'RunningOnServer'") end + def cancel(cascade: false, need_transaction: true) + raise "No longer supported" + end + protected def bootstrap_components if pipeline_template and (!components or components.empty?) @@ -112,30 +130,6 @@ class PipelineInstance < ArvadosModel end end - def dependency_search(haystack) - if haystack.is_a? String - if (re = haystack.match /^([0-9a-f]{32}(\+[^,]+)*)+/) - {re[1] => true} - else - {} - end - elsif haystack.is_a? Array - deps = {} - haystack.each do |value| - deps.merge! dependency_search(value) - end - deps - elsif haystack.respond_to? :keys - deps = {} - haystack.each do |key, value| - deps.merge! dependency_search(value) - end - deps - else - {} - end - end - def verify_status changed_attributes = self.changed @@ -146,11 +140,9 @@ class PipelineInstance < ArvadosModel end end - if self.state.in?(States) - true - else + if !self.state.in?(States) errors.add :state, "'#{state.inspect} must be one of: [#{States.join ', '}]" - false + throw(:abort) end end @@ -160,4 +152,25 @@ class PipelineInstance < ArvadosModel end end + def update_timestamps_when_state_changes + return if not (state_changed? or new_record?) + + case state + when RunningOnServer, RunningOnClient + self.started_at ||= db_current_time + when Failed, Complete + current_time = db_current_time + self.started_at ||= current_time + self.finished_at ||= current_time + end + end + + + def create_disabled + raise "Disabled" + end + + def update_disabled + raise "Disabled" + end end