1.3.1 • Published 6 years ago

apiconnect-collective-jmx v1.3.1

Weekly downloads
411
License
SEE LICENSE IN LI...
Repository
-
Last release
6 years ago

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

Classes

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

ParamTypeDescription
optionsobjectThe options object.
options.hostNamestringThe hostname of the member.
options.wlpUserDirstringThe path on the host to the 'usr' folder that contains the member.
options.serverNamestringThe name of the member to join to the collective.
options.wlpInstallDirstringThe directory of the wlp installation.
options.keystorePasswordstringThe password for the certificates generated as a part of the collective join operation.
options.certPropertiesobjectAn options object for changing the behaviours of certificate generation.
options.hostAuthInfoobjectAn options object for defining properties used by the collective to remotely access the host machine of the member.
options.rpcHoststringThe Host address of the remote server
options.rpcUserstringThe username of an account
options.rpcUserHomestringThe UserHome directory of rpcUser that can run RPC commands against the host. Does not apply if SSH is used.
options.rpcPortstringThe RPC port of the member host. Does not apply if SSH is used.
options.rpcUserPasswordstringThe password for the user account running RPC commands. Does not apply if SSH is used.
options.hostAuthInfo.sudoUserstringOn systems where "sudo" is available, this will be the username of a sudoer for elevating SSH commands. Only applies to SSH.
options.sudoPasswordstringThe password for the sudoer. Only applies to SSH.
options.sshPublicKeyPathstringThe path to the SSH public key.
options.sshPrivateKeyPathstringThe path to the SSH private key.
options.sshPrivateKeyPasswordstringThe password for the SSH private key.
options.useHostCredentialsbooleanTells the member to inherit its credentials configuration from the host's configuration (requires the host to already have been registered with the collective).
options.hostReadListArrayThe list of locations on the host with allowed read access.
options.hostWriteListArrayThe 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

ParamTypeDescription
optionsobjectThe options object.
options.hostNamestringThe hostname of the member.
options.wlpUserDirstringThe path on the host to the 'usr' folder that contains the member.
options.serverNamestringThe 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

ParamTypeDescription
optionsobjectThe options object.
options.hostNamestringThe hostname of the member.
options.rpcHoststringThe Host address of the remote server
options.rpcUserstringThe username of an account
options.rpcUserHomestringThe UserHome directory of rpcUser that can run RPC commands against the host. Does not apply if SSH is used.
options.rpcPortstringThe RPC port of the member host. Does not apply if SSH is used.
options.rpcUserPasswordstringThe 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.sshPrivateKeyPasswordstringThe password for the SSH private key.

Collective.unregisterHost(options)

Generates the JMX command to unregister a host.

Kind: static method of Collective

ParamTypeDescription
optionsobjectThe options object.
options.hostNamestringThe hostname of the member.

Collective.updateHost(options)

Generates the JMX command to update a host info.

Kind: static method of Collective

ParamTypeDescription
optionsobjectThe options object.
options.hostNamestringThe hostname of the member.
options.rpcHoststringThe Host address of the remote server
options.rpcUserstringThe username of an account
options.rpcUserHomestringThe UserHome directory of rpcUser that can run RPC commands against the host. Does not apply if SSH is used.
options.rpcPortstringThe RPC port of the member host. Does not apply if SSH is used.
options.rpcUserPasswordstringThe 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.sshPrivateKeyPasswordstringThe 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

ParamType
valboolean

encoder.addString(val)

Add a string to the JMX payload.

Kind: instance method of Encoder

ParamType
valstring

encoder.addInteger(val)

Add an integer to the JMX payload.

Kind: instance method of Encoder

ParamType
valnumber

encoder.addDouble(val)

Add a double to the JMX payload.

Kind: instance method of Encoder

ParamType
valnumber

encoder.addList(arr, type)

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

Kind: instance method of Encoder

ParamDescription
arrThe array of objects to add to the payload. All items must be of the same type!
typeThe 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

ParamDescription
arrThe array of objects to add to the payload. All items must be of the same type!
typeThe 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

ParamTypeDefaultDescription
map*The JSON object that acts as your map.
keyTypestringThe Java type of the keys.
valueTypestringThe Java type of the values.
isComplexKeybooleanfalseWhether 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

ParamTypeDefaultDescription
hashMap*The JSON object that acts as your map.
valuestringThe value to be put in the map
keystringThe key for the value in the map
keyTypestringThe Java type of the keys.
valueTypestringThe Java type of the values.
isComplexKeybooleanfalseWhether 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

ParamTypeDescription
val*The value to insert into the payload.
typestringThe Java data-type of the value.
baseTypestringThe 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

NameTypeDescription
options.acceptUnauthorizedstringAccept unauthorized HTTPS certificates if the server uses them. Common during initial join.
options.checkServerIdentitystringWhether to verify that server's hostname matches the CN in the TLS certificate. Defaults to true.
options.castringA PEM encoded CA certificate to trust as as an HTTPS certificate issuer.
options.usernamestringThe username used for Basic auth with the endpoint.
options.passwordstringThe password used for Basic auth with the endpoint.
options.pfxstringThe client identity.
options.pfxPassphrasestringThe pfx passphrase.
options.requestfunctionInject 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.

ParamTypeDescription
hoststringThe IP address of the host.
portnumber | stringThe port to connect to.
optionsobjectAdditional 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

ParamTypeDescription
payloadPayloadThe JMX payload to submit to the endpoint.
optionsobjectThe options object.
cbfunctionHandle the server's response.

Payload

Kind: global class

new Payload(path, verb, data, qs)

ParamTypeDescription
pathstringThe path to the resource.
verbstringThe REST verb of the request.
dataobjectThe JMX body of the request. Must be a JSON object, not a string!
qsstringAn 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

ParamTypeDescription
optionsobjectThe options object.
options.hoststringThe host on which the server is running.
options.userDirstringThe user directory in which the server is set up.
options.serverstringThe server name associated to the server.
options.applicationNamestringThe application name.
options.contextRootstringThe context root if routing by context root (the value is / if not).
options.vHoststringThe virtual host address if routing by virtual host (the value is * unless otherwise).
options.vHostPortstringThe virtual host port if routing by virtual host (the value is * unless otherwise)
operationstringThe 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

ParamTypeDescription
optionsobjectThe options object.
options.hoststringThe host on which the server is running.
options.userDirstringThe user directory in which the server is set up.
options.serverstringThe server name associated to the server.
options.applicationNamestringThe application name.
operationstringThe 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

ParamTypeDescription
optionsobjectThe options object.
options.hoststringThe host on which the server is running.
options.userDirstringThe user directory in which the server is set up.
options.serverstringThe server name associated to the server.
options.attributestringThe attribute type to be set.
options.attributeValuestringThe attribute value to be set.
operationstringThe 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