---
src/app/models/deployment.rb | 16 +++++++++++++---
src/app/models/event.rb | 10 ++++++++--
src/app/models/instance.rb | 4 +++-
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 1a11e71..12f4f93 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -36,6 +36,8 @@ require 'util/deployable_xml'
require 'util/config_server_util'
class Deployment < ActiveRecord::Base
+ acts_as_paranoid
+
include PermissionedObject
class << self
include CommonFilterMethods
@@ -69,7 +71,7 @@ class Deployment < ActiveRecord::Base
before_validation :replace_special_characters_in_name
validates_presence_of :pool_id
validates_presence_of :name
- validates_uniqueness_of :name, :scope => :pool_id
+ validates_uniqueness_of :name, :scope => [:pool_id, :deleted_at]
validates_length_of :name, :maximum => 50
validates_presence_of :owner_id
validate :pool_must_be_enabled
@@ -303,12 +305,20 @@ class Deployment < ActiveRecord::Base
end
def provider
- inst = instances.joins(:provider_account => :provider).first
+ if deleted?
+ inst = instances.unscoped.joins(:provider_account => :provider).first
+ else
+ inst = instances.joins(:provider_account => :provider).first
+ end
inst && inst.provider_account && inst.provider_account.provider
end
def provider_account
- inst = instances.joins(:provider_account).first
+ if deleted?
+ inst = instances.unscoped.joins(:provider_account).first
+ else
+ inst = instances.joins(:provider_account).first
+ end
inst && inst.provider_account
end
diff --git a/src/app/models/event.rb b/src/app/models/event.rb
index a4d99d6..58fd488 100644
--- a/src/app/models/event.rb
+++ b/src/app/models/event.rb
@@ -34,6 +34,8 @@
# Likewise, all the methods added will be available for all controllers.
class Event < ActiveRecord::Base
+ acts_as_paranoid
+
require "#{Rails.root}/lib/aeolus/event.rb"
belongs_to :source, :polymorphic => true
@@ -46,6 +48,10 @@ class Event < ActiveRecord::Base
scope :lifetime, where(:status_code => [:first_running, :all_running, :some_running,
:all_stopped])
scope :descending_by_created_at, order('created_at DESC')
+ def self.all
+ self.unscoped
+ end
+
# Notifies the Event API if certain conditions are met
def transmit_event
# Extract just the old values from change_hash
@@ -57,7 +63,7 @@ class Event < ActiveRecord::Base
when "Instance"
if ['running', 'stopped'].include?(status_code)
# If we look this up through the 'source' association, we end up with it
being a stale object.
- instance = Instance.find(source_id)
+ instance = Instance.unscoped.find(source_id)
# If we have a time_last_running, use it; otherwise, we just started and it's
not populated yet
start_time = instance.time_last_running || Time.now
terminate_time = status_code == 'stopped' ? instance.time_last_stopped :
nil
@@ -88,7 +94,7 @@ class Event < ActiveRecord::Base
# There is also a "summary" attribute on state changes, but we don't
appear to need to check it
when "Deployment"
if ['some_stopped', 'first_running', 'all_stopped',
'all_running'].include?(status_code)
- deployment = Deployment.find(source_id)
+ deployment = Deployment.unscoped.find(source_id)
begin
# TODO - The Cddr method supports a :deployable_id, but we don't implement
this at the moment
e = Aeolus::Event::Cddr.new({
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 8258118..a23503f 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -61,6 +61,8 @@ require 'util/deployable_xml'
require 'util/instance_config_xml'
class Instance < ActiveRecord::Base
+ acts_as_paranoid
+
class << self
include CommonFilterMethods
end
@@ -98,7 +100,7 @@ class Instance < ActiveRecord::Base
#validates_uniqueness_of :external_key, :scope => :provider_id
validates_presence_of :name
- validates_uniqueness_of :name, :scope => :pool_id
+ validates_uniqueness_of :name, :scope => [:pool_id, :deleted_at]
validates_length_of :name, :maximum => 1024
before_create :generate_uuid
--
1.7.6.5