jchaos v1.2.1
JCHAOS
This javascript module can be used, both in HTML or as nodejs library to access !CHAOS resources. This package bundles some !CHAOS utility and management applications.
Install
Global installation:
npm install -g jchaos
NPM Will install library and applications
Repository
git@baltig.infn.it:chaos-lnf-control/jchaos.git
Application
jchaosctl
This application will perform management operation on chaos. The basic usage is:
/usr/bin/jchaosctl <--server server:port>
[--upload <config to upload>]
[--download <config output>>]
[--findlive < cu | us | agent | mds | webui | variable | snapshotsof | snapshots | script | zone | class >]
[--find < cu | us | agent | mds | webui | variable | snapshotsof | snapshots | script | zone | class >]
[--op < start | stop | init | deinit| load | unload | kill | shutdown |health>]
[--uid <!CHAOS node UID>]
[--help]jchaos library
Table of Contents
- jchaos
- okcb
- badcb
- cmdPar
- varpath
- channelid
- call
- createLibrary
- decodeCUPath
- toHHMMSS
- setOption
- basicRmt
- rmtGetEnvironment
- rmtSetProp
- rmtCreateProcess
- rmtCreateProcess
- rmtUploadScript
- rmtListProcess
- rmtKill
- rmtPurge
- basicPost
- registerCU
- pushCU
- mdsBase
- tag
- checkRestore
- checkBurstRunning
- checkEndBurst
- snapshot
- node
- variable
- log
- search
- findCUByImplementation
- getCUStatus
- convertArray2CSV
- getChannel
- setProperty
- loadUnload
- sendCUCmd
- sendCUFullCmd
- getHistory
- fetchHistoryToZip
- checkPeriodiocally
- saveFullConfig
- restoreFullConfigFromFile
- restoreFullConfig
- activeAgentList
- getAllProcessInfo
- findBestServer
- runScript
- encodeName
- checkLive
jchaos
!CHAOS REST Library
Meta
- version: 1.0
- author: Andrea Michelotti
options
Properties
- updateEachCallboolean =true choose if update each call of history operation
- uristring =localhost:8081 REST server URI
- asyncboolean =true if false force the call to be synchronous, otherwise depend if the callback is definedd
- limit_on_goinginteger =10000 limits the concurrent operations
- history_page_leninteger =1000 default history page len
- timeoutinteger =5000 default timeout for operation
- console_logcallback redirected on console.log
- console_errcallback redirected on console.error
Prints a String on the configured console
Parameters
- strstring
perror
Prints a String on the configured console error
Parameters
- strstring
rmtCreateProcess
Parameters
- server
- name
- cmdline
- ptype
- workdir
- handler
- badhandler
rmtDownload
Retrive a process working directory return a zip file
Parameters
- server
- uid
- workdir
- handler
- badhandler
rmtUploadScript
Parameters
- server
- name
- ptype
- content
- handler
- badhandler
rmtSetConsole
Write on the remote console of the specified process
Parameters
- serverstring rest process remote management server
- uidstring the process uid returned by the rmtCreateProcess
- strstring line to send
- handlerokcb handler on success
- badhandlerbadcb handler on failure
rmtGetConsole
Reads the console of the specified process uid
Parameters
- serverstring rest process remote management server
- uidstring the process uid returned by the rmtCreateProcess
- fromlineinteger get from this line
- tolineinteger until this line (-1 means end)
- handlerokcb handler on success
- badhandlerbadcb handler on failure
progressBar
Parameters
- msg
- id
- lab
addLongKey
Parameters
- obj
- key
- valuestr
getLongLong
Parameters
- obj
- key
setLongLong
Parameters
- obj
- key
- val
normalizeDataset
Parameters
- obj
getUS
get a US description
Parameters
- _name
loadScript
Parameters
- _name
- seqid
- handleFunc
- errFunc
manageInstanceScript
Parameters
- script_name
- script_seq
- instance_name
- create
- handleFunc
saveScript
Parameters
- value
- handleFunc
rmScript
Parameters
- value
- handleFunc
searchScriptInstance
Parameters
- script_name
- search_string
- handleFunc
- errfunc
updateScriptInstance
Parameters
- script_instance
- script_base_description
- handleFunc
setAttribute
Parameters
- devs(string | Array<string>) CU or array of CU
- attrstring attribute name
- valuestring attribute value
- handleFuncokcb? callback if ok, enable async mode
- handleFuncErrbadcb? bad callback
okcb
Callback in asynchronous operations called when the operation is ok
Type: Function
Parameters
- dataobject depend on the operation (typically a dataset)
badcb
Callback in asynchronous operations called when the operation is fails
Type: Function
Parameters
cmdPar
The command object for sendCU commands
Type: Object
Properties
- cmdstring command name
- priointeger Priority
- modeinteger mode
varpath
CU variable path
Type: Object
Properties
- custring CU PATH
- dirstring direction (input,output)
- varstring variable dataset name
- conststring constantco:String
- originstring full path
channelid
Channel idintification mapping: -1 : all 0: output 1: input 2: custom 3: system 4: health 5: cu alarms 6: device alarms 128: status 255: health+system+ alarams
Type: integer
call
Type: object
Properties
createLibrary
Creates a new jchaos object.
decodeCUPath
Decode a CU dataset element path and return an object
Parameters
- cupathstring
Returns varpath
toHHMMSS
translate seconds in days hours minutes seconds string
Parameters
- sec_numinteger
Returns string return string xx days hh:mm:ss
setOption
Set Library options options
Parameters
- optobject
basicRmt
Helper function to post commands on the process remote management
Parameters
- serverstring rest process remote management server
- funcstring REST function
- paramobject REST function parameters
- handlerokcb handler on success
- badhandlerbadcb handler on failure
rmtGetEnvironment
Retrive a given environemnt variable
Parameters
- serverstring rest process remote management server
- varnamestring environment variable name
- handlerokcb handler on success
- badhandlerbadcb handler on failure
Returns any the value on the specified handler.
rmtSetProp
Set the specified propery
Parameters
- serverstring rest process remote management server
- prop{uid: String, propname: String} property name
- handlerokcb handler on success
- badhandlerbadcb handler on failure
Returns any the value on the specified handler.
rmtCreateProcess
Launch a process the specified process on the given remote server return a process structure
Parameters
- serverstring rest process remote management server
- namestring program name
- cmdlinestring command line
- ptypestring type ("exec": binary, "C++": C++ script")
- workdirstring remote local directory
- handlerokcb handler on success
- badhandlerbadcb handler on failure
Returns object return a process object with many status and information
rmtCreateProcess
Return a zip file contaning the working directory of the specified process can be used to retrieve outputs of remote runs
Parameters
- serverstring rest process remote management server
- uidstring the process uid returned by the rmtCreateProcess
- workdirstring working dir to retrieve and zip
- handlerokcb handler on success
- badhandlerbadcb handler on failure
rmtUploadScript
Upload a script/executable on the remote server return the path
Parameters
- serverstring rest process remote management server
- namestring program name
- ptypestring type ("exec": binary, "C++": C++ script")
- contentstring base64 encoded content to upload
- handlerokcb handler on success
- badhandlerbadcb handler on failure
Returns object return the path of the remote process
rmtListProcess
Return a list of process on the given server
Parameters
- serverstring rest process remote management server
- handlerokcb handler on success
- badhandlerbadcb handler on failure
Returns Array<object> return a list of process descriptors
rmtKill
Kill the specified process
Parameters
- serverstring rest process remote management server
- uidstring the process uid returned by the rmtCreateProcess
- handlerokcb handler on success
- badhandlerbadcb handler on failure
rmtPurge
Purge a list of process to a given level (0 soft (EXCEPTION), 1 medium (ENDED and EXCEPTION), 2 hard (ALL)
Parameters
- serverstring rest process remote management server
- levelinteger purge level
- handlerokcb? handler on success
- badhandlerbadcb? handler on failure
basicPost
Helper function that is the base of all commands to the !CHAOS REST SERVER the server is specified in the option
Parameters
- funcstring REST function to perform
- paramsstring parameters
- handlerokcb? handler on success, if present the call will be asynchronous
- badhandlerbadcb? handler on failure
- serverstring? override the default server
registerCU
Registers a CU dataset using REST
Parameters
- cuidstring
- objobject the CU dataset to register/push
- handleFuncokcb? handler on success, if present the call will be asynchronous
- badhandlerbadcb? handler on failure
pushCU
Push a CU dataset using REST
Parameters
- cuidstring
- objobject the CU dataset to register/push
- handleFuncokcb? handler on success, if present the call will be asynchronous
- badhandlerbadcb? handler on failure
mdsBase
Helper function that wrap basic post used for query that regards generic MDS operations
Parameters
- cmdstring command to send
- optobject options
- handleFuncokcb? handler on success, if present the call will be asynchronous
- errFuncbadcb? handler on failure
tag
Start tagging a list of nodes for an interval of given time, expressed in cycles or ms
Parameters
- tagnamestring
- node_list(string | Array<string>)
- tag_typeinteger (2= time in ms, 1=cycles)
- tag_valueinteger numer of ms or cycles
- handleFuncokcb? handler on success, if present the call will be asynchronous
- nokbadcb? handler on failure
Examples
//tagging for 10s two CU (cameras), give the name burstbyseconds  
var camera_list=["TEST/FLAME/CMP/CAMERA/FLACMPFF","TEST/FLAME/CMP/CAMERA/FLMCMP01"];
jchaos.tag("burstbyseconds",camera_list,2,10000,function(d){jchaos.print("tagging started");});checkRestore
Check if a lists of CU have done a correct snapshot restore, the check is performed every timeout/10 ms for maximum timeout
Parameters
- _tagnamestring name of the tag
- _node_list(string | Array<string>) list of nodes
- _timeoutinteger timeout
- _okhandlerokcb?
- _nokhandlerbadcb?
checkBurstRunning
Helper function to check if a burst is running
Parameters
- _tagnamestring name of the tag
- _node_list(string | Array<string>) list of nodes
- _timeoutinteger timeout
- _okhandlerokcb?
- _nokhandlerbadcb?
Examples
// check the burst is running
var camera_list=["TEST/FLAME/CMP/CAMERA/FLACMPFF","TEST/FLAME/CMP/CAMERA/FLMCMP01"];
jchaos.checkBurstRunning("burstbyseconds",camera_list,10000,function(){jchaos.print("OK");},function(){chaos.error("BAD");})checkEndBurst
Check if a list of CU ended correct burst, the check is performed every timeout/10 ms for maximum timeout
Parameters
- _tagnamestring name of the tag
- _node_list(string | Array<string>) list of nodes
- _timeoutinteger timeout
- _okhandlerokcb?
- _nokhandlerbadcb?
Examples
// check the burst is running
var camera_list=["TEST/FLAME/CMP/CAMERA/FLACMPFF","TEST/FLAME/CMP/CAMERA/FLMCMP01"];
jchaos.checkEndBurst(camera_list,10000,function(){jchaos.print("OK");},function(){chaos.error("BAD");})snapshot
- See: tag
Performs snapshot operations
Parameters
- _namestring name of the snapshot
- _what(- "create"|- "load"|- "set"|- "delete"|- "restore"|- "burst") operation to perform
- _node_list(string | Array<string>) nodes to snapshot
- value_object? parameter for set command
- handleFuncokcb?
- nokbadcb?
Examples
// create a set point programmatically of a set of powersupply
var ps=["BTF/QUADRUPOLE/QUATB001","BTF/QUADRUPOLE/QUATB002","BTF/QUADRUPOLE/QUATB003"];
var powersupply_setpoint = {
"input": {
"ndk_uid": "undefined",
"current": 0.1,
"stby": true,
"polarity": 1
},
"output": {
"ndk_uid": "undefined",
"current": 0.1,
"stby": true,
"polarity": 1,
"local": false
}
};
var snapshot_set = [];
var polarity = 1;
var current = Number(0.0000001);
ps.forEach(function (elem) {
var snap = powersupply_setpoint;
snap.input.stby = true;
snap.input.current = current;
snap.input.ndk_uid = elem;
snap.input.polarity = polarity;
snap.output.ndk_uid = elem;
snap.output.polarity = polarity;
snap.output.stby = true;
snap.output.current = current;
polarity = polarity > 0 ? -1 : 1;
jchaos.snapshot("zero-stby", "set", "", snap, function (d) {
jchaos.print("set setpoint OK:"+JSON.stringify(snap));
});
});node
Perform and operation specified by '_what' onthe nodes of '_name' of type :'_type'
Parameters
- _name(string | Array<string>) the name of the nodes where to perform the operation
- _what(- "init"|- "deinit"|- "start"|- "stop"|- "get"|- "set"|- "del"|- "killcmd"|- "shutdown"|- "kill"|- "restart"|- "desc"|- "getlog"|- "health"|- "info") operation type
- _type(- "us"|- "cu"|- "agent") target type of the command
- _parentstring? some commands needs a parent node to be specified
- value_object? some commands needs a parameter
- handleFuncokcb
- nokbadcb
Examples
// stop|start|init|deinit a cu 
jchaos.node("BTF/QUADRUPOLE/QUATB001","stop","cu");
jchaos.node("BTF/QUADRUPOLE/QUATB001","start","cu");variable
Allows to manage variables that are persistent (on DB)
Parameters
- _name(string | Array<string>)
- _what(- "set"|- "get"|- "del"|- "search") operation type
- value_object? in case of set the object
- handleFuncokcb? callback if ok, enable async mode
- handleFuncbadcb? callback if failure
Examples
// store an object
var point={x:10.34,y:14.0};
jchaos.variable("mypoint","set",point);
// perform list
jchaos.variable("mypoint","search",function(ls){jchaos.print(JSON.stringify(ls));}); 
// get and visualize variable stored
jchaos.variable("mypoint","get",function(ls){jchaos.print(JSON.stringify(ls));});
// delete variable
jchaos.variable("mypoint","del");log
Search logs for the given CUs
Parameters
- devs(string | Array<string>) to search
- _what- "search"operation to perform
- _type(- "all"|- "Info"|- "error"|- "warning"|- "log"|- "command") specify log type
- _startinteger epoch in ms start of the search
- _endinteger epoch md end of the search (-1 is now)
- handleFuncokcb? callback if ok, enable async mode
- handlerrbadcb? callback if error
Examples
// retrieve all logs for a given CU till now
jchaos.log("BTF/QUADRUPOLE/QUATB001","search","all",0,-1,function(ls){jchaos.print(JSON.stringify(ls));});search
Parameters
- _namestring is the substring of what you want search
- _what(- "cu"|- "us"|- "agent"|- "cds"|- "webui"|- "variable"|- "snapshotsof"|- "snapshots"|- "script"|- "zone"|- "class") operation type
- _aliveboolean search among alive (true) or all(false)
- handleFuncokcb? callback if ok, enable async mode
- handlerrbadcb? callback if error
Examples
// search all CU alive
jchaos.search("","cu",true,function(ls){jchaos.print(JSON.stringify(ls));});Returns any an array of strings or objects
findCUByImplementation
Find an array of CU with the given implementation
Parameters
- implstring C++ implementation name to find
- alivebool search from alive or all
- handleFuncokcb? callback if ok, enable async mode
Examples
// find implementation that starts with SCA(ctuators)
jchaos.findCUByImplementation("SCA",true,function(ls){jchaos.print(JSON.stringify(ls));});getCUStatus
Return an array of CU that match a given status
Parameters
convertArray2CSV
convert an array into a CommaSepareted elements
Parameters
Returns string
getChannel
Retrive the specified dataset correspoding to a given CU
Parameters
- devs(String | Array<String>) CU or array of CU
- channel_idchannelid (-1: all,0: output, 1: input, 2:custom,3:system, 4: health, 5 cu alarm, 6 dev alarms,128 status)
- handleFuncokcb? callback if ok, enable async mode
- badfuncbadcb? bad callback
Examples
//retrive all channels of a give CU
chaos.getChannel("BTF/QUADRUPOLE/QUATB001",-1,function(ls){jchaos.print(JSON.stringify(ls));});Returns object the specified dataset
setProperty
Set a CU property
Parameters
- dev(string | Array<string>) CU or array of CU
- propstring property name
- handleFuncokcb? callback if ok, enable async mode
- errFuncbadcb? bad callback
loadUnload
Load or Unload a CU
Parameters
- dev(string | Array<string>) CU or array of CU
- loadunloadbool (true = load, false=unload)
- handleFuncokcb? callback if ok, enable async mode
- nokbadcb? bad callback
sendCUCmd
Sends a command to a CU
Parameters
- devs(string | Array<string>) CU or array of CU
- cmdcmdPar command to send
- paramobject? optional and my be included into cmd
- handleFuncokcb? callback if ok, enable async mode
- handleFuncErrbadcb? bad callback
sendCUFullCmd
Sends a command to a CU, with explicit params
Parameters
- devs(string | Array<string>) CU or array of CU
- cmdstring command to send
- param(string | object)?
- forceinteger
- priointeger
- handleFuncokcb? callback if ok, enable async mode
- handleFuncErrbadcb? bad callback
getHistory
Retrive history of a channel dataset of a group of devices
Parameters
- devs(string | Array<string>) CU or array of CU
- channelinteger channel to retrieve
- start(integer | string) epoch timestamp in ms (GMT) of start of search
- stop(integer | string) epoch timestamp in ms (GMT) of start of search
- varnamestring? optional name of the variable to retrieve (instead of all)
- handleFuncokcb? callback if ok, enable async mode
- tagsv(string | Array<string>)? optional tags
- funcerrbadcb? optional bad callback
fetchHistoryToZip
Retrive history and write a local zip
Parameters
- zipnamestring
- cams(string | Array<string>) array of CU
- start(integer | string) epoch timestamp in ms (GMT) of start of search
- stop(integer | string) epoch timestamp in ms (GMT) of start of search
- tagsvArray<string>? tags
- updateCallokcb
- errCallbadcb
checkPeriodiocally
- See: checkLive
- See: checkBurstRunning
Helper function th check a periodically a condition the difference with check live is the check function don't receive a dataset in input
Parameters
- strstring string to display each time the check is performed
- retryinteger retry the check for a maximum of number of time
- checkFreqinteger check frequency in ms
- checkFuncokcb check function, should return true if ok or false if fails
- okhandleokcb callback to call if test succeed
- nokhandlebadcb callback to call if fails
saveFullConfig
saveFullConfig Save to local disk the state of fundamental configurations
Examples
//save the infrastructure info.
saveFullConfig();restoreFullConfigFromFile
Restore a full configuration from file
restoreFullConfig
Restore a previously a configuration into the infrastructure
Parameters
- configobject
- configToRestoreArray<string> array of things to restore "us","agents","snapshots","graphs","custom_group","cu_templates"
activeAgentList
activeAgentList return a list of agents addresses in the callback
Parameters
- cbokcb callback called with the agent object list
Examples
jchaos.activeAgentList(function(cb){jchaos.print(JSON.stringify(cb));})Returns Array<object> return in the callback the list descriptor of the agents
getAllProcessInfo
Return a vector of process information in the callback
Parameters
findBestServer
findBestServer return a list of agents ordered by occupation in the callback NOTE: this function use a tcp port the is different from REST server one (it goes directly on the server)
Parameters
- cbokcb : return a list of active agents
Examples
// find the best server to run a script:
jchaos.findBestServer(function(cb){jchaos.print(JSON.stringify(cb));})Returns string return the best server
runScript
runScript Run the specified script on the chaos infrastructure
Parameters
- namestring the name of the script present in the DB
- parmobject? optional parameters
- okhandleokcb? called when ok
- errorhandlebadcb? called when failed
encodeName
Encode a path name removes trailing
Parameters
- strstring string to encode
Returns string encoded string
checkLive
This function used mainly in tests. It checks for a variable change on a 'devlist', for 'retry' times, checking every 'checkFreq' 'checkFunc' takes in input the live and realize the check okhandle is called if success nokhandle if fails
Parameters
- strstring string to display when the check is peformed
- devlistArray<string> list of CU to check
- retryinteger retry the ckeck for the given number of times
- checkFreqinteger check frequency expressed in ms
- checkFuncokcb call back to call that perform the check, it takes in input the dataset to check, should return true if the check succeed or false if not
- okhandleokcb callback to call if the test complete successfully
- nokhandlebadcb callback to call if the test fails
Examples
// check if the list of CUs are in start
 var cu_status=["BTF/QUADRUPOLE/QUATB001","BTF/QUADRUPOLE/QUATB002","BTF/QUADRUPOLE/QUATB003"];
 jchaos.checkLive('check Start',cu_status, 20, 1000, function (ds) {jchaos.print("testing..."); return (ds!=null)&&ds.hasOwnProperty("health")&&ds.health.hasOwnProperty("nh_status")&&(ds.health.nh_status == "Start"); }, function () { jchaos.print("CHECK OK"); }, function () { jchaos.error("CHECK FAILED"); });3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago