caf_platform/plug_nodes

A plug to manage available nodes, i.e., node.js processes, that run your application.

A node is identified by a hostname:port string, where the hostname is a publicly visible address or DNS name. The port may be used as a network port, or encoded in the actual external address.

In many cloud deployments, public addresses are NATed to an internal IP address, and it is more efficient to use internal addresses for communication between co-located services and nodes.

For this reason, we add the notion of a private node identifier, that uses a non-externally routable IP address/port.

This plug caches the public to private name bindings for all nodes, and exposes them using a $ context.

It also self-registers at boot time with a naming service (e.g., Redis), using its own local name, and obtaining a public name in response. This binding is implemented with a lease, and this plug will continously renew it while still alive.

Properties:

{stealthMode: boolean, nodesService: string, leaseTimeout: number,
 allPublicNodeIds: {publicHostname: string, publicRangeStart: number,
                    publicRangeEnd: number} | null}

where:

  • stealthMode: whether this node should not register (mostly for debugging or network proxies).
  • nodesService: backend service for managing nodes, e.g., cp.
  • leaseTimeout: time in seconds before the node lease expires.
  • allPublicNodeIds: recipe to enumerate available public identifiers for nodes. In stealth mode it can be null.
Source:

Extends

Members

$ :Object.<string, string>

Source:

Public to private bindings of known nodes.

Type:
  • Object.<string, string>

Methods

__ca_pulse__(cb0)

Source:

Entry method for a cron to periodically trigger node lease renewal, and also refresh node bindings.

Parameters:
Name Type Description
cb0 cbType

A callback to notify when done.

getAllPublicNodeIds() → {Array.<string>|null}

Source:

Gets the public indentifiers of all checked nodes.

The status of these nodes is in that.$ when detected.

Returns:

All the public identifiers of checked nodes. A null value means all found nodes will be included.

Type
Array.<string> | null

getNodeId() → {string}

Source:

Gets a public unique identifier for the current node.js process.

Identifiers are of the form hostname:port where hostname is a public IP address or DNS name.

Returns:

An identifier for the current node.js process.

Type
string

getPrivateNodeId() → {string}

Source:

Gets a private unique identifier for the current node.js process.

Identifiers are of the form hostname:port where hostname is a private IP address or DNS name.

Many cloud deployments NAT a public address to a private one, and performance improves if private addresses are used within the data center.

Returns:

A private identifier for the current node.js process.

Type
string

getVersion() → {number}

Source:

Gets a version number reflecting the state of public to private node bindings.

Returns:

A version number for the current node bindings.

Type
number

onChange(clientF, closeFopt)

Source:

Register for notifications of node binding changes.

Parameters:
Name Type Attributes Description
clientF function

A callback of type function(number):void called when bindings change with a new version number.

closeF function <optional>

An optional callback called when no more notifications will be issued.