Commit ea1ab2b2 authored by Alessio Netti's avatar Alessio Netti
Browse files

Metadata integration

- Metadata is now parsed from config files, sent from Pushers to
Collectagents as JSON, and finally written to Cassandra
parent dcafa065
......@@ -185,9 +185,8 @@ bool AnalyticsController::publishSensors() {
for (const auto &s : u->getBaseOutputs()) {
if (s->getPublish()) {
if (s->getMetadata()) {
SensorMetadata* sm = s->getMetadata();
//TODO: update this publishSensor call
err = _dcdbCfg->publishSensor(sm->publicName.c_str(), s->getMqtt().c_str());
DCDB::PublicSensor ps = Configuration::metadataToPublicSensor(*s->getMetadata(), s->getMqtt());
err = _dcdbCfg->publishSensor(ps);
} else {
err = _dcdbCfg->publishSensor(s->getName().c_str(), s->getMqtt().c_str());
}
......
......@@ -58,7 +58,6 @@
#include <dcdb/version.h>
#include <dcdb/sensor.h>
#include "version.h"
#include "metadatastore.h"
#include "CARestAPI.h"
#include "configuration.h"
......@@ -216,8 +215,8 @@ int mqttCallback(SimpleMQTTMessage *msg)
LOG(error) << "Invalid metadata packed received!";
return 1;
}
// TODO: update this publishSensor call
err = mySensorConfig->publishSensor(sm.publicName.c_str(), topic + DCDB_MET_LEN);
DCDB::PublicSensor ps = Configuration::metadataToPublicSensor(sm, std::string(topic + DCDB_MET_LEN));
err = mySensorConfig->publishSensor(ps);
} else {
err = mySensorConfig->publishSensor(payload.c_str(), topic + DCDB_MAP_LEN);
}
......
......@@ -73,3 +73,21 @@ void Configuration::readAdditionalBlocks(boost::property_tree::iptree& cfg) {
}
}
}
DCDB::PublicSensor Configuration::metadataToPublicSensor(const SensorMetadata& sm, const string& pattern) {
DCDB::PublicSensor ps;
ps.name = sm.publicName;
ps.is_virtual = sm.isVirtual;
ps.pattern = pattern;
ps.unit = sm.unit;
ps.scaling_factor = sm.scale;
ps.ttl = sm.ttl;
ps.interval = sm.interval;
uint64_t sensorMask = 0;
if(sm.integrable)
sensorMask = sensorMask | INTEGRABLE;
if(sm.monotonic)
sensorMask = sensorMask | MONOTONIC;
ps.operations = sm.getOperationsString();
return ps;
}
......@@ -33,6 +33,8 @@
#include "logging.h"
#include "globalconfiguration.h"
#include "metadatastore.h"
#include <dcdb/sensorconfig.h>
#define LISTENHOST "localhost"
#define LISTENPORT "1883"
......@@ -72,7 +74,7 @@ class Configuration : public GlobalConfiguration {
public:
/**
* Create new Configuration. Sets global config file to read from to cfgFile.
* @brief Create new Configuration. Sets global config file to read from to cfgFile.
*
* @param cfgFilePath Path to where all config-files are located
* @param cfgFileName Name of the file containing the config
......@@ -85,6 +87,15 @@ public:
virtual ~Configuration() {}
/**
* @brief
*
* @param s
* @param pattern
* @return
*/
static DCDB::PublicSensor metadataToPublicSensor(const SensorMetadata& s, const string& pattern);
// Additional configuration parameters to be parsed within the global block
std::string mqttListenHost = string(LISTENHOST);
std::string mqttListenPort = string(LISTENPORT);
......
......@@ -117,6 +117,8 @@ public:
this->scale = stod(val.second.data());
} else if (boost::iequals(val.first, "interval")) {
this->interval = stoull(val.second.data()) * 1000000;
} else if (boost::iequals(val.first, "ttl")) {
this->ttl = stoull(val.second.data()) * 1000000;
} else if (boost::iequals(val.first, "operations")) {
_parseVector(val.second.data(), this->operations);
}
......@@ -146,6 +148,17 @@ public:
_dumpPTREE(config);
return config;
}
/**
* @brief Returns a string representation of the internal vector of sensor operations.
*
* @return A comma-separated string of sensor operations
*/
string getOperationsString() const {
string out="";
_dumpVector(out, this->operations);
return out;
}
// Public class members
bool isVirtual;
......@@ -185,6 +198,7 @@ protected:
config.push_back(boost::property_tree::ptree::value_type("publicName", boost::property_tree::ptree(this->publicName)));
config.push_back(boost::property_tree::ptree::value_type("scale", boost::property_tree::ptree(to_string(this->scale))));
config.push_back(boost::property_tree::ptree::value_type("interval", boost::property_tree::ptree(to_string(this->interval / 1000000))));
config.push_back(boost::property_tree::ptree::value_type("ttl", boost::property_tree::ptree(to_string(this->ttl / 1000000))));
config.push_back(boost::property_tree::ptree::value_type("operations", boost::property_tree::ptree(ops)));
}
......
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