Skip to content

Commit

Permalink
Notify DEA for deleted routes
Browse files Browse the repository at this point in the history
Change-Id: I0c0cd3b80235ca75c98c9b5c7d9d3d29a7f90b9d
  • Loading branch information
Bob Nugmanov and Dmitriy Kalinin committed Jan 28, 2013
1 parent 9662d15 commit 959fa58
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
5 changes: 4 additions & 1 deletion lib/cloud_controller/models/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 13 additions & 4 deletions lib/cloud_controller/models/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,14 +89,20 @@ def self.user_visibility_filter(user)

private

def around_destroy

This comment has been minimized.

Copy link
@d

d Feb 1, 2013

Contributor

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
40 changes: 39 additions & 1 deletion spec/models/route_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ module VCAP::CloudController
end
end


describe "instance methods" do
let(:space) { Models::Space.make }

Expand Down Expand Up @@ -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.