Commit 642fce1a authored by Alessio Netti's avatar Alessio Netti
Browse files

Analytics: fixed assignment of sensor sink paths in UnitGenerator

- Forward slashes are stripped out of MQTT topics before creating
the respective file sinks, if required
parent e58af57d
......@@ -32,6 +32,7 @@
#include <boost/algorithm/string.hpp>
#include "sensornavigator.h"
#include "UnitTemplate.h"
#include "mqttchecker.h"
using namespace std;
......@@ -331,13 +332,8 @@ public:
uOut.setMqtt(_navi->buildTopicForNode(j, uOut.getMqtt()));
// Duplicating the file sink adding the name of each unit to the path
string sPath = uOut.getSinkPath();
if(sPath != "") {
size_t idx = sPath.find_last_of("/\\");
if( idx != string::npos)
uOut.setSinkPath(sPath.substr(0, idx+1) + j + "_" + sPath.substr(idx+1, string::npos));
else
uOut.setSinkPath(j + "_" + sPath);
}
if(sPath != "")
uOut.setSinkPath(adjustSinkPath(sPath, j));
jobUnit->addOutput(uOut);
}
return jobUnit;
......@@ -366,6 +362,17 @@ public:
}
protected:
// Adjust the path of a sensor sink such that it will include the unit name as well
string adjustSinkPath(const string& sPath, const string& node) {
string newSPath = sPath;
size_t idx = newSPath.find_last_of("/\\");
if(idx != string::npos)
newSPath = newSPath.substr(0, idx+1) + MQTTChecker::topicToName(node) + "_" + newSPath.substr(idx+1, string::npos);
else
newSPath = MQTTChecker::topicToName(node) + "_" + newSPath;
return newSPath;
}
// This private method will resolve all nodes in the current sensor tree that satisfy the "unit" pattern,
// and then verify whether "node" belongs to this set or not.
......@@ -455,13 +462,8 @@ protected:
uOut.setMqtt(_navi->buildTopicForNode(u, uOut.getMqtt()));
// Duplicating the file sink adding the name of each unit to the path
string sPath = uOut.getSinkPath();
if(sPath != "") {
size_t idx = sPath.find_last_of("/\\");
if( idx != string::npos)
uOut.setSinkPath(sPath.substr(0, idx+1) + u + "_" + sPath.substr(idx+1, string::npos));
else
uOut.setSinkPath(u + "_" + sPath);
}
if(sPath != "")
uOut.setSinkPath(adjustSinkPath(sPath, u));
}
// If we are not using units (only unit is root, out of the hierarchy) we build sensors like in samplers
else
......
Markdown is supported
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