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_create :verify_status
13 before_save :verify_status
15 api_accessible :user, extend: :common do |t|
16 t.add :pipeline_template_uuid
17 t.add :pipeline_template, :if => :pipeline_template
25 t.add :components_summary
28 # Supported states for a pipeline instance
31 RunningOnServer = 'RunningOnServer'
32 RunningOnClient = 'RunningOnClient'
38 dependency_search(self.components).keys
41 # if all components have input, the pipeline is Ready
42 def self.is_ready components
43 if !components || components.empty? # is this correct?
47 all_components_have_input = true
48 components.each do |name, component|
49 component['script_parameters'].each do |parametername, parameter|
50 parameter = { 'value' => parameter } unless parameter.is_a? Hash
51 if parameter['value'].nil? and
52 ![false,'false',0,'0'].index 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('active = true')
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)
144 self.state = RunningOnServer
146 if PipelineInstance.is_ready self.components
152 elsif success_changed?
155 self.state = Complete
178 else # new object create or save
179 if !self.state || self.state == New || !self.active
180 if PipelineInstance.is_ready self.components