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 operationuristring =localhost:8081 REST server URIasyncboolean =true if false force the call to be synchronous, otherwise depend if the callback is defineddlimit_on_goinginteger =10000 limits the concurrent operationshistory_page_leninteger =1000 default history page lentimeoutinteger =5000 default timeout for operationconsole_logcallback redirected on console.logconsole_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
servernamecmdlineptypeworkdirhandlerbadhandler
rmtDownload
Retrive a process working directory return a zip file
Parameters
serveruidworkdirhandlerbadhandler
rmtUploadScript
Parameters
servernameptypecontenthandlerbadhandler
rmtSetConsole
Write on the remote console of the specified process
Parameters
serverstring rest process remote management serveruidstring the process uid returned by the rmtCreateProcessstrstring line to sendhandlerokcb handler on successbadhandlerbadcb handler on failure
rmtGetConsole
Reads the console of the specified process uid
Parameters
serverstring rest process remote management serveruidstring the process uid returned by the rmtCreateProcessfromlineinteger get from this linetolineinteger until this line (-1 means end)handlerokcb handler on successbadhandlerbadcb handler on failure
progressBar
Parameters
msgidlab
addLongKey
Parameters
objkeyvaluestr
getLongLong
Parameters
objkey
setLongLong
Parameters
objkeyval
normalizeDataset
Parameters
obj
getUS
get a US description
Parameters
_name
loadScript
Parameters
_nameseqidhandleFuncerrFunc
manageInstanceScript
Parameters
script_namescript_seqinstance_namecreatehandleFunc
saveScript
Parameters
valuehandleFunc
rmScript
Parameters
valuehandleFunc
searchScriptInstance
Parameters
script_namesearch_stringhandleFuncerrfunc
updateScriptInstance
Parameters
script_instancescript_base_descriptionhandleFunc
setAttribute
Parameters
devs(string | Array<string>) CU or array of CUattrstring attribute namevaluestring attribute valuehandleFuncokcb? callback if ok, enable async modehandleFuncErrbadcb? 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 namepriointeger Prioritymodeinteger mode
varpath
CU variable path
Type: Object
Properties
custring CU PATHdirstring direction (input,output)varstring variable dataset nameconststring constantco:Stringoriginstring 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 serverfuncstring REST functionparamobject REST function parametershandlerokcb handler on successbadhandlerbadcb handler on failure
rmtGetEnvironment
Retrive a given environemnt variable
Parameters
serverstring rest process remote management servervarnamestring environment variable namehandlerokcb handler on successbadhandlerbadcb handler on failure
Returns any the value on the specified handler.
rmtSetProp
Set the specified propery
Parameters
serverstring rest process remote management serverprop{uid: String, propname: String} property namehandlerokcb handler on successbadhandlerbadcb 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 servernamestring program namecmdlinestring command lineptypestring type ("exec": binary, "C++": C++ script")workdirstring remote local directoryhandlerokcb handler on successbadhandlerbadcb 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 serveruidstring the process uid returned by the rmtCreateProcessworkdirstring working dir to retrieve and ziphandlerokcb handler on successbadhandlerbadcb handler on failure
rmtUploadScript
Upload a script/executable on the remote server return the path
Parameters
serverstring rest process remote management servernamestring program nameptypestring type ("exec": binary, "C++": C++ script")contentstring base64 encoded content to uploadhandlerokcb handler on successbadhandlerbadcb 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 serverhandlerokcb handler on successbadhandlerbadcb handler on failure
Returns Array<object> return a list of process descriptors
rmtKill
Kill the specified process
Parameters
serverstring rest process remote management serveruidstring the process uid returned by the rmtCreateProcesshandlerokcb handler on successbadhandlerbadcb 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 serverlevelinteger purge levelhandlerokcb? handler on successbadhandlerbadcb? 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 performparamsstring parametershandlerokcb? handler on success, if present the call will be asynchronousbadhandlerbadcb? handler on failureserverstring? override the default server
registerCU
Registers a CU dataset using REST
Parameters
cuidstringobjobject the CU dataset to register/pushhandleFuncokcb? handler on success, if present the call will be asynchronousbadhandlerbadcb? handler on failure
pushCU
Push a CU dataset using REST
Parameters
cuidstringobjobject the CU dataset to register/pushhandleFuncokcb? handler on success, if present the call will be asynchronousbadhandlerbadcb? handler on failure
mdsBase
Helper function that wrap basic post used for query that regards generic MDS operations
Parameters
cmdstring command to sendoptobject optionshandleFuncokcb? handler on success, if present the call will be asynchronouserrFuncbadcb? handler on failure
tag
Start tagging a list of nodes for an interval of given time, expressed in cycles or ms
Parameters
tagnamestringnode_list(string | Array<string>)tag_typeinteger (2= time in ms, 1=cycles)tag_valueinteger numer of ms or cycleshandleFuncokcb? handler on success, if present the call will be asynchronousnokbadcb? 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 snapshotvalue_object? parameter for set commandhandleFuncokcb?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 specifiedvalue_object? some commands needs a parameterhandleFuncokcbnokbadcb
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 typevalue_object? in case of set the objecthandleFuncokcb? callback if ok, enable async modehandleFuncbadcb? 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 modehandlerrbadcb? 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 modehandlerrbadcb? 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 findalivebool search from alive or allhandleFuncokcb? 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 CUchannel_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 modebadfuncbadcb? 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 CUpropstring property namehandleFuncokcb? callback if ok, enable async modeerrFuncbadcb? bad callback
loadUnload
Load or Unload a CU
Parameters
dev(string | Array<string>) CU or array of CUloadunloadbool (true = load, false=unload)handleFuncokcb? callback if ok, enable async modenokbadcb? bad callback
sendCUCmd
Sends a command to a CU
Parameters
devs(string | Array<string>) CU or array of CUcmdcmdPar command to sendparamobject? optional and my be included into cmdhandleFuncokcb? callback if ok, enable async modehandleFuncErrbadcb? bad callback
sendCUFullCmd
Sends a command to a CU, with explicit params
Parameters
devs(string | Array<string>) CU or array of CUcmdstring command to sendparam(string | object)?forceintegerpriointegerhandleFuncokcb? callback if ok, enable async modehandleFuncErrbadcb? bad callback
getHistory
Retrive history of a channel dataset of a group of devices
Parameters
devs(string | Array<string>) CU or array of CUchannelinteger channel to retrievestart(integer | string) epoch timestamp in ms (GMT) of start of searchstop(integer | string) epoch timestamp in ms (GMT) of start of searchvarnamestring? optional name of the variable to retrieve (instead of all)handleFuncokcb? callback if ok, enable async modetagsv(string | Array<string>)? optional tagsfuncerrbadcb? optional bad callback
fetchHistoryToZip
Retrive history and write a local zip
Parameters
zipnamestringcams(string | Array<string>) array of CUstart(integer | string) epoch timestamp in ms (GMT) of start of searchstop(integer | string) epoch timestamp in ms (GMT) of start of searchtagsvArray<string>? tagsupdateCallokcberrCallbadcb
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 performedretryinteger retry the check for a maximum of number of timecheckFreqinteger check frequency in mscheckFuncokcb check function, should return true if ok or false if failsokhandleokcb callback to call if test succeednokhandlebadcb 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
configobjectconfigToRestoreArray<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 DBparmobject? optional parametersokhandleokcb? called when okerrorhandlebadcb? 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 peformeddevlistArray<string> list of CU to checkretryinteger retry the ckeck for the given number of timescheckFreqinteger check frequency expressed in mscheckFuncokcb 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 notokhandleokcb callback to call if the test complete successfullynokhandlebadcb 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
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
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
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
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago