Commit 4da0788a authored by Alessio Netti's avatar Alessio Netti
Browse files

DA: changed unit instantiation syntax

- When instantiating analyzer units, the sensor tree can be navigated
vertically through the "topdown N" and "bottomup N" keywords, which
respectively mean "N levels down from the top" or "N levels up from the
bottom" of the sensor tree
- This renders the "unit - X" syntax obsolete
parent 0523cf25
......@@ -17,23 +17,23 @@ mqttStart 00
input {
sensor "<unit>col_user"
sensor "<bottomup>col_user"
sensor "<unit-1>MemFree"
sensor "<topdown>MemFree"
}
output {
sensor "<unit, filter cpu250>sum" {
sensor "<bottomup, filter cpu250>sum" {
mqttsuffix 76
}
sensor "<unit, filter cpu250>max" {
sensor "<bottomup, filter cpu250>max" {
mqttsuffix 77
}
sensor "<unit, filter cpu250>avg" {
sensor "<bottomup, filter cpu250>avg" {
mqttsuffix 78
}
......@@ -49,23 +49,23 @@ mqttStart 00
input {
sensor "<unit>col_user"
sensor "<topdown 1>col_user"
sensor "<unit - 1>MemFree"
sensor "<bottomup 1>MemFree"
}
output {
sensor "<unit - 1>sum" {
sensor "<bottomup 1>sum" {
mqttsuffix 76
}
sensor "<unit - 1>max" {
sensor "<bottomup 1>max" {
mqttsuffix 77
}
sensor "<unit - 1>avg" {
sensor "<bottomup 1>avg" {
mqttsuffix 78
}
......@@ -87,15 +87,15 @@ mqttStart 00
output {
sensor "<unit - 1>sumall" {
sensor "<bottomup 1>sumall" {
mqttsuffix 80
}
sensor "<unit - 1>maxall" {
sensor "<bottomup 1>maxall" {
mqttsuffix 81
}
sensor "<unit - 1>avgall" {
sensor "<bottomup 1>avgall" {
mqttsuffix 82
}
......
......@@ -59,11 +59,11 @@ public:
* @brief Parses a string encoding a tree level
*
* This method serves to parse strings that are used to express hierarchy levels in config files
* of the data analytics framework. These strings are in the format "<unit-X>.*", and signify
* "sensors that are in nodes X levels up from the deepest level in the sensor tree". As such,
* the method returns the depth level of sensors represented by the input string. Note that
* "<unit+X>.*" is not supported, because the system relates to the deepest level of the current
* sensor tree.
* of the data analytics framework. These strings are in the format "<topdown X>.*" or
* "<bottomup X>.*", and signify "sensors that are in nodes X levels down from level 0 in the
* sensor tree", or "sensors that are in nodes X levels up from the deepest level in the sensor
* tree" respectively. As such, the method returns the depth level of sensors represented by the
* input string.
*
* @param s String to be parsed
* @return Absolute depth level in the sensor tree that is encoded in the string
......@@ -73,13 +73,26 @@ public:
throw runtime_error("UnitGenerator: SensorNavigator tree not initialized!");
int _treeDepth = _navi->getTreeDepth();
bool topDown = false;
if(boost::regex_search(s.c_str(), _match, _blockRx)) {
string blockMatch = _match.str(0);
if(!boost::regex_search(blockMatch.c_str(), _match, _nodeRx))
if(boost::regex_search(blockMatch.c_str(), _match, _topRx))
topDown = true;
else if(boost::regex_search(blockMatch.c_str(), _match, _bottomRx))
topDown = false;
else
throw runtime_error("UnitGenerator: Syntax error in configuration!");
blockMatch = _match.str(0);
int lv = !boost::regex_search(blockMatch.c_str(), _match, _numRx) ? _treeDepth : _treeDepth - (int)stoi(_match.str(0));
return lv<-1 ? -1 : lv;
int lv;
if(topDown)
lv = !boost::regex_search(blockMatch.c_str(), _match, _numRx) ? 0 : (int)stoi(_match.str(0));
else
lv = !boost::regex_search(blockMatch.c_str(), _match, _numRx) ? _treeDepth : _treeDepth - (int)stoi(_match.str(0));
if( lv < 0 ) lv = 0;
else if( lv > _treeDepth ) lv = _treeDepth;
return lv;
}
else
return -1;
......@@ -92,7 +105,7 @@ public:
* takes as input also the name of a node in the sensor tree. The method will then return the set
* of sensors expressed by "s", that belong to nodes encoded in its hierarchy level and that are
* related to "node", either as ancestors or descendants. If a filter was included in the unit
* clause, e.g. <unit - 1, filter cpu>freq, then only sensors in nodes matching the filter
* clause, e.g. <bottomup 1, filter cpu>freq, then only sensors in nodes matching the filter
* regular expression will be returned.
*
* @param s String to be parsed
......@@ -155,7 +168,7 @@ public:
set<string>* units = NULL;
if(unitLevel > -1)
units = resolveNodeLevelString(outputs[0]->getName(), SensorNavigator::rootKey, false);
// If no depth level was found (output sensor names do not contain any <unit-X> keyword) we assume that
// If no depth level was found (output sensor names do not contain any <unit> block) we assume that
// everything relates to root
else if(unitLevel == -1) {
units = new set<string>();
......@@ -283,8 +296,8 @@ protected:
// Mapping inputs
for(const auto& in : inputs) {
// Depending on the relationship of an input prototype sensor to the output level, it could be
// mapped to one sensor or more: for example, if output has level <unit-1>, and an input sensor
// has level <unit-2>, than the input will be unique, and the sensor associated to the father of the
// mapped to one sensor or more: for example, if output has level <bottomup 1>, and an input sensor
// has level <bottomup 2>, than the input will be unique, and the sensor associated to the father of the
// unit. If the other way around, the input will consist of multiple sensors, one for each child of
// the unit
sensors = resolveNodeLevelString(in->getName(), u);
......@@ -357,7 +370,8 @@ protected:
boost::cmatch _match;
//Regex that matches the entire unit configuration block
const boost::regex _blockRx = boost::regex("<.*>");
const boost::regex _nodeRx = boost::regex("(?<=[,<])[ \\t]*unit[ \\t]*(-[ \\t]*[0-9]+[ \\t]*)?(?=[,>])");
const boost::regex _bottomRx = boost::regex("(?<=[,<])[ \\t]*bottomup[ \\t]*([ \\t]*[0-9]+[ \\t]*)?(?=[,>])");
const boost::regex _topRx = boost::regex("(?<=[,<])[ \\t]*topdown[ \\t]*([ \\t]*[0-9]+[ \\t]*)?(?=[,>])");
const boost::regex _filterRx = boost::regex("(?<=filter)[ \\t]+[^ \\t,>]+");
const boost::regex _numRx = boost::regex("[0-9]+");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment