Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds the following message bus behaviors: - Component announcement / registration - router registration and re-registration Also included is a patch addressing the incompatibility introduced by Yajl's JSON gem ``compatibility'' layer. Ironies abound. Test plan: - Unit tests passed - Deploy to dev instance and ad-hock test http end points on both the CCNG domain and API2 domain. Change-Id: Icc1038e990523065883b4c281920da4b2668f03d
- Loading branch information
Showing
5 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) 2012-2012 VMware, Inc. | ||
|
||
# FIXME: this is so gross | ||
# Monkey-patching the monkeypatch: UAA gem is unhappy because yajl/json_gem | ||
# ignores symbolize_names | ||
# The UAA client gem should probably move to Yajl... | ||
def JSON.parse(str, opts=JSON.default_options) | ||
if opts.delete(:symbolize_names) | ||
opts[:symbolize_keys] = true | ||
end | ||
Yajl::Parser.parse(str, opts) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) 2012-2012 VMware, Inc. | ||
|
||
require "nats/client" | ||
require "vcap/component" | ||
require "cloud_controller/json_patch" | ||
|
||
module VCAP::CloudController::MessageBus | ||
class << self | ||
attr_reader :config | ||
attr_reader :nats | ||
|
||
def configure(config) | ||
@config = config | ||
@nats = config[:nats] || NATS | ||
end | ||
end | ||
|
||
def self.register_components | ||
# hook up with NATS | ||
# TODO: put useful metrics in varz | ||
# TODO: subscribe to the two DEA channels | ||
EM.schedule do | ||
nats.start(:uri => config[:nats_uri]) do | ||
VCAP::Component.register( | ||
:type => 'CloudController', | ||
:host => VCAP.local_ip, | ||
:index => config[:index], | ||
:config => config, | ||
# leaving the varz port / user / pwd blank to be random | ||
) | ||
end | ||
end | ||
end | ||
|
||
def self.register_routes | ||
EM.schedule do | ||
# TODO: blacklist api2 in legacy CC | ||
# TODO: Yajl should probably also be injected | ||
router_register_message = Yajl::Encoder.encode({ | ||
:host => VCAP.local_ip, | ||
:port => config[:port], | ||
:uris => [config[:external_domain]], | ||
:tags => {:component => "CloudController" }, | ||
}) | ||
nats.publish("router.register", router_register_message) | ||
# Broadcast when a router restarts | ||
nats.subscribe("router.start") do | ||
nats.publish("router.register", router_register_message) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters