Skip to content

Commit c66d671

Browse files
maxmoehlhoffmaen
andauthored
feat: notify diego of route updates (#4298)
* feat: notify diego of route updates After updating a route via the new update route endpoint, it was only stored in the database. Since routes can be changed without restarting the application this commit adds logic to also push the update to diego. Resolves: #4286 Co-Authored-By: Clemens Hoffmann <[email protected]> * Verify call to notify_backend_of_route_update in route.update * Address review comments * Notify diego outside of transaction --------- Co-authored-by: Clemens Hoffmann <[email protected]>
1 parent e4fc02b commit c66d671

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

app/actions/route_update.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ class RouteUpdate
33
def update(route:, message:)
44
Route.db.transaction do
55
route.options = route.options.symbolize_keys.merge(message.options).compact if message.requested?(:options)
6-
76
route.save
87
MetadataUpdate.update(route, message)
98
end
109

10+
if message.requested?(:options)
11+
route.apps.each do |process|
12+
ProcessRouteHandler.new(process).notify_backend_of_route_update
13+
end
14+
end
1115
route
1216
end
1317
end

spec/unit/actions/route_update_spec.rb

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ module VCAP::CloudController
4141
end
4242

4343
let(:message) { RouteUpdateMessage.new(body) }
44-
let(:route) { Route.make }
44+
let(:process) { ProcessModel.make }
45+
let(:route_mapping) { RouteMappingModel.make(app: process.app) }
46+
let(:route) { route_mapping.route }
4547

4648
subject { RouteUpdate.new }
4749
describe '#update metadata' do
50+
before do
51+
expect(ProcessRouteHandler).not_to receive(:new)
52+
end
53+
4854
context 'when the route has no existing metadata' do
4955
context 'when no metadata is specified' do
5056
let(:body) do
@@ -135,6 +141,13 @@ module VCAP::CloudController
135141
end
136142

137143
describe '#update options' do
144+
let(:fake_route_handler) { instance_double(ProcessRouteHandler) }
145+
146+
before do
147+
allow(ProcessRouteHandler).to receive(:new).with(process).and_return(fake_route_handler)
148+
allow(fake_route_handler).to receive(:notify_backend_of_route_update)
149+
end
150+
138151
context 'when the route has no existing options' do
139152
context 'when no options are specified' do
140153
let(:body) do
@@ -147,6 +160,11 @@ module VCAP::CloudController
147160
route.reload
148161
expect(route.options).to eq({})
149162
end
163+
164+
it 'does not notifies the backend' do
165+
expect(fake_route_handler).not_to receive(:notify_backend_of_route_update)
166+
subject.update(route:, message:)
167+
end
150168
end
151169

152170
context 'when an option is specified' do
@@ -161,10 +179,14 @@ module VCAP::CloudController
161179
it 'adds the route option' do
162180
expect(message).to be_valid
163181
subject.update(route:, message:)
164-
165182
route.reload
166183
expect(route[:options]).to eq('{"loadbalancing":"round-robin"}')
167184
end
185+
186+
it 'notifies the backend' do
187+
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
188+
subject.update(route:, message:)
189+
end
168190
end
169191
end
170192

@@ -184,6 +206,11 @@ module VCAP::CloudController
184206
route.reload
185207
expect(route.options).to include({ 'loadbalancing' => 'round-robin' })
186208
end
209+
210+
it 'does not notifies the backend' do
211+
expect(fake_route_handler).not_to receive(:notify_backend_of_route_update)
212+
subject.update(route:, message:)
213+
end
187214
end
188215

189216
context 'when an option is specified' do
@@ -199,9 +226,13 @@ module VCAP::CloudController
199226
expect(message).to be_valid
200227
subject.update(route:, message:)
201228
route.reload
202-
203229
expect(route.options).to include({ 'loadbalancing' => 'least-connection' })
204230
end
231+
232+
it 'notifies the backend' do
233+
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
234+
subject.update(route:, message:)
235+
end
205236
end
206237

207238
context 'when the option value is set to null' do
@@ -219,6 +250,11 @@ module VCAP::CloudController
219250
route.reload
220251
expect(route.options).to eq({})
221252
end
253+
254+
it 'notifies the backend' do
255+
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
256+
subject.update(route:, message:)
257+
end
222258
end
223259
end
224260
end

0 commit comments

Comments
 (0)