1 class PipelineInstance < ArvadosModel
4 include CommonApiTemplate
5 serialize :components, Hash
6 serialize :properties, Hash
7 serialize :components_summary, Hash
8 belongs_to :pipeline_template, :foreign_key => :pipeline_template_uuid, :primary_key => :uuid
10 before_validation :bootstrap_components
11 before_validation :update_success
12 before_validation :verify_status
13 before_create :set_state_before_save
14 before_save :set_state_before_save
16 api_accessible :user, extend: :common do |t|
17 t.add :pipeline_template_uuid
18 t.add :pipeline_template, :if => :pipeline_template
26 t.add :components_summary
29 # Supported states for a pipeline instance
32 RunningOnServer = 'RunningOnServer'
33 RunningOnClient = 'RunningOnClient'
39 dependency_search(self.components).keys
42 # if all components have input, the pipeline is Ready
43 def components_look_ready?
44 if !self.components || self.components.empty?
48 all_components_have_input = true
49 self.components.each do |name, component|
50 component['script_parameters'].andand.each do |parametername, parameter|
51 parameter = { 'value' => parameter } unless parameter.is_a? Hash
52 if parameter['value'].nil? and parameter['required']
53 if parameter['output_of']
56 all_components_have_input = false
61 return all_components_have_input
68 components['steps'].collect do |step|
70 row = [nrow, step['name']]
71 if step['complete'] and step['complete'] != 0
72 if step['output_data_locator']
83 row << (step['warehousejob']['id'] rescue nil)
84 row << (step['warehousejob']['revision'] rescue nil)
85 row << step['output_data_locator']
86 row << (Time.parse(step['warehousejob']['finishtime']) rescue nil)
96 return 0 if t.size < 1
97 t.collect { |r| r[2] }.inject(0.0) { |sum,a| sum += a } / t.size
101 self.where("state = 'RunningOnServer'")
105 def bootstrap_components
106 if pipeline_template and (!components or components.empty?)
107 self.components = pipeline_template.components.deep_dup
112 if components and progress_ratio == 1.0
117 def dependency_search(haystack)
118 if haystack.is_a? String
119 if (re = haystack.match /^([0-9a-f]{32}(\+[^,]+)*)+/)
124 elsif haystack.is_a? Array
126 haystack.each do |value|
127 deps.merge! dependency_search(value)
130 elsif haystack.respond_to? :keys
132 haystack.each do |key, value|
133 deps.merge! dependency_search(value)
142 changed_attributes = self.changed
144 if 'state'.in? changed_attributes
146 when New, Ready, Paused
158 self.state = Failed # before_validation will fail if false is returned in the previous line
165 elsif 'success'.in? changed_attributes
168 self.state = Complete
173 elsif 'active'.in? changed_attributes
175 if self.state == New || self.state == Ready || self.state == Paused
176 self.state = RunningOnServer
179 if self.components_look_ready?
187 if 'components'.in? changed_attributes
188 if self.components_look_ready? && (!self.state || self.state == New)
194 def set_state_before_save
195 if !self.state || self.state == New || self.state == Ready || self.state == Paused
197 self.state = RunningOnServer
198 elsif self.components_look_ready? && (!self.state || self.state == New)