belongs_to :pipeline_template, :foreign_key => :pipeline_template_uuid, :primary_key => :uuid
before_validation :bootstrap_components
- before_validation :update_success
+ before_validation :update_status
before_validation :verify_status
before_create :set_state_before_save
before_save :set_state_before_save
t.add :pipeline_template, :if => :pipeline_template
t.add :name
t.add :components
- t.add :success
- t.add :active
t.add :dependencies
t.add :properties
t.add :state
else
row << 0.0
if step['failed']
- self.success = false
+ self.state = Failed
end
end
row << (step['warehousejob']['id'] rescue nil)
end
end
- def update_success
+ def update_status
if components and progress_ratio == 1.0
- self.success = true
+ self.state = Complete
end
end
def verify_status
changed_attributes = self.changed
- if 'state'.in? changed_attributes
- case self.state
- when New, Ready, Paused
- self.active = nil
- self.success = nil
- when RunningOnServer
- self.active = true
- self.success = nil
- when RunningOnClient
- self.active = nil
- self.success = nil
- when Failed
- self.active = false
- self.success = false
- self.state = Failed # before_validation will fail if false is returned in the previous line
- when Complete
- self.active = false
- self.success = true
- else
- return false
- end
- elsif 'success'.in? changed_attributes
- logger.info "pipeline_instance changed_attributes has success for #{self.uuid}"
- if self.success
- self.active = false
- self.state = Complete
- else
- self.active = false
- self.state = Failed
- end
- elsif 'active'.in? changed_attributes
- logger.info "pipeline_instance changed_attributes has active for #{self.uuid}"
- if self.active
- if self.state.in? [New, Ready, Paused]
- self.state = RunningOnServer
- end
- else
- if self.state == RunningOnServer # state was RunningOnServer
- self.active = nil
- self.state = Paused
- elsif self.components_look_ready?
- self.state = Ready
- else
- self.state = New
- end
- end
- elsif new_record? and self.state.nil?
- # No state, active, or success given
- self.state = New
- end
-
if new_record? or 'components'.in? changed_attributes
self.state ||= New
- if self.state == New and self.components_look_ready?
+ if (self.state == New) and self.components_look_ready?
self.state = Ready
end
end
end
def set_state_before_save
- if !self.state || self.state == New || self.state == Ready || self.state == Paused
- if self.active
- self.state = RunningOnServer
- elsif self.components_look_ready? && (!self.state || self.state == New)
+ if self.components_look_ready? && (!self.state || self.state == New)
self.state = Ready
end
- end
end
end
test "check active and success for a pipeline in new state" do
pi = pipeline_instances :new_pipeline
- assert !pi.active, 'expected active to be false for :new_pipeline'
- assert !pi.success, 'expected success to be false for :new_pipeline'
assert_equal 'New', pi.state, 'expected state to be New for :new_pipeline'
# save the pipeline and expect state to be New
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::New, pi.state, 'expected state to be New for new pipeline'
- assert !pi.active, 'expected active to be false for a new pipeline'
- assert !pi.success, 'expected success to be false for a new pipeline'
end
test "check active and success for a newly created pipeline" do
pi.save
assert pi.valid?, 'expected newly created empty pipeline to be valid ' + pi.errors.messages.to_s
- assert !pi.active, 'expected active to be false for a new pipeline'
- assert !pi.success, 'expected success to be false for a new pipeline'
assert_equal 'Ready', pi.state, 'expected state to be Ready for a new empty pipeline'
end
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
assert_equal pi.components.size, 1, 'expected one component'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
# add a component with no input not required
component = {'script_parameters' => {"input_not_provided" => {"required" => false}}}
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
assert_equal pi.components.size, 1, 'expected one component'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
# add a component with input and expect state to become Ready
component = {'script_parameters' => {"input" => "yyyad4b39ca5a924e481008009d94e32+210"}}
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
assert_equal pi.components.size, 1, 'expected one component'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
-
- pi.active = true
- assert_equal true, pi.save, 'expected pipeline instance to save, but ' + pi.errors.messages.to_s
- pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
- assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating active to true'
- assert pi.active, 'expected active to be true after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
-
- pi.success = false
- pi.save
- pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
- assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating success to false'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
pi.state = PipelineInstance::RunningOnServer
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating state to RunningOnServer'
- assert pi.active, 'expected active to be true after update'
- assert !pi.success, 'expected success to be alse after update'
pi.state = PipelineInstance::Paused
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Paused, pi.state, 'expected state to be Paused after updating state to Paused'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false after update'
pi.state = PipelineInstance::Complete
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating state to Complete'
- assert !pi.active, 'expected active to be false after update'
- assert pi.success, 'expected success to be true after update'
pi.state = 'bogus'
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Complete, pi.state, 'expected state to be unchanged with set to a bogus value'
- assert !pi.active, 'expected active to be false after update'
- assert pi.success, 'expected success to be true after update'
pi.state = PipelineInstance::Failed
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating state to Failed'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false after update'
end
test "update attributes for pipeline with two components" do
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
assert_equal pi.components.size, 2, 'expected two components'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
end
[:has_component_with_no_script_parameters,
pi = pipeline_instances pi_name
Thread.current[:user] = users(:active)
- # Make sure we go through the "active_changed? and active" code:
- assert_equal true, pi.update_attributes(active: true), pi.errors.messages
- assert_equal true, pi.update_attributes(active: false), pi.errors.messages
- assert_equal PipelineInstance::Paused, pi.state
+ assert_equal PipelineInstance::Ready, pi.state
end
end
end