Narcissistic, Perfectly Modest

    apiconnect-collective-jmx

    1.3.1 • Public • Published

    apiconnect-collective-jmx

    Overview

    The apiconnect-collective-jmx library provides helper functions for communicating with a WAS Liberty Collective, as well as JMX encoding tools to allow creation of custom JMX messages.

    Usage

    Install by running npm i --save apiconnect-collective-jmx.

    Pre-defined Modules

    This toolkit comes with a collection of modules and functions for performing operations against a collective.

    Example

    var jmx = require('apiconnect-collective-jmx');
    var path = require('path');
    var payload = jmx.collective.registerHost({
      rpcHost: 'someHost',
      rpcUser: 'someUser',
      sshPrivateKey: path.resolve('path', 'to', 'key_rsa');
    });

    For a full list, see the API Reference.

    Make your own JMX requests

    If there are no helper libraries defined for the JMX calls you'd like to make, then you have the option of defining your own using the same common modules used throughout this toolkit.

    Simple Example

    Using the Encoder, Payload and Endpoint objects, you can construct a JMX payload with the Encoder, target the REST resource with the Payload and then send the request to a specific server with Endpoint!

    var jmx = require('apiconnect-collective-jmx');
    var Encoder = jmx.Encoder;
    var Payload = jmx.Payload;
    var Endpoint = jmx.Endpoint;
    var url = require('url');
     
    // Make an encoder instance.
    var encoder = new Encoder();
     
    // Add parameters in order!
    // Pretend we're calling an endpoint that takes a title (string), a size (int)
    // and whether or not it's available (boolean).
    encoder.addString('foo');
    encoder.addNumber(2);
    encoder.addBoolean(true);
    // Send a JMX payload to {host:port}/targetResource!
    var payload = new Payload('/targetResource', 'POST', encoder.encodeJson());
     
    // Can also take a 3rd options param!
    var controller = new Endpoint('localhost', '9443');
     
    // Give it the payload, options and a callback!
    controller.request(payload, {}, function(err, response) {
      if (err) console.error('oh noes!');
      else {
        console.log('Made a new widget!');
        console.log(response);
      }
    });
     

    Advanced Usage

    Types

    Here are the Java types available on the Encoder's types object:

    • JavaObject (java.lang.Object)
    • String (java.lang.String)
    • Integer (java.lang.Integer)
    • Double (java.lang.Double)
    • Boolean (java.lang.Boolean)
    • HashMap (java.util.HashMap)
    • ArrayList (java.util.ArrayList)

    Using these static type definitions will simplify your usage, and help avoid typos within Java types on your payloads. See the examples below for usage of the Encoder.types collection.

    Add an Array

    var names = ['foo', 'bar' ];
    var encoder = new Encoder();
    encoder.addArray(names, encoder.types.String);

    Add a Map

    var map = {
      'foo': 2,
      'bar': 3,
    };
    var encoder = new Encoder();
    encoder.addMap(map, encoder.types.String, encoder.types.Integer);

    Add a Custom Value

    Using the encoder doesn't limit you to the predefined types! In fact, you can create your own custom entries with the addSimpleValue function.

    If you know the expected Java type at the target API level, you can specify it as a string!

    var widgetInstance = getMagicWidget();
    var encoder = new Encoder();
     
    encoder.addSimpleValue(widgetInstance, 'com.foobar.Widget', 'java.lang.Object');

    API Reference

    Modules

    apiconnect-collective-jmx

    Classes

    Collective
    Encoder
    Endpoint
    Payload
    RouterClient
    Types

    apiconnect-collective-jmx

    Collective

    Kind: global class

    new Collective()

    Operations for registering and unregistering host machines, as well as joining and removing applications from a collective.

    Collective.COLLECTIVE_REGISTRATION_MBEAN

    The path string for collective registration operations on a Liberty JMX collective controller.

    Kind: static property of Collective

    Collective.Join(options)

    Generates the JMX command to join a member server to a collective.

    Kind: static method of Collective

    Param Type Description
    options object The options object.
    options.hostName string The hostname of the member.
    options.wlpUserDir string The path on the host to the 'usr' folder that contains the member.
    options.serverName string The name of the member to join to the collective.
    options.wlpInstallDir string The directory of the wlp installation.
    options.keystorePassword string The password for the certificates generated as a part of the collective join operation.
    [options.certProperties] object An options object for changing the behaviours of certificate generation.
    options.hostAuthInfo object An options object for defining properties used by the collective to remotely access the host machine of the member.
    [options.rpcHost] string The Host address of the remote server
    [options.rpcUser] string The username of an account
    [options.rpcUserHome] string The UserHome directory of rpcUser that can run RPC commands against the host. Does not apply if SSH is used.
    [options.rpcPort] string The RPC port of the member host. Does not apply if SSH is used.
    [options.rpcUserPassword] string The password for the user account running RPC commands. Does not apply if SSH is used.
    [options.hostAuthInfo.sudoUser] string On systems where "sudo" is available, this will be the username of a sudoer for elevating SSH commands. Only applies to SSH.
    [options.sudoPassword] string The password for the sudoer. Only applies to SSH.
    [options.sshPublicKeyPath] string The path to the SSH public key.
    [options.sshPrivateKeyPath] string The path to the SSH private key.
    [options.sshPrivateKeyPassword] string The password for the SSH private key.
    [options.useHostCredentials] boolean Tells the member to inherit its credentials configuration from the host's configuration (requires the host to already have been registered with the collective).
    [options.hostReadList] Array The list of locations on the host with allowed read access.
    [options.hostWriteList] Array The list of locations on the host with allowed write access.

    Collective.Remove(options)

    Generates the JMX command to remove a member server from a collective.

    Kind: static method of Collective

    Param Type Description
    options object The options object.
    options.hostName string The hostname of the member.
    options.wlpUserDir string The path on the host to the 'usr' folder that contains the member.
    options.serverName string The name of the member to join to the collective.

    Collective.registerHost(options)

    Generates the JMX command to register a host in a collective.

    Kind: static method of Collective

    Param Type Description
    options object The options object.
    options.hostName string The hostname of the member.
    [options.rpcHost] string The Host address of the remote server
    [options.rpcUser] string The username of an account
    [options.rpcUserHome] string The UserHome directory of rpcUser that can run RPC commands against the host. Does not apply if SSH is used.
    [options.rpcPort] string The RPC port of the member host. Does not apply if SSH is used.
    [options.rpcUserPassword] string The password for the user account running RPC commands. Does not apply if SSH is used. * @param {string=} options.sshPrivateKeyPath - The path to the SSH private key.
    [options.sshPrivateKeyPassword] string The password for the SSH private key.

    Collective.unregisterHost(options)

    Generates the JMX command to unregister a host.

    Kind: static method of Collective

    Param Type Description
    options object The options object.
    options.hostName string The hostname of the member.

    Collective.updateHost(options)

    Generates the JMX command to update a host info.

    Kind: static method of Collective

    Param Type Description
    options object The options object.
    options.hostName string The hostname of the member.
    [options.rpcHost] string The Host address of the remote server
    [options.rpcUser] string The username of an account
    [options.rpcUserHome] string The UserHome directory of rpcUser that can run RPC commands against the host. Does not apply if SSH is used.
    [options.rpcPort] string The RPC port of the member host. Does not apply if SSH is used.
    [options.rpcUserPassword] string The password for the user account running RPC commands. Does not apply if SSH is used. * @param {string=} options.sshPrivateKeyPath - The path to the SSH private key.
    [options.sshPrivateKeyPassword] string The password for the SSH private key.

    Encoder

    Kind: global class

    encoder.clearPayload()

    Clear the payload contained within the JMX object (if you want to reuse it).

    Kind: instance method of Encoder

    encoder.encodeJson() ⇒ Object | * | Object

    Prepare a JMX object in JSON based on the existing payload in this object.

    Kind: instance method of Encoder

    encoder.addBoolean(val)

    Add a boolean to the JMX payload.

    Kind: instance method of Encoder

    Param Type
    val boolean

    encoder.addString(val)

    Add a string to the JMX payload.

    Kind: instance method of Encoder

    Param Type
    val string

    encoder.addInteger(val)

    Add an integer to the JMX payload.

    Kind: instance method of Encoder

    Param Type
    val number

    encoder.addDouble(val)

    Add a double to the JMX payload.

    Kind: instance method of Encoder

    Param Type
    val number

    encoder.addList(arr, type)

    Add a list to the JMX object (Java's ArrayList in JSON form).

    Kind: instance method of Encoder

    Param Description
    arr The array of objects to add to the payload. All items must be of the same type!
    type The Java data-type of the values within the array.

    encoder.addArray(arr, type)

    Add an array to the JMX object (different than List/ArrayList, requires special string annotations for type).

    Kind: instance method of Encoder

    Param Description
    arr The array of objects to add to the payload. All items must be of the same type!
    type The Java data-type of the values within the array.

    encoder.addMap(map, keyType, valueType, [isComplexKey])

    Add a Map (HashMap) to the JMX payload.

    Kind: instance method of Encoder

    Param Type Default Description
    map * The JSON object that acts as your map.
    keyType string The Java type of the keys.
    valueType string The Java type of the values.
    [isComplexKey] boolean false Whether or not the Java data type of the keys are complex or simple. Defaults to false (simple).

    encoder.addEntryToMap(hashMap, value, key, keyType, valueType, [isComplexKey])

    Add a Map (HashMap) to the JMX payload.

    Kind: instance method of Encoder

    Param Type Default Description
    hashMap * The JSON object that acts as your map.
    value string The value to be put in the map
    key string The key for the value in the map
    keyType string The Java type of the keys.
    valueType string The Java type of the values.
    [isComplexKey] boolean false Whether or not the Java data type of the keys are complex or simple. Defaults to false (simple).

    encoder.addSimpleValue(val, type, [baseType])

    Add a simple value to the JMX payload; does not support complex data types!

    Kind: instance method of Encoder

    Param Type Description
    val * The value to insert into the payload.
    type string The Java data-type of the value.
    [baseType] string The baseType of the object (only added to signature!)

    Encoder.types

    The list of pre-defined Java types available for use in JMX payloads.

    Kind: static property of Encoder
    See: Types

    Endpoint

    Kind: global class
    Properties

    Name Type Description
    options.acceptUnauthorized string Accept unauthorized HTTPS certificates if the server uses them. Common during initial join.
    options.checkServerIdentity string Whether to verify that server's hostname matches the CN in the TLS certificate. Defaults to true.
    options.ca string A PEM encoded CA certificate to trust as as an HTTPS certificate issuer.
    options.username string The username used for Basic auth with the endpoint.
    options.password string The password used for Basic auth with the endpoint.
    options.pfx string The client identity.
    options.pfxPassphrase string The pfx passphrase.
    options.request function Inject a request function compatible with the request module (useful for faking calls to a remote target).

    new Endpoint(host, port, [options])

    Represents a target server and resource to submit requests against.

    Param Type Description
    host string The IP address of the host.
    port number | string The port to connect to.
    [options] object Additional options for function overrides and for request-specific configuration vars.

    endpoint.request(payload, options, cb)

    Submit JMX requests to target endpoint.

    Kind: instance method of Endpoint

    Param Type Description
    payload Payload The JMX payload to submit to the endpoint.
    options object The options object.
    cb function Handle the server's response.

    Payload

    Kind: global class

    new Payload(path, verb, data, [qs])

    Param Type Description
    path string The path to the resource.
    verb string The REST verb of the request.
    data object The JMX body of the request. Must be a JSON object, not a string!
    [qs] string An optional query string to apply to the payload.

    RouterClient

    Kind: global class

    new RouterClient()

    JMX operations for configuring application and endpoint routing information.

    RouterClient.SetApplicationRoutingInfo(options, operation)

    Sets the application routing information. The application routing info is the address which is mapped to the user application. This URL includes context root, as well as virtual host address and vHost port. The router client redirects the request to this application if it finds the requested url the address which is set by this method.

    Kind: static method of RouterClient

    Param Type Description
    options object The options object.
    options.host string The host on which the server is running.
    options.userDir string The user directory in which the server is set up.
    options.server string The server name associated to the server.
    options.applicationName string The application name.
    options.contextRoot string The context root if routing by context root (the value is / if not).
    options.vHost string The virtual host address if routing by virtual host (the value is * unless otherwise).
    options.vHostPort string The virtual host port if routing by virtual host (the value is * unless otherwise)
    operation string The operation to set/delete/create a value in the collective repository of the controller.

    RouterClient.SetApplicationState(options, operation)

    Sets the application routing information. The application routing info is the address which is mapped to the user application. This URL includes context root, as well as virtual host address and vHost port. The router client redirects the request to this application if it finds the requested url the address which is set by this method.

    Kind: static method of RouterClient

    Param Type Description
    options object The options object.
    options.host string The host on which the server is running.
    options.userDir string The user directory in which the server is set up.
    options.server string The server name associated to the server.
    options.applicationName string The application name.
    operation string The operation to set/delete/create a value in the collective repository of the controller.

    RouterClient.SetEndPointRoutingInfo(options, operation)

    Sets the end point routing information. This information includes the address and port that application is running. There are 12 attributes values which are sent to the controller. these attributes are defined in enum called attributes which includes host, workport, etc.

    Kind: static method of RouterClient

    Param Type Description
    options object The options object.
    options.host string The host on which the server is running.
    options.userDir string The user directory in which the server is set up.
    options.server string The server name associated to the server.
    options.attribute string The attribute type to be set.
    options.attributeValue string The attribute value to be set.
    operation string The operation to set/delete/create a value in the collective repository of the controller.

    Types

    Kind: global class

    Types.ArrayList

    A resizable array implemention of Java's List interface. https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

    Kind: static property of Types

    Types.Boolean

    A single-bit representation of a truth value, either being "true" or "false". https://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html

    Kind: static property of Types

    Types.HashMap

    A hash-table based implementation of the Map interface. https://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html

    Kind: static property of Types

    Types.Integer

    A number without decimal places. https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html

    Kind: static property of Types

    Types.JavaObject

    The base class for all other classes in the class hierarchy. https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html

    Kind: static property of Types

    Types.String

    An immutable array of alphanumeric characters. https://docs.oracle.com/javase/7/docs/api/java/lang/String.html

    Kind: static property of Types

    Keywords

    none

    Install

    npm i apiconnect-collective-jmx

    DownloadsWeekly Downloads

    229

    Version

    1.3.1

    License

    SEE LICENSE IN LICENSE.txt

    Unpacked Size

    12.6 MB

    Total Files

    25

    Last publish

    Collaborators

    • jisoolee
    • dhmlau
    • ritch
    • johnbellessa
    • chrisdudley
    • redlanne
    • scheu
    • sanchit.chadha