distributed-metadata module
Use the distributed-metadata module to manage distributed variables in the distributed store. The distributed store is the gateway-peering instance for distributed variables.
Distributed variables provide you with a mechanism to read from or write to DataPower® facilities across transactions or domains. Access the
distributed-metadata module with a
require(distributed-metadata') statement. To use distributed variables, you must
define the settings for distributed variables that include a dedicated gateway-peering instance. For
more information, see Distributed variables.
name
form and an options form.- The
nameform takes a variable name and a callback function. - The
optionsobject form takes a JSON object and a callback function. The JSON object includes thenameproperty and the following properties. These properties take a Boolean value oftrueorfalse, wheretrueis the default value. Because the default value istrue, the variable is domain specific and for an API gateway specific to the same organization in a catalog.useDomain- Specifies whether to limit the variable scope to the application domain.
useOrg- Specifies whether to limit the variable scope to the organization defined for the API gateway. This property is ignored if defined for a traditional DataPower service.
useCatalog- Specifies whether to limit the variable scope to the catalog defined for the API gateway. This
property is ignored if defined for a traditional DataPower service.
When
useOrgisfalse,useCatalogmust befalse. IfuseOrgisfalseanduseCatalogistrue, the call returns an error.
The following code illustrates an example to manage a variable from any domain, organization, and catalog.
let optGlobal = {
name: 'var://dist/myContext/myGlobalVar',
useDomain: false,
useOrg: false,
useCatalog: false
};
dm.delVariable()
Deletes the distributed variable from distributed storage.
- Syntax
-
nameformdm.delVariable(name,callback)optionsformdm.delVariable(options,callback)
- Parameters
-
- dm
- The name of the previously defined variable for the distributed-metadata object.
- name
- The name of the distributed variable to delete in the form of
var://dist/context/variable. Where context is the name of the context and variable is the name of the variable. - options
- The JSON object that defines the distributed variable to delete in the appropriate scope.
- callback
- The callback function in the
function(error,response){}form.
- Guidelines
- The dm.delVariable() API deletes the distributed variable from distributed storage or returns undefined if the variable does not exist. For a successful call, the result is the number of deleted entries.
- Examples
- Delete the
myVariabledistributed variable in themyContextcontext.var dm = require('distributed-metadata'); dm.delVariable('var://dist/myContext/myVariable',function(error,result) { if( !error) { console.log('delVariable result = ' + result); } else { console.error('delVariable error = ' + error); } });
dm.getVariable()
Gets the value of a distributed variable.
- Syntax
-
nameformdm.getVariable(name,callback)optionsformdm.getVariable(options,callback)
- Parameters
-
- dm
- The name of the previously defined variable for the distributed-metadata object.
- name
- The name of the distributed variable to access in the form of
var://dist/context/variable. Where context is the name of the context and variable is the name of the variable. - options
- The JSON object that defines the distributed variable to access in the appropriate scope.
- callback
- The callback function in the
function(error,response){}form.
- Guidelines
- The dm.getVariable() API returns the value of the variable or returns undefined if the variable does not exist. For a successful call, the result is the retrieved value for the entry.
- Examples
- Gets the value of the
myVariabledistributed variable in themyContextcontext.var dm = require('distributed-metadata'); dm.getVariable('var://dist/myContext/myVariable',function(error,result) { if( !error) { console.log('getVariable result = ' + result); } else { console.error('getVariable error = ' + error); } });
dm.setVariable()
Sets the value of a distributed variable.
- Syntax
-
nameformdm.setVariable(name,value,callback)optionsformdm.setVariable(options,callback)
- Parameters
-
- dm
- The name of the previously defined variable for the distributed-metadata object.
- name
- The name of the distributed variable to create in the form of
var://dist/context/variable. Where context is the name of the context and variable is the name of the variable. - options
- The JSON object that defines the distributed variable to set in the appropriate scope.
- value
- The value to set for the distributed variable. The value must be one of the following data
types. Attempting to set a value of any other type results in an error.
arraybooleandocumentnodelistnullnumberobjectstringundefined
- callback
- The callback function in the
function(error,response){}form.
- Guidelines
- The dm.setVariable() API creates a distributed variable if the specified
distributed variable does not exist. For a successful call, the result is
OK
. - Examples
- Create the
myVariabledistributed variable in themyContextcontext with a value ofmyValue.var dm = require('distributed-metadata'); dm.setVariable('var://dist/myContext/myVariable', "myValue",function(error,result) { if( !error) { console.log('setVariable result = ' + result); } else { console.error('setVariable error = ' + error); } });