Permalink
Browse files

Notify DEA for deleted routes

Change-Id: I0c0cd3b80235ca75c98c9b5c7d9d3d29a7f90b9d
  • Loading branch information...
1 parent 9662d15 commit 959fa5819127b78d5ed7fbfe0658a8f926056608 Bob Nugmanov and Dmitriy Kalinin committed Jan 28, 2013
Showing with 56 additions and 6 deletions.
  1. +4 −1 lib/cloud_controller/models/app.rb
  2. +13 −4 lib/cloud_controller/models/route.rb
  3. +39 −1 spec/models/route_spec.rb
@@ -10,7 +10,10 @@ class InvalidBindingRelation < InvalidRelation; end
many_to_one :space
many_to_one :framework
many_to_one :runtime
- many_to_many :routes, :before_add => :validate_route, :after_add => :mark_routes_changed, :after_remove => :mark_routes_changed
+ many_to_many :routes,
+ :before_add => :validate_route,
+ :after_add => :mark_routes_changed,
+ :after_remove => :mark_routes_changed
one_to_many :service_bindings, :after_remove => :after_remove_binding
many_to_many :service_instances, :join_table => :service_bindings
@@ -10,7 +10,10 @@ class InvalidAppRelation < InvalidRelation; end
many_to_one :domain
many_to_one :space
- many_to_many :apps, :before_add => :validate_app, :after_add => :mark_app_routes_changed, :after_remove => :mark_app_routes_changed
+ many_to_many :apps,
+ :before_add => :validate_app,
+ :after_add => :mark_app_routes_changed,
+ :after_remove => :mark_app_routes_changed
add_association_dependencies :apps => :nullify
export_attributes :host, :domain_guid, :space_guid
@@ -86,14 +89,20 @@ def self.user_visibility_filter(user)
private
+ def around_destroy
@d
d Feb 1, 2013 Cloud Foundry member

This looks bad... We should do it in before_destroy

+ loaded_apps = apps
+ super
+
+ loaded_apps.each do |app|
+ mark_app_routes_changed(app)
+ end
+ end
+
def mark_app_routes_changed(app)
app.routes_changed = true
- # I hate putting this in the model, but let's get this feature shippped
- # TODO: use event emitter to decouple this from the model
if app.dea_update_pending?
VCAP::CloudController::DeaClient.update_uris(app)
end
end
-
end
end
@@ -133,7 +133,6 @@ module VCAP::CloudController
end
end
-
describe "instance methods" do
let(:space) { Models::Space.make }
@@ -232,5 +231,44 @@ module VCAP::CloudController
}.to raise_error Sequel::ValidationFailed
end
end
+
+ describe "#remove" do
+ let!(:route) { Models::Route.make }
+ let!(:app_1) do
+ Models::App.make({
+ :space => route.space,
+ :route_guids => [route.guid]
+ }.merge(app_attributes))
+ end
+
+ context "when app is running and staged" do
+ let(:app_attributes) { {:state => "STARTED", :package_state => "STAGED"} }
+
+ it "notifies DEAs of route change for running apps" do
+ VCAP::CloudController::DeaClient.should_receive(:update_uris).with(app_1)
+ Models::Route[:guid => route.guid].destroy
+ end
+ end
+
+ context "when app is not staged and running" do
+ let(:app_attributes) { {:state => "STARTED", :package_state => "FAILED"} }
+
+ it "does not notify DEAs of route change for apps that are not started" do
+ Models::App.make(:space => route.space, :state => "STOPPED", :route_guids => [route.guid])
+ VCAP::CloudController::DeaClient.should_not_receive(:update_uris)
+ Models::Route[:guid => route.guid].destroy
+ end
+ end
+
+ context "when app is staged but not running" do
+ let(:app_attributes) { {:state => "STOPPED", :package_state => "STAGED"} }
+
+ it "does not notify DEAs of route change for apps that are not staged" do
+ Models::App.make(:space => route.space, :package_state => "FAILED", :route_guids => [route.guid])
+ VCAP::CloudController::DeaClient.should_not_receive(:update_uris)
+ Models::Route[:guid => route.guid].destroy
+ end
+ end
+ end
end
end

0 comments on commit 959fa58

Please sign in to comment.