Commit 9ed2230e authored by Alessio Netti's avatar Alessio Netti

Analytics: refactored UnitGenerator (2)

- Added generateFromTemplate method
- Fixed handling of special cases (on-demand and root units)
- Added enforceTopics option to force a MQTT prefix for unit outputs
- printConfig in UnitTemplate now accounts for hierarchical units
- Updated README
parent b08c1680
......@@ -283,7 +283,7 @@ bool OperatorManager::checkTopics(op_dl_t p) {
MQTTChecker& mqttCheck = MQTTChecker::getInstance();
bool validTopics=true;
for(const auto& op : p.configurator->getOperators()) {
if (!mqttCheck.checkGroup(op->getName()) && !(op->getStreaming() && op->getDuplicate()))
if (!(op->getStreaming() && op->getDuplicate()) && !mqttCheck.checkGroup(op->getName()))
validTopics = false;
if (op->getStreaming()) {
for (const auto &u : op->getUnits())
......
This diff is collapsed.
......@@ -95,7 +95,7 @@ protected:
op.setDuplicate(false);
vector <shared_ptr<UnitTemplate<SBase>>> *units = NULL;
try {
units = this->_unitGen.generateUnits(std::list<std::string>(), protoInputs, protoOutputs, inputMode, op.getMqttPart(), true, op.getRelaxed());
units = this->_unitGen.generateUnits(std::list<std::string>(), protoInputs, protoOutputs, inputMode, op.getMqttPart(), true, false, op.getRelaxed());
}
catch (const std::exception &e) {
LOG(error) << this->_operatorName << " " << op.getName() << ": Error when creating template job unit: " << e.what();
......
......@@ -238,7 +238,7 @@ protected:
// The job unit is generated as a hierarchical unit with the top level unit and the sub-units having
// the same set of output sensors
jobUnit = unitGen.generateHierarchicalUnit(jobTopic, jobData.nodes, uTemplate->getOutputs(), uTemplate->getInputs(),
uTemplate->getOutputs(), uTemplate->getInputMode(), this->_mqttPart, this->_relaxed);
uTemplate->getOutputs(), uTemplate->getInputMode(), this->_mqttPart, false, false, this->_relaxed);
// Initializing sensors if necessary
jobUnit->init(this->_cacheSize, this->_flatten);
this->addToUnitCache(jobUnit);
......
......@@ -514,7 +514,7 @@ protected:
LOG(debug) << " No output specified, generating sink unit.";
try {
units = _unitGen.generateUnits(std::list<std::string>(), protoInputs, protoOutputs, inputMode, op.getMqttPart(), !op.getStreaming(), op.getRelaxed());
units = _unitGen.generateUnits(std::list<std::string>(), protoInputs, protoOutputs, inputMode, op.getMqttPart(), !op.getStreaming(), false, op.getRelaxed());
}
catch (const std::exception &e) {
LOG(error) << _operatorName << " " << op.getName() << ": Error when creating units: " << e.what();
......
......@@ -80,6 +80,7 @@ public:
_mqttPart(""),
_isTemplate(false),
_relaxed(false),
_enforceTopics(false),
_duplicate(false),
_streaming(true),
_sync(true),
......@@ -106,6 +107,7 @@ public:
_mqttPart(other._mqttPart),
_isTemplate(other._isTemplate),
_relaxed(other._relaxed),
_enforceTopics(other._enforceTopics),
_duplicate(other._duplicate),
_streaming(other._streaming),
_sync(other._sync),
......@@ -137,6 +139,7 @@ public:
_mqttPart = other._mqttPart;
_isTemplate = other._isTemplate;
_relaxed = other._relaxed;
_enforceTopics = other._enforceTopics;
_unitID = other._unitID;
_duplicate = other._duplicate;
_streaming = other._streaming;
......@@ -251,6 +254,7 @@ public:
const string& getMqttPart() const { return _mqttPart; }
bool getTemplate() const { return _isTemplate; }
bool getRelaxed() const { return _relaxed; }
bool getEnforceTopics() const { return _enforceTopics; }
bool getSync() const { return _sync; }
bool getDuplicate() const { return _duplicate; }
bool getStreaming() const { return _streaming; }
......@@ -269,6 +273,7 @@ public:
void setMqttPart(const string& mqttPart) { _mqttPart = mqttPart; }
void setTemplate(bool t) { _isTemplate = t; }
void setRelaxed(bool r) { _relaxed = r; }
void setEnforcetopics(bool e) { _enforceTopics = e; }
void setSync(bool sync) { _sync = sync; }
void setUnitID(int u) { _unitID = u; }
void setStreaming(bool streaming) { _streaming = streaming; }
......@@ -329,6 +334,8 @@ protected:
bool _isTemplate;
// If the operator's units must be built in relaxed mode
bool _relaxed;
// If true, when building the units of this operator all output sensors will have _mqttPart prepended to them
bool _enforceTopics;
// If true, the operator is a duplicate of another
bool _duplicate;
// If true, the operator performs computation in streaming
......
......@@ -147,8 +147,11 @@ public:
LOG_VAR(ll) << " Unit Cache Size: " << _unitCacheLimit;
if(!_units.empty()) {
LOG_VAR(ll) << " Units:";
for (auto u : _units)
u->printConfig(ll, lg);
if(_unitID<0)
for (auto u : _units)
u->printConfig(ll, lg);
else
_units[_unitID]->printConfig(ll, lg);
} else
LOG_VAR(ll) << " Units: none";
}
......@@ -323,7 +326,7 @@ public:
throw std::runtime_error("No template unit in operator " + _name + "!");
LOG(debug) << "Operator " << _name << ": cache miss for unit " << node << ".";
U_Ptr uTemplate = _unitCache->at(SensorNavigator::templateKey);
tempUnit = unitGen.generateUnit(node, uTemplate->getInputs(), uTemplate->getOutputs(), uTemplate->getInputMode(), _mqttPart, _relaxed);
tempUnit = unitGen.generateUnit(node, uTemplate->getInputs(), uTemplate->getOutputs(), uTemplate->getInputMode(), _mqttPart, false, false, _relaxed);
addToUnitCache(tempUnit);
}
......
This diff is collapsed.
......@@ -113,10 +113,11 @@ public:
/**
* @brief Prints the current unit configuration
*
* @param ll Logging level at which the configuration is printed
* @param lg Logger object to be used
* @param ll Logging level at which the configuration is printed
* @param lg Logger object to be used
* @param leadingSpaces Number of leading spaces to pre-pend
*/
virtual void printConfig(LOG_LEVEL ll, LOGGER& lg) = 0;
virtual void printConfig(LOG_LEVEL ll, LOGGER& lg, unsigned leadingSpaces=16) = 0;
};
......
......@@ -337,21 +337,24 @@ public:
/**
* @brief Prints the current unit configuration
*
* @param ll Logging level at which the configuration is printed
* @param lg Logger object to be used
* @param ll Logging level at which the configuration is printed
* @param lg Logger object to be used
* @param leadingSpaces Number of leading spaces to pre-pend
*/
virtual void printConfig(LOG_LEVEL ll, LOGGER& lg) override {
LOG_VAR(ll) << " Unit: " << _name;
LOG_VAR(ll) << " Inputs: ";
virtual void printConfig(LOG_LEVEL ll, LOGGER& lg, unsigned leadingSpaces=16) override {
if(leadingSpaces>30) return;
std::string leading(leadingSpaces, ' ');
LOG_VAR(ll) << leading << "Unit: " << _name;
LOG_VAR(ll) << leading << "Inputs: ";
for (const auto &i : _inputs)
LOG_VAR(ll) << " " << i->getName();
LOG_VAR(ll) << " Outputs: ";
LOG_VAR(ll) << leading << " " << i->getName();
LOG_VAR(ll) << leading << "Outputs: ";
for (const auto &o : _outputs)
o->printConfig(ll, lg, 20);
o->printConfig(ll, lg, leadingSpaces+4);
if(_subUnits.size()>0) {
LOG_VAR(ll) << " Sub-units: ";
LOG_VAR(ll) << leading << "Sub-units: ";
for (const auto &u : _subUnits)
LOG_VAR(ll) << " " << u->getName();
u->printConfig(ll, lg, leadingSpaces+4);
}
}
......
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