The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit 84f185bc authored by Axel Auweter's avatar Axel Auweter
Browse files

Refactor DCDBLib to introduce DCDB namespace & prepare DB schema for virtual sensor support.

parent 4fd356ec
......@@ -30,7 +30,7 @@ int keepRunning;
bool statistics;
uint64_t msgCtr;
uint64_t pmsgCtr;
SensorDataStore *mySensorDataStore;
DCDB::SensorDataStore *mySensorDataStore;
std::string listenHost, cassandraHost, ttl;
/* Normal termination (SIGINT, CTRL+C) */
......@@ -93,7 +93,7 @@ void mqttCallback(SimpleMQTTMessage *msg)
* into a valid SensorId. If successful, store
* the record in the database.
*/
SensorId sid;
DCDB::SensorId sid;
if (sid.mqttTopicConvert(msg->getTopic())) {
#if 0
cout << "Topic decode successful:"
......@@ -185,8 +185,8 @@ int main(int argc, char* const argv[]) {
* Allocate and initialize connection to Cassandra.
*/
std::string sdHost = cassandraHost;
DCDBConnection* dcdbConn;
dcdbConn = new DCDBConnection(sdHost, 9042);
DCDB::Connection* dcdbConn;
dcdbConn = new DCDB::Connection(sdHost, 9042);
if (!dcdbConn->connect()) {
std::cout << "Cannot connect to Cassandra!" << std::endl;
......@@ -201,7 +201,7 @@ int main(int argc, char* const argv[]) {
/*
* Allocate the SensorDataStore.
*/
mySensorDataStore = new SensorDataStore(dcdbConn);
mySensorDataStore = new DCDB::SensorDataStore(dcdbConn);
/*
* Set TTL for data store inserts if TTL > 0.
......
......@@ -9,7 +9,7 @@
* @file
* @brief This file contains parts of the public API for the
* DCDBLib library.
* It contains the class definition of the DCDBConnection class,
* It contains the class definition of the Connection class,
* that handles connections to the data store and schema
* initialization.
*/
......@@ -19,16 +19,18 @@
#include "cassandra.h"
#ifndef CONNECTION_H
#define CONNECTION_H
#ifndef DCDB_CONNECTION_H
#define DCDB_CONNECTION_H
namespace DCDB {
/* Forward-declaration of the implementation-internal classes */
class DCDBConnectionImpl;
class ConnectionImpl;
class DCDBConnection
class Connection
{
private:
DCDBConnectionImpl* impl; /**< The object which implements the core functionality of this class */
ConnectionImpl* impl; /**< The object which implements the core functionality of this class */
public:
/**
......@@ -99,21 +101,23 @@ public:
bool initSchema();
/**
* @brief Standard constructor for DCDBConnections.
* @brief Standard constructor for Connections.
*
* If not set explicitly, hostname and port will default to localhost and 9042.
*/
DCDBConnection();
Connection();
/**
* @brief Construct a DCDBConnection to the specific host and port.
* @brief Construct a Connection to the specific host and port.
*/
DCDBConnection(std::string hostname, uint16_t port);
Connection(std::string hostname, uint16_t port);
/**
* @brief Standard destructor for DCDBConnections.
* @brief Standard destructor for Connections.
*/
virtual ~DCDBConnection();
virtual ~Connection();
};
#endif /* CONNECTION_H */
} /* End of namespace DCDB */
#endif /* DCDB_CONNECTION_H */
......@@ -22,12 +22,14 @@
#include "cassandra.h"
#ifndef SENSORCONFIG_H
#define SENSORCONFIG_H
#ifndef DCDB_SENSORCONFIG_H
#define DCDB_SENSORCONFIG_H
namespace DCDB {
class SensorConfigImpl;
class DCDBPublicSensor
class PublicSensor
{
public:
std::string name;
......@@ -36,8 +38,8 @@ public:
std::string unit;
bool integrable;
DCDBPublicSensor();
DCDBPublicSensor(const DCDBPublicSensor &copy);
PublicSensor();
PublicSensor(const PublicSensor &copy);
};
typedef enum {
......@@ -58,21 +60,22 @@ public:
SCError publishSensor(const char* publicName, const char* sensorPattern);
SCError unPublishSensor(const char* publicName);
SCError getPublicSensorNames(std::list<std::string>& publicSensors);
SCError getPublicSensorsVerbose(std::list<DCDBPublicSensor>& publicSensors);
SCError getPublicSensorsVerbose(std::list<PublicSensor>& publicSensors);
SCError getPublicSensorByName(DCDBPublicSensor& sensor, const char* publicName);
SCError getPublicSensorByName(PublicSensor& sensor, const char* publicName);
SCError getSensorPattern(std::string& pattern, std::string publicName);
SCError getSensorListForPattern(std::list<SensorId>& sensorIds, std::string pattern);
SCError getSensorListForPattern(std::list<SensorId>& sensorIds, std::string pattern, DCDBTimeStamp start, DCDBTimeStamp end);
SCError getSensorListForPattern(std::list<SensorId>& sensorIds, std::string pattern, TimeStamp start, TimeStamp end);
SCError setSensorScalingFactor(std::string publicName, double scalingFactor);
SCError setSensorUnit(std::string publicName, std::string unit);
SCError setSensorIntegrable(std::string publicName, bool integrable);
SensorConfig(DCDBConnection* conn);
SensorConfig(Connection* conn);
virtual ~SensorConfig();
};
} /* End of namespace DCDB */
#endif /* CONFIG_H */
#endif /* DCDB_SENSORCONFIG_H */
......@@ -21,8 +21,10 @@
#include "timestamp.h"
#include "connection.h"
#ifndef SENSORDATASTORE_H_
#define SENSORDATASTORE_H_
#ifndef DCDB_SENSORDATASTORE_H
#define DCDB_SENSORDATASTORE_H
namespace DCDB {
typedef enum {
SDS_OK,
......@@ -40,7 +42,7 @@ class SensorDataStoreReading
{
public:
SensorId sensorId;
DCDBTimeStamp timeStamp;
TimeStamp timeStamp;
int64_t value;
#if 0
......@@ -85,7 +87,7 @@ public:
* @param start Start of the time series.
* @param end End of the time series.
*/
void query(std::list<SensorDataStoreReading>& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end);
void query(std::list<SensorDataStoreReading>& result, SensorId& sid, TimeStamp& start, TimeStamp& end);
/**
* @brief This function queries the integrated value (val * sec)
......@@ -96,7 +98,7 @@ public:
* @param end End of the time series.
* @return SDS_OK if ok, SDS_EMPTYSET if not at least 2 readings in interval.
*/
SDSQueryResult querySum(int64_t& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end);
SDSQueryResult querySum(int64_t& result, SensorId& sid, TimeStamp& start, TimeStamp& end);
/**
* @brief This function truncates all sensor data that is older than
......@@ -109,10 +111,10 @@ public:
* @brief A shortcut constructor for a SensorDataStore object
* that allows accessing the data store through a
* connection that is already established.
* @param conn The DCDBConnection object of an established
* @param conn The Connection object of an established
* connection to Cassandra.
*/
SensorDataStore(DCDBConnection* conn);
SensorDataStore(Connection* conn);
/**
* @brief The standard destructor for a SensorDatStore object.
......@@ -120,5 +122,6 @@ public:
virtual ~SensorDataStore();
};
} /* End of namespace DCDB */
#endif /* SENSORDATASTORE_H_ */
#endif /* DCDB_SENSORDATASTORE_H */
......@@ -8,8 +8,10 @@
#include <cstdint>
#include <string>
#ifndef SENSORID_H
#define SENSORID_H
#ifndef DCDB_SENSORID_H
#define DCDB_SENSORID_H
namespace DCDB {
/* Ensure that the unions and structs are created without padding */
#pragma pack(push,1)
......@@ -122,4 +124,6 @@ public:
#pragma pack(pop)
#endif /* SENSORID_H */
} /* End of namespace DCDB */
#endif /* DCDB_SENSORID_H */
/*
* dcdbtimestamp.h
* timestamp.h
*
* Created on: Feb 18, 2015
* Author: Axel Auweter
......@@ -8,7 +8,7 @@
/**
* @file
* @brief This file is a companion to the sensordatastore API.
* It contains the DCDBTimeStamp class definition that helps in
* It contains the TimeStamp class definition that helps in
* creating and modifying timestamps in the SensorDataStore.
*/
......@@ -17,26 +17,28 @@
#include <string>
#include <stdexcept>
#ifndef DCDBTIMESTAMP_H
#define DCDBTIMESTAMP_H
#ifndef DCDB_TIMESTAMP_H
#define DCDB_TIMESTAMP_H
class DCDBTimeStampConversionException : public std::runtime_error
namespace DCDB {
class TimeStampConversionException : public std::runtime_error
{
public:
DCDBTimeStampConversionException():runtime_error("Time stamp conversion error.") {}
TimeStampConversionException():runtime_error("Time stamp conversion error.") {}
};
/**
* @brief The DCDBTimeStamp class contains a single TimeStamp.
* @brief The TimeStamp class contains a single TimeStamp.
*/
class DCDBTimeStamp
class TimeStamp
{
protected:
uint64_t raw; /**< The raw timestamp data (nanoseconds since Unix Epoch) */
/**
* @brief Parses a string and tries to derive the time from it by
* guessing the format. Throws DCDBTimeStampException on failure.
* guessing the format. Throws TimeStampException on failure.
* @param timestr A string containing a representation of time
* @param localTime Denotes if the timestr contains local time instead of UTC
*/
......@@ -47,27 +49,27 @@ public:
/**
* @brief Standard constructor. Initializes the object with the current time.
*/
DCDBTimeStamp();
TimeStamp();
/**
* @brief Raw constructor. Initializes the object with an existing raw time.
*/
DCDBTimeStamp(uint64_t ts) {raw = ts;}
TimeStamp(uint64_t ts) {raw = ts;}
/**
* @brief String constructor. Initializes the object by best guess from a time string.
*/
DCDBTimeStamp(std::string ts, bool localTime = false);
TimeStamp(std::string ts, bool localTime = false);
/**
* @brief Time_t constructor. Initializes the object from a time_t struct.
*/
DCDBTimeStamp(time_t ts);
TimeStamp(time_t ts);
/**
* @brief Standard destructor.
*/
virtual ~DCDBTimeStamp();
virtual ~TimeStamp();
/**
* @brief Sets the object's value to the current time.
......@@ -103,13 +105,14 @@ public:
uint16_t getWeekstamp(void);
/* Overloaded operators (compare raw values) */
inline bool operator == (const DCDBTimeStamp& rhs) const {return raw == rhs.raw;}
inline bool operator != (const DCDBTimeStamp& rhs) const {return raw != rhs.raw;}
inline bool operator < (const DCDBTimeStamp& rhs) const {return raw < rhs.raw;}
inline bool operator > (const DCDBTimeStamp& rhs) const {return raw > rhs.raw;}
inline bool operator <= (const DCDBTimeStamp& rhs) const {return raw <= rhs.raw;}
inline bool operator >= (const DCDBTimeStamp& rhs) const {return raw >= rhs.raw;}
inline bool operator == (const TimeStamp& rhs) const {return raw == rhs.raw;}
inline bool operator != (const TimeStamp& rhs) const {return raw != rhs.raw;}
inline bool operator < (const TimeStamp& rhs) const {return raw < rhs.raw;}
inline bool operator > (const TimeStamp& rhs) const {return raw > rhs.raw;}
inline bool operator <= (const TimeStamp& rhs) const {return raw <= rhs.raw;}
inline bool operator >= (const TimeStamp& rhs) const {return raw >= rhs.raw;}
};
} /* End of namespace DCDB */
#endif /* DCDBTIMESTAMP_H */
#endif /* DCDB_TIMESTAMP_H */
......@@ -5,68 +5,72 @@
* Author: Axel Auweter
*/
#ifndef UNITCONV_H
#define UNITCONV_H
#include <cstdint>
#include <string>
#ifndef DCDB_UNITCONV_H
#define DCDB_UNITCONV_H
namespace DCDB {
typedef enum {
/* Undefined */
DCDBUnit_None,
Unit_None,
/* Base units */
DCDBUnit_Meter,
DCDBUnit_Second,
DCDBUnit_Ampere,
DCDBUnit_Kelvin,
DCDBUnit_Watt,
DCDBUnit_Volt,
DCDBUnit_Hertz,
Unit_Meter,
Unit_Second,
Unit_Ampere,
Unit_Kelvin,
Unit_Watt,
Unit_Volt,
Unit_Hertz,
/* Others */
DCDBUnit_Celsius,
DCDBUnit_Fahrenheit,
Unit_Celsius,
Unit_Fahrenheit,
/* 1e3 */
DCDBUnit_KiloHertz,
Unit_KiloHertz,
/* 1e6 */
DCDBUnit_MegaHertz,
Unit_MegaHertz,
/* 1e9 */
DCDBUnit_GigaHertz,
Unit_GigaHertz,
/* 1e-2 */
DCDBUnit_CentiMeter,
DCDBUnit_CentiCelsius,
Unit_CentiMeter,
Unit_CentiCelsius,
/* 1e-3 */
DCDBUnit_MilliMeter,
DCDBUnit_MilliSecond,
DCDBUnit_MilliAmpere,
DCDBUnit_MilliKelvin,
DCDBUnit_MilliWatt,
DCDBUnit_MilliVolt,
DCDBUnit_MilliCelsius,
Unit_MilliMeter,
Unit_MilliSecond,
Unit_MilliAmpere,
Unit_MilliKelvin,
Unit_MilliWatt,
Unit_MilliVolt,
Unit_MilliCelsius,
/* 1e-6 */
DCDBUnit_MicroMeter,
DCDBUnit_MicroSecond,
DCDBUnit_MicroAmpere,
DCDBUnit_MicroKelvin,
DCDBUnit_MicroWatt,
DCDBUnit_MicroVolt,
DCDBUnit_MicroCelsius,
} DCDBUnit;
Unit_MicroMeter,
Unit_MicroSecond,
Unit_MicroAmpere,
Unit_MicroKelvin,
Unit_MicroWatt,
Unit_MicroVolt,
Unit_MicroCelsius,
} Unit;
class UnitConv
{
public:
static DCDBUnit fromString(std::string unit);
static std::string toString(DCDBUnit unit);
static bool convert(int64_t& value, DCDBUnit from, DCDBUnit to);
static bool convert(double& value, DCDBUnit from, DCDBUnit to);
static Unit fromString(std::string unit);
static std::string toString(Unit unit);
static bool convert(int64_t& value, Unit from, Unit to);
static bool convert(double& value, Unit from, Unit to);
};
#endif
} /* End of namespace DCDB */
#endif /* DCDB_UNITCONV_H */
......@@ -8,8 +8,8 @@
/*
* @file
* @brief This file contains the internal functions of the
* DCDBConnection which are provided by the
* DCDBConnectionImpl class.
* Connection which are provided by the
* ConnectionImpl class.
*/
#include <string>
......@@ -17,10 +17,12 @@
#include "connection.h"
#ifndef CONNECTION_INTERNAL_H
#define CONNECTION_INTERNAL_H
#ifndef DCDB_CONNECTION_INTERNAL_H
#define DCDB_CONNECTION_INTERNAL_H
class DCDBConnectionImpl
namespace DCDB {
class ConnectionImpl
{
protected:
std::string hostname_; /**< The hostname of a DB front-end node. */
......@@ -92,57 +94,59 @@ protected:
public:
/**
* @brief The implementation function of DCDBConnection::printError().
* @brief The implementation function of Connection::printError().
*/
void printError(CassFuture* future);
/**
* @brief The implementation function of DCDBConnection::setHostname().
* @brief The implementation function of Connection::setHostname().
*/
void setHostname(std::string hostname);
/**
* @brief The implementation function of DCDBConnection::getHostname().
* @brief The implementation function of Connection::getHostname().
*/
std::string getHostname();
/**
* @brief The implementation function of DCDBConnection::setPort().
* @brief The implementation function of Connection::setPort().
*/
void setPort(uint16_t port);
/**
* @brief The implementation function of DCDBConnection::getPort().
* @brief The implementation function of Connection::getPort().
*/
uint16_t getPort();
/**
* @brief The implementation function of DCDBConnection::connect().
* @brief The implementation function of Connection::connect().
*/
bool connect();
/**
* @brief The implementation function of DCDBConnection::disconnect().
* @brief The implementation function of Connection::disconnect().
*/
void disconnect();
/**
* @brief The implementation function of DCDBConnection::getSessionHandle().
* @brief The implementation function of Connection::getSessionHandle().
*/
CassSession* getSessionHandle();
/**
* @brief The implementation function of DCDBConnection::executeSimpleQuery().
* @brief The implementation function of Connection::executeSimpleQuery().
*/
CassError executeSimpleQuery(std::string query);
/**
* @brief The implementation function of DCDBConnection::initSchema().
* @brief The implementation function of Connection::initSchema().
*/
bool initSchema();
DCDBConnectionImpl();
virtual ~DCDBConnectionImpl();
ConnectionImpl();
virtual ~ConnectionImpl();
};
#endif /* CONNECTION_INTERNAL_H */
} /* End of namespace DCDB */
#endif /* DCDB_CONNECTION_INTERNAL_H */
......@@ -16,13 +16,15 @@
#include "sensorconfig.h"
#ifndef SENSORCONFIG_INTERNAL_H
#define SENSORCONFIG_INTERNAL_H
#ifndef DCDB_SENSORCONFIG_INTERNAL_H
#define DCDB_SENSORCONFIG_INTERNAL_H
namespace DCDB {
class SensorConfigImpl
{
protected:
DCDBConnection* connection;
Connection* connection;
CassSession* session;
bool validateSensorPattern(const char* sensorPattern);
......@@ -32,20 +34,22 @@ public:
SCError publishSensor(std::string publicName, std::string sensorPattern);
SCError unPublishSensor(std::string publicName);
SCError getPublicSensorNames(std::list<std::string>& publicSensors);
SCError getPublicSensorsVerbose(std::list<DCDBPublicSensor>& publicSensors);
SCError getPublicSensorsVerbose(std::list<PublicSensor>& publicSensors);
SCError getPublicSensorByName(DCDBPublicSensor& sensor, const char* publicName);
SCError getPublicSensorByName(PublicSensor& sensor, const char* publicName);
SCError getSensorPattern(std::string& pattern, std::string publicName);
SCError getSensorListForPattern(std::list<SensorId>& sensorIds, std::string pattern);
SCError getSensorListForPattern(std::list<SensorId>& sensorIds, std::string pattern, DCDBTimeStamp start, DCDBTimeStamp end);
SCError getSensorListForPattern(std::list<SensorId>& sensorIds, std::string pattern, TimeStamp start, TimeStamp end);
SCError setSensorScalingFactor(std::string publicName, double scalingFactor);
SCError setSensorUnit(std::string publicName, std::string unit);
SCError setSensorIntegrable(std::string publicName, bool integrable);
SensorConfigImpl(DCDBConnection* conn);
SensorConfigImpl(Connection* conn);
virtual ~SensorConfigImpl();
};
#endif /* SENSORCONFIG_INTERNAL_H */
} /* End of namespace DCDB */
#endif /* DCDB_SENSORCONFIG_INTERNAL_H */
/*
* dcdb_internal.h
* sensordatastore_internal.h
*
* Internal data structures and definitions for the DCDB Library
* Internal data structures and definitions for the DCDB SensorDataStore Class.
*
*/
......@@ -12,14 +12,16 @@
* SensorDataStoreImpl class.
*/
#ifndef DCDB_INTERNAL_H
#define DCDB_INTERNAL_H
#ifndef DCDB_SENSORDATASTORE_INTERNAL_H
#define DCDB_SENSORDATASTORE_INTERNAL_H
#include <string>
#include "sensordatastore.h"
#include "connection.h"
namespace DCDB {
/**
* @brief The SensorDataStoreImpl class contains all protected