Control

Control

Control

Constructor

new Control(options)

Source:
See:

Establishes a PxGrid Control connection. Generally passed to a PxGrid REST Client session.

Example
const fs = require('fs');
certs = [];
certs.clientCert = fs.readFileSync('./certs/publiccert.cer');
certs.clientKey = fs.readFileSync('./certs/key.pem');
certs.caBundle = fs.readFileSync('./certs/caBundle.cer');

const Pxgrid = require('pxgrid-node');

const pxgridControlOptions = {
  host: 'my-ise-server.domain.com',
  hosts: ['ise01.domain.com', 'ise02.domain.com']
  client: 'my-node-app',
  clientCert: certs.clientCert,
  clientKey: certs.clientKey,
  caBundle: certs.caBundle,
  clientKeyPassword: false,
  secret: '',
  port: '8910',
  verifySSL: false,
  httpTimeout: 3000
}

const pxgrid = new Pxgrid.Control(pxgridControlOptions);
Parameters:
Name Type Description
options Object

Options for the PxGrid Control instance. See examples for more information.

Properties
Name Type Attributes Default Description
host string

The IP or URL of the PxGrid Controller. Deprecated in v1.3.0, please use hosts array.

hosts Object

An array of PxGrid controllers to attempt connecting to. The first successful connection will be used.

port number <optional>

The host port to connect to the PxGrid Controller on.

client string

The desired name of the client for the client.

clientCert Buffer

A byte stream of the client public key certificate file to use.

clientKey Buffer

A byte stream of the client private key file to use.

caBundle Buffer

A byte stream of the CA Bundle used to verify the PxGrid Controller's identity.

verifySSL Boolean <optional>
true

If true, verify server's SSL certificate.

httpTimeout number <optional>
1000

Value, in milliseconds, to consider a server unavailable.

clientKeyPassword string <optional>

The password to unlock the client private key file.

secret string <optional>

The secret to help authenticate a newly registered service.

Methods

activate(accountDescopt, retryIntervalopt, maxRetriesopt, retryAttemptopt) → {Promise}

Source:
See:

Activate your client pxGrid account on the controller.

This needs to happen one time before using your new client, as well as anytime its state changes to PENDING or DISABLED on the controller.

For simplicity, this is handled automatically by Client#connect, but can be done manually, as well.

If the client is not activated, you will fail to interact with pxGrid.

Sometimes, the account will return with a PENDING status which will induce a backoff timer of 60 seconds before retrying. This is normally because the account needs to be activated on the pxGrid Controller (either manually, or automatically). If configured for auto-approval, the activation should work in the next attempt.

Parameters:
Name Type Attributes Default Description
accountDesc string <optional>
'pxgrid-node'

A description for the client you are registering.

retryInterval number <optional>
60000

Retry interval in milliseconds.

maxRetries number <optional>
10

Maximum retries that will be attempted.

retryAttempt number <optional>
1

Which attempt we are on. This is necessary since we use recursion for retries.

Returns:

True if the PxGrid account has been activated on the upstream PxGrid controller.

Type
Promise

autoServiceReregister(serviceId, interval)

Source:
See:

Automatically reregister a service at a given interval. Reregistration will occur 5 seconds prior to provided interval to prevent inadvertent timeouts.

Parameters:
Name Type Description
serviceId string

The ID of the service to reregister.

interval number

Interval to reregister (milliseconds).

getAccessSecret(nodeName) → {Promise}

Source:

Gets the Access Secret for a given node. AccessSecret is a unique secret between a Consumer and Provider pair.

Parameters:
Name Type Description
nodeName string

The node name to get the secret for.

Returns:

Access Secret for node.

Type
Promise

getConfig() → {Object}

Source:

Returns the control configuration.

Returns:

Control configuration.

Type
Object

serviceLookup(serviceName, retryIntervalopt, maxRetriesopt, retryAttemptopt) → {Promise}

Source:

Looks up any nodes publishing the serviceName.

If no nodes are publishing, response is empty. Therefore, if subscribing, your subscription will fail until a publisher is registered for the service/topic.

Will retry every retryInterval if no publishers are registered and activated.

Parameters:
Name Type Attributes Default Description
serviceName string

Name of the service to lookup.

retryInterval number <optional>
30000

Retry interval in milliseconds.

maxRetries number <optional>
10

Maximum retries that will be attempted.

retryAttempt number <optional>
1

Which attempt we are on. This is necessary since we use recursion for retries.

Returns:

Returns a list of nodes providing the specified service, as well as their properties. Empty if no publishers registered.

Type
Promise

serviceRegister(serviceName, properties) → {Promise}

Source:

Register as a publisher to a service. This could be a new service, or an existing service.

Parameters:
Name Type Description
serviceName string

Name of the service to register for.

properties Object

Properties of the service you are registering.

Returns:

The id and reregisterTimeMillis for the newly registered service.

Type
Promise

serviceReregister(serviceId) → {Promise}

Source:
See:

Reregister your node for a service. Services must reregister within the reregisterTimeMillis interval provided when initially registering.

Parameters:
Name Type Description
serviceId string

The ID of the service to reregister.

Returns:

Empty response from controller, if successful.

Type
Promise

serviceUnregister(serviceId) → {Promise}

Source:

Unregisters a service.

Parameters:
Name Type Description
serviceId string

The ID of the service to unregister.

Returns:

Empty response from controller, if successful.

Type
Promise

serviceUnregisterAll()

Source:

Unregisters all services that have been registered by the instance.