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_state
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
24 t.add :components_summary
30 # Supported states for a pipeline instance
35 (RunningOnServer = 'RunningOnServer'),
36 (RunningOnClient = 'RunningOnClient'),
39 (Complete = 'Complete'),
43 dependency_search(self.components).keys
46 # if all components have input, the pipeline is Ready
47 def components_look_ready?
48 if !self.components || self.components.empty?
52 all_components_have_input = true
53 self.components.each do |name, component|
54 component['script_parameters'].andand.each do |parametername, parameter|
55 parameter = { 'value' => parameter } unless parameter.is_a? Hash
56 if parameter['value'].nil? and parameter['required']
57 if parameter['output_of']
60 all_components_have_input = false
65 return all_components_have_input
72 components['steps'].collect do |step|
74 row = [nrow, step['name']]
75 if step['complete'] and step['complete'] != 0
76 if step['output_data_locator']
87 row << (step['warehousejob']['id'] rescue nil)
88 row << (step['warehousejob']['revision'] rescue nil)
89 row << step['output_data_locator']
90 row << (Time.parse(step['warehousejob']['finishtime']) rescue nil)
100 return 0 if t.size < 1
101 t.collect { |r| r[2] }.inject(0.0) { |sum,a| sum += a } / t.size
105 self.where("state = 'RunningOnServer'")
109 def bootstrap_components
110 if pipeline_template and (!components or components.empty?)
111 self.components = pipeline_template.components.deep_dup
116 if components and progress_ratio == 1.0
117 self.state = Complete
121 def dependency_search(haystack)
122 if haystack.is_a? String
123 if (re = haystack.match /^([0-9a-f]{32}(\+[^,]+)*)+/)
128 elsif haystack.is_a? Array
130 haystack.each do |value|
131 deps.merge! dependency_search(value)
134 elsif haystack.respond_to? :keys
136 haystack.each do |key, value|
137 deps.merge! dependency_search(value)
146 changed_attributes = self.changed
148 if new_record? or 'components'.in? changed_attributes
150 if (self.state == New) and self.components_look_ready?
155 if self.state.in?(States)
158 errors.add :state, "'#{state.inspect} must be one of: [#{States.join ', '}]"
163 def set_state_before_save
164 if self.components_look_ready? && (!self.state || self.state == New)