Class: Cf::Registrar
- Inherits:
-
Object
- Object
- Cf::Registrar
- Defined in:
- lib/cf/registrar.rb
Constant Summary collapse
- DISCOVER_TOPIC =
"vcap.component.discover"
- ANNOUNCE_TOPIC =
"vcap.component.announce"
- ROUTER_START_TOPIC =
"router.start"
- ROUTER_GREET_TOPIC =
"router.greet"
- ROUTER_REGISTER_TOPIC =
"router.register"
- ROUTER_UNREGISTER_TOPIC =
"router.unregister"
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#message_bus_servers ⇒ Object
readonly
Returns the value of attribute message_bus_servers.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#private_instance_id ⇒ Object
readonly
Returns the value of attribute private_instance_id.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
-
#initialize(config) ⇒ Registrar
constructor
A new instance of Registrar.
- #register_varz_credentials ⇒ Object
- #register_with_router ⇒ Object
- #shutdown(&block) ⇒ Object
Constructor Details
#initialize(config) ⇒ Registrar
Returns a new instance of Registrar.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cf/registrar.rb', line 18 def initialize(config) @logger = Steno.logger("cf.registrar") config = symbolize_keys(config) @message_bus_servers = config[:message_bus_servers] @host = config[:host] @port = config[:port] @uri = config[:uri] @tags = config[:tags] @index = config[:index] || 0 @private_instance_id = config[:private_instance_id] if config[:varz] @type = config[:varz][:type] @username = config[:varz][:username] @password = config[:varz][:password] @uuid = config[:varz][:uuid] || SecureRandom.uuid end end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def host @host end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def index @index end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def logger @logger end |
#message_bus_servers ⇒ Object (readonly)
Returns the value of attribute message_bus_servers.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def @message_bus_servers end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def port @port end |
#private_instance_id ⇒ Object (readonly)
Returns the value of attribute private_instance_id.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def private_instance_id @private_instance_id end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def @tags end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def type @type end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def uri @uri end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def username @username end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
15 16 17 |
# File 'lib/cf/registrar.rb', line 15 def uuid @uuid end |
Instance Method Details
#register_varz_credentials ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cf/registrar.rb', line 39 def register_varz_credentials discover_msg = { :type => type, :host => "#{host}:#{port}", :index => index, :uuid => "#{index}-#{uuid}", :credentials => [username, password] } if username.nil? || password.nil? logger.error("Could not register nil varz credentials") else logger.info("Connected to NATS - varz registration") .subscribe(DISCOVER_TOPIC) do |_, reply| logger.debug("Received #{DISCOVER_TOPIC} publishing #{reply.inspect} #{discover_msg.inspect}") .publish(reply, discover_msg) end logger.info("Announcing start up #{ANNOUNCE_TOPIC}") .publish(ANNOUNCE_TOPIC, discover_msg) end end |
#register_with_router ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cf/registrar.rb', line 63 def register_with_router logger.info("Connected to NATS - router registration") @router_start_sid = .subscribe(ROUTER_START_TOPIC) do || handle_router_greeting() end .request(ROUTER_GREET_TOPIC) do || handle_router_greeting() end end |
#shutdown(&block) ⇒ Object
77 78 79 80 81 |
# File 'lib/cf/registrar.rb', line 77 def shutdown(&block) EM.cancel_timer(@registration_timer) if @registration_timer unsubscribe_from_router_start (&block) end |