Merge branch 'master' into 2903-remove-pi-active-and-success
authorradhika <radhika@curoverse.com>
Fri, 30 May 2014 21:39:44 +0000 (17:39 -0400)
committerradhika <radhika@curoverse.com>
Fri, 30 May 2014 21:39:44 +0000 (17:39 -0400)
services/api/app/controllers/arvados/v1/pipeline_instances_controller.rb
services/api/app/models/pipeline_instance.rb
services/api/app/views/pipeline_instances/index.html.erb
services/api/db/migrate/20140528143351_pipeline_instance_attributes.rb [new file with mode: 0644]
services/api/db/schema.rb
services/api/test/unit/pipeline_instance_test.rb

index 9781caf7e8183f618d33971335ed4d6e38a23ab3..67090e68f23d02395acbc931285a360c6c9951c1 100644 (file)
@@ -2,4 +2,5 @@ class Arvados::V1::PipelineInstancesController < ApplicationController
   accept_attribute_as_json :components_summary, Hash
   accept_attribute_as_json :components, Hash
   accept_attribute_as_json :properties, Hash
+  accept_attribute_as_json :components_summary, Hash
 end
index 7bb814c60d4a902d15a61485952ead0437a96cbe..f83d43660737710e4c75082aeade0baac6b0dc16 100644 (file)
@@ -8,7 +8,7 @@ class PipelineInstance < ArvadosModel
   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
@@ -18,8 +18,6 @@ class PipelineInstance < ArvadosModel
     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
@@ -80,7 +78,7 @@ class PipelineInstance < ArvadosModel
         else
           row << 0.0
           if step['failed']
-            self.success = false
+            self.state = Failed
           end
         end
         row << (step['warehousejob']['id'] rescue nil)
@@ -111,9 +109,9 @@ class PipelineInstance < ArvadosModel
     end
   end
 
-  def update_success
+  def update_status
     if components and progress_ratio == 1.0
-      self.success = true
+      self.state = Complete
     end
   end
 
@@ -144,60 +142,9 @@ class PipelineInstance < ArvadosModel
   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
@@ -211,13 +158,9 @@ class PipelineInstance < ArvadosModel
   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
index e8cb553daff3508fce09b54b903743ed640c366c..cfadd26cdd28ae473b78bf3cc79f26253e8d9e2d 100644 (file)
 
   <% @objects.each do |o| %>
 
-  <% status = o.success ? 'success' : (o.success == false ? 'failure' : 'pending') %>
+  <% status = (o.state == 'Complete') ? 'success' : ((o.state == 'Failed') ? 'failure' : 'pending') %>
 
   <tr class="pipeline-instance-status pipeline-instance-status-<%= status %>" data-showhide-selector="tr#extra-info-<%= o.uuid %>" style="cursor:pointer">
     <td>
       <%= status %>
     </td><td>
-      <%= o.active ? 'yes' : '-' %>
+      <%= (o.state == 'RunningOnServer') ? 'yes' : '-' %>
     </td><td>
       <%= (o.progress_ratio * 1000).floor / 10 %>
     </td><td>
diff --git a/services/api/db/migrate/20140528143351_pipeline_instance_attributes.rb b/services/api/db/migrate/20140528143351_pipeline_instance_attributes.rb
new file mode 100644 (file)
index 0000000..ed09fd4
--- /dev/null
@@ -0,0 +1,42 @@
+class PipelineInstanceAttributes < ActiveRecord::Migration
+  include CurrentApiClient
+
+  def up
+    if column_exists?(:pipeline_instances, :active)
+      remove_column :pipeline_instances, :active
+    end
+
+    if column_exists?(:pipeline_instances, :success)
+      remove_column :pipeline_instances, :success
+    end
+  end
+
+  def down
+    if !column_exists?(:pipeline_instances, :success)
+      add_column :pipeline_instances, :success, :boolean, :null => true
+    end
+    if !column_exists?(:pipeline_instances, :active)
+      add_column :pipeline_instances, :active, :boolean, :default => false
+    end
+
+    act_as_system_user do
+      PipelineInstance.all.each do |pi|
+        case pi.state
+        when PipelineInstance::New, PipelineInstance::Ready, PipelineInstance::Paused, PipelineInstance::RunningOnClient
+          pi.active = nil
+          pi.success = nil
+        when PipelineInstance::RunningOnServer
+          pi.active = true
+          pi.success = nil
+        when PipelineInstance::Failed
+          pi.active = false
+          pi.success = false
+        when PipelineInstance::Complete
+          pi.active = false
+          pi.success = true
+        end
+        pi.save!
+      end
+    end
+  end
+end
index 26f1bdcc1bc275036df2b8215cb4c954cca88049..b987a4f9adf62cc9820378c0dab433443e9c4054 100644 (file)
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20140527152921) do
+ActiveRecord::Schema.define(:version => 20140528143351) do
 
 
 
@@ -321,16 +321,14 @@ ActiveRecord::Schema.define(:version => 20140527152921) do
   create_table "pipeline_instances", :force => true do |t|
     t.string   "uuid"
     t.string   "owner_uuid"
-    t.datetime "created_at",                                 :null => false
+    t.datetime "created_at",              :null => false
     t.string   "modified_by_client_uuid"
     t.string   "modified_by_user_uuid"
     t.datetime "modified_at"
     t.string   "pipeline_template_uuid"
     t.string   "name"
     t.text     "components"
-    t.boolean  "success"
-    t.boolean  "active",                  :default => false
-    t.datetime "updated_at",                                 :null => false
+    t.datetime "updated_at",              :null => false
     t.text     "properties"
     t.string   "state"
     t.text     "components_summary"
index 0f2c2edad83dc7ff15b561c536c637e040febd6e..93354f8b1edd31d2b332a71cd6d7de28bcc490e6 100644 (file)
@@ -5,8 +5,6 @@ class PipelineInstanceTest < ActiveSupport::TestCase
   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
@@ -15,8 +13,6 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     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
@@ -26,8 +22,6 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     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
 
@@ -44,8 +38,6 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     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}}}
@@ -55,8 +47,6 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     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"}}
@@ -66,57 +56,31 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     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
@@ -135,8 +99,6 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     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,
@@ -145,10 +107,7 @@ class PipelineInstanceTest < ActiveSupport::TestCase
       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