Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Support registering apps with nil tags
Browse files Browse the repository at this point in the history
If an app is registered without providing tags, the droplet will be
saved successfully, but when the app is looked up, ULS will generate
a response nginx cannot deal with, which leads to an internal error.

This change makes ULS tolerant of register message without tags.

Change-Id: I053f98c76d5454a4022094828c1d33d64afa33be
  • Loading branch information
Anfernee Gui committed Sep 27, 2012
1 parent 8a3d41b commit 346867c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/router/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def lookup_droplet(url)
def register_droplet(url, host, port, tags, app_id)
return unless host && port
url.downcase!
tags ||= {}

droplets = @droplets[url] || []
# Skip the ones we already know about..
droplets.each { |droplet|
Expand All @@ -180,7 +182,7 @@ def register_droplet(url, host, port, tags, app_id)
return
end
}
tags.delete_if { |key, value| key.nil? || value.nil? } if tags
tags.delete_if { |key, value| key.nil? || value.nil? }
droplet = {
:app => app_id,
:host => host,
Expand All @@ -191,7 +193,7 @@ def register_droplet(url, host, port, tags, app_id)
:requests => 0,
:tags => tags
}
add_tag_metrics(tags) if tags
add_tag_metrics(tags)
droplets << droplet
@droplets[url] = droplets
VCAP::Component.varz[:urls] = @droplets.size
Expand Down
2 changes: 1 addition & 1 deletion lib/router/router_uls_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ParserError < StandardError; end
# Get session cookie for droplet
new_sticky = Router.get_session_cookie(droplet)

uls_req_tags = Base64.encode64(Marshal.dump(droplet[:tags])).strip if droplet[:tags]
uls_req_tags = Base64.encode64(Marshal.dump(droplet[:tags])).strip
uls_response = {
ULS_STICKY_SESSION => new_sticky,
ULS_BACKEND_ADDR => "#{droplet[:host]}:#{droplet[:port]}",
Expand Down
13 changes: 13 additions & 0 deletions spec/unit/router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ def setup
VCAP::Component.varz[:urls].should == 1
end

it 'should register a droplet with nil tags' do
Router.register_droplet('foo.vcap.me', '10.0.1.22', 2222, nil, 123)
VCAP::Component.varz[:droplets].should == 1
VCAP::Component.varz[:urls].should == 1

droplets = Router.lookup_droplet('foo.vcap.me')
droplet = droplets.first
droplet.should have_key :tags
droplet[:tags].should == {}
end

it 'should allow proper lookup' do
Router.register_droplet('foo.vcap.me', '10.0.1.22', 2222, {}, 123)
droplets = Router.lookup_droplet('foo.vcap.me')
Expand All @@ -49,11 +60,13 @@ def setup
droplet.should have_key :host
droplet.should have_key :port
droplet.should have_key :clients
droplet.should have_key :tags
droplet[:requests].should == 0
droplet[:url].should == 'foo.vcap.me'
droplet[:host].should == '10.0.1.22'
droplet[:port].should == 2222
droplet[:clients].should == {}
droplet[:tags].should == {}
end

it 'should allow looking up uppercase uri' do
Expand Down

0 comments on commit 346867c

Please sign in to comment.