Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing 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 25835b1e authored by Daniele Tafani's avatar Daniele Tafani
Browse files

Introduced a bit mask for sensor properties in dcdblib and dcdbconfig (e.g.,...

Introduced a bit mask for sensor properties in dcdblib and dcdbconfig (e.g., integrable, monotonic,...)
parent 01d7167d
//================================================================================
// Name : sensorconfig.h
// Author : Axel Auweter
// Author : Axel Auweter, Daniele Tafani
// Copyright : Leibniz Supercomputing Centre
// Description : C++ API for configuring libdcdb public sensors.
//================================================================================
......@@ -61,7 +61,7 @@ public:
std::string pattern; /**< For non-virtual sensors, this holds a pattern describing the (internal) sensor IDs to which this public sensor matches. */
double scaling_factor; /**< Scaling factor for every sensor reading */
std::string unit; /**< Describes the unit of the sensor. See unitconv.h for known units. */
bool integrable; /**< Determines this sensor as being integrable. */
uint64_t sensor_mask; /**< Determines the properties of the sensor. Currently defined are: integrable, monotonic. */
std::string expression; /**< For virtual sensors, this field holds the expression through which the virtual sensor's value is calculated. */
std::string v_sensorid; /**< For virtual sensors, this field holds a SensorID used for storing cached values in the database. (FIXME: Cache to be implemented) */
uint64_t t_zero; /**< For virtual sensors, this field holds the first point in time at which the sensor carries a value. */
......@@ -87,6 +87,9 @@ typedef enum {
SC_UNKNOWNERROR /**< An unknown error occurred */
} SCError;
#define INTEGRABLE 1
#define MONOTONIC 2
/**
* This class holds all functions to create/delete/modify the configuration of (virtual and non-virtual) public sensors in DCDB.
*/
......@@ -212,13 +215,13 @@ public:
SCError setSensorUnit(std::string publicName, std::string unit);
/**
* @brief Set a sensor integrable or not.
* @brief Set a sensor property with a mask. Currently implemented properties are "integrable" and "monotonic".
*
* @param publicName Name of the sensor.
* @param integrable New integrable setting for the sensor.
* @param mask New bit mask for the sensor properties.
* @return See SCError.
*/
SCError setSensorIntegrable(std::string publicName, bool integrable);
SCError setSensorMask(std::string publicName, uint64_t mask);
/**
* @brief Set a new sensor expression for a virtual sensor.
......
//================================================================================
// Name : sensorconfig_internal.h
// Author : Axel Auweter
// Author : Axel Auweter, Daniele Tafani
// Copyright : Leibniz Supercomputing Centre
// Description : Internal Interface for configuring libdcdb public sensors.
//================================================================================
......@@ -70,7 +70,7 @@ public:
SCError setSensorScalingFactor(std::string publicName, double scalingFactor);
SCError setSensorUnit(std::string publicName, std::string unit);
SCError setSensorIntegrable(std::string publicName, bool integrable);
SCError setSensorMask(std::string publicName, uint64_t mask);
SCError setVirtualSensorExpression(std::string publicName, std::string expression);
SCError setVirtualSensorTZero(std::string publicName, TimeStamp tZero);
......
//================================================================================
// Name : c_api.cpp
// Author : Axel Auweter
// Author : Axel Auweter, Daniele Tafani
// Copyright : Leibniz Supercomputing Centre
// Description : C API Implementation for libdcdb
//================================================================================
......@@ -97,7 +97,7 @@ DCDB_C_RESULT dcdbQuerySum(
PublicSensor sensorProperties;
switch (sensorConfig.getPublicSensorByName(sensorProperties, sensorPublicName)) {
case SC_OK:
if (!sensorProperties.integrable) {
if ((sensorProperties.sensor_mask & INTEGRABLE) == INTEGRABLE) {
delete connection;
return DCDB_C_NOTINTEGRABLE;
}
......@@ -202,7 +202,7 @@ DCDB_C_RESULT dcdbQuerySumMultiple(
PublicSensor sensorProperties;
switch (sensorConfig.getPublicSensorByName(sensorProperties, sensorPublicName[i])) {
case SC_OK:
if (!sensorProperties.integrable) {
if ((sensorProperties.sensor_mask & INTEGRABLE) == INTEGRABLE) {
delete connection;
return DCDB_C_NOTINTEGRABLE;
}
......@@ -382,7 +382,7 @@ DCDB_C_RESULT dcdbQuerySumMultipleThreaded(
PublicSensor sensorProperties;
switch (sensorConfig.getPublicSensorByName(sensorProperties, sensorPublicName[i])) {
case SC_OK:
if (!sensorProperties.integrable) {
if ((sensorProperties.sensor_mask & INTEGRABLE) == INTEGRABLE) {
delete connection;
return DCDB_C_NOTINTEGRABLE;
}
......
//================================================================================
// Name : connection.cpp
// Author : Axel Auweter
// Author : Axel Auweter, Daniele Tafani
// Copyright : Leibniz Supercomputing Centre
// Description : C++ API implementation for libdcdb connections
//================================================================================
......@@ -419,7 +419,9 @@ bool ConnectionImpl::initSchema() {
"pattern varchar, " /* In case of physical sensors: pattern for MQTT topics that this sensor matches against */
"scaling_factor double, " /* Unused */
"unit varchar, " /* Unit of the sensor (e.g. W for Watts) */
"integrable boolean, " /* Indicates whether the sensor is integrable over time */
"sensor_mask bigint, " /* Bit mask that specifies sensor properties. Currently defined ones are:
Integrable: indicates whether the sensor is integrable over time;
Monotonic : indicates whether the collected sensor data is monotonic. */
"expression varchar, " /* For virtual sensors: arithmetic expression to derive the virtual sensor's value */
"vsensorid varchar, " /* For virtual sensors: Unique sensorId for the sensor in the virtualsensors table */
"tzero bigint, " /* For virtual sensors: time of the first reading */
......
//================================================================================
// Name : sensorconfig.cpp
// Author : Axel Auweter
// Author : Axel Auweter, Daniele Tafani
// Copyright : Leibniz Supercomputing Centre
// Description : C++ API implementation for configuring libdcdb public sensors.
//================================================================================
......@@ -51,7 +51,7 @@ PublicSensor::PublicSensor()
pattern = "";
scaling_factor = 1.0;
unit = "";
integrable = false;
sensor_mask = 0;
expression = "";
v_sensorid = "";
t_zero = 0;
......@@ -65,7 +65,7 @@ PublicSensor::PublicSensor (const PublicSensor &copy)
pattern = copy.pattern;
scaling_factor = copy.scaling_factor;
unit = copy.unit;
integrable = copy.integrable;
sensor_mask = copy.sensor_mask;
expression = copy.expression;
v_sensorid = copy.v_sensorid;
t_zero = copy.t_zero;
......@@ -135,9 +135,9 @@ SCError SensorConfig::setSensorUnit(std::string publicName, std::string unit)
return impl->setSensorUnit(publicName, unit);
}
SCError SensorConfig::setSensorIntegrable(std::string publicName, bool integrable)
SCError SensorConfig::setSensorMask(std::string publicName, uint64_t mask)
{
return impl->setSensorIntegrable(publicName, integrable);
return impl->setSensorMask(publicName, mask);
}
SCError SensorConfig::setVirtualSensorExpression(std::string publicName, std::string expression)
......@@ -555,7 +555,7 @@ SCError SensorConfigImpl::getPublicSensorsVerbose(std::list<PublicSensor>& publi
double scaling_factor;
const char* unit;
size_t unit_len;
cass_bool_t integrable;
int64_t sensor_mask;
const char* expression;
size_t expression_len;
const char* vsensorid;
......@@ -581,8 +581,8 @@ SCError SensorConfigImpl::getPublicSensorsVerbose(std::list<PublicSensor>& publi
if (cass_value_get_string(cass_row_get_column_by_name(row, "unit"), &unit, &unit_len) != CASS_OK) {
unit = ""; unit_len = 0;
}
if (cass_value_get_bool(cass_row_get_column_by_name(row, "integrable"), &integrable) != CASS_OK) {
integrable = cass_false;
if (cass_value_get_int64(cass_row_get_column_by_name(row, "sensor_mask"), &sensor_mask) != CASS_OK) {
sensor_mask = 0;
}
if (cass_value_get_string(cass_row_get_column_by_name(row, "expression"), &expression, &expression_len) != CASS_OK) {
expression = ""; expression_len = 0;
......@@ -602,7 +602,7 @@ SCError SensorConfigImpl::getPublicSensorsVerbose(std::list<PublicSensor>& publi
sensor.pattern = std::string(pattern, pattern_len);
sensor.scaling_factor = scaling_factor;
sensor.unit = std::string(unit, unit_len);
sensor.integrable = integrable == cass_true ? true: false;
sensor.sensor_mask = sensor_mask;
sensor.expression = std::string(expression, expression_len);
sensor.v_sensorid = std::string(vsensorid, vsensorid_len);
sensor.t_zero = tzero;
......@@ -679,7 +679,7 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
double scaling_factor;
const char* unit;
size_t unit_len;
cass_bool_t integrable;
int64_t sensor_mask;
const char* expression;
size_t expression_len;
const char* vsensorid;
......@@ -704,8 +704,8 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
if (cass_value_get_string(cass_row_get_column_by_name(row, "unit"), &unit, &unit_len) != CASS_OK) {
unit = ""; unit_len = 0;
}
if (cass_value_get_bool(cass_row_get_column_by_name(row, "integrable"), &integrable) != CASS_OK) {
integrable = cass_false;
if (cass_value_get_int64(cass_row_get_column_by_name(row, "sensor_mask"), &sensor_mask) != CASS_OK) {
sensor_mask = 0;
}
if (cass_value_get_string(cass_row_get_column_by_name(row, "expression"), &expression, &expression_len) != CASS_OK) {
expression = ""; expression_len = 0;
......@@ -725,7 +725,7 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
sensor.pattern = std::string(pattern, pattern_len);
sensor.scaling_factor = scaling_factor;
sensor.unit = std::string(unit, unit_len);
sensor.integrable = integrable == cass_true ? true: false;
sensor.sensor_mask = sensor_mask;
sensor.expression = std::string(expression, expression_len);
sensor.v_sensorid = std::string(vsensorid, vsensorid_len);
sensor.t_zero = tzero;
......@@ -1081,7 +1081,7 @@ SCError SensorConfigImpl::setSensorUnit(std::string publicName, std::string unit
return error;
}
SCError SensorConfigImpl::setSensorIntegrable(std::string publicName, bool integrable)
SCError SensorConfigImpl::setSensorMask(std::string publicName, uint64_t mask)
{
SCError error = SC_UNKNOWNERROR;
......@@ -1090,7 +1090,7 @@ SCError SensorConfigImpl::setSensorIntegrable(std::string publicName, bool integ
CassStatement* statement = nullptr;
CassFuture* future = nullptr;
const CassPrepared* prepared = nullptr;
const char* query = "UPDATE " CONFIG_KEYSPACE_NAME "." CF_PUBLISHEDSENSORS " SET integrable = ? WHERE name = ? ;";
const char* query = "UPDATE " CONFIG_KEYSPACE_NAME "." CF_PUBLISHEDSENSORS " SET sensor_mask = ? WHERE name = ? ;";
future = cass_session_prepare(session, query);
cass_future_wait(future);
......@@ -1106,7 +1106,7 @@ SCError SensorConfigImpl::setSensorIntegrable(std::string publicName, bool integ
statement = cass_prepared_bind(prepared);
cass_statement_bind_bool(statement, 0, integrable == true ? cass_true : cass_false);
cass_statement_bind_int64(statement, 0, mask);
cass_statement_bind_string(statement, 1, publicName.c_str());
future = cass_session_execute(session, statement);
......
//================================================================================
// Name : sensoraction.cpp
// Author : Axel Auweter
// Author : Axel Auweter, Daniele Tafani
// Copyright : Leibniz Supercomputing Centre
// Description : Implementation of actions on the DCDB sensor configuration
//================================================================================
......@@ -44,25 +44,27 @@ void SensorAction::printHelp(int argc, char* argv[])
/* 01234567890123456789012345678901234567890123456789012345678901234567890123456789 */
std::cout << "SENSOR command help" << std::endl << std::endl;
std::cout << "The SENSOR command has the following options:" << std::endl;
std::cout << " PUBLISH <public name> <pattern> - Make a sensor publicly available under" << std::endl;
std::cout << " <public name> comprising of all internal" << std::endl;
std::cout << " sensors matching the given <pattern>." << std::endl;
std::cout << " PUBLISH <public name> <pattern> - Make a sensor publicly available under" << std::endl;
std::cout << " <public name> comprising of all internal" << std::endl;
std::cout << " sensors matching the given <pattern>." << std::endl;
std::cout << " VCREATE <public name> <expr> <vsensorid> <t0> <freq>" << std::endl;
std::cout << " - Create a virtual public sensor that is" << std::endl;
std::cout << " visible as <public name> and evaluates" << std::endl;
std::cout << " <expr> starting at time t0 every <freq>" << std::endl;
std::cout << " nanoseconds. Cached values are stored" << std::endl;
std::cout << " under the unique <vsensorid>." << std::endl;
std::cout << " LIST - List all public sensors." << std::endl;
std::cout << " LISTPUBLIC - Same as LIST, includes patterns." << std::endl;
std::cout << " SHOW <public name> - Show details for a given sensor." << std::endl;
std::cout << " SCALINGFACTOR <public name> <fac> - Set scaling factor to <fac>." << std::endl;
std::cout << " UNIT <public name> <unit> - Set unit to <unit>." << std::endl;
std::cout << " INTEGRABLE <public name> [ON|OFF] - Mark sensor integrable." << std::endl;
std::cout << " EXPRESSION <public name> <expr> - Change expression of virt sensor." << std::endl;
std::cout << " TZERO <public name> <t0> - Change t0 of virt sensor." << std::endl;
std::cout << " FREQUENCY <public name> <freq> - Change frequency of virt sensor." << std::endl;
std::cout << " UNPUBLISH <public name> - Unpublish a sensor." << std::endl;
std::cout << " - Create a virtual public sensor that is" << std::endl;
std::cout << " visible as <public name> and evaluates" << std::endl;
std::cout << " <expr> starting at time t0 every <freq>" << std::endl;
std::cout << " nanoseconds. Cached values are stored" << std::endl;
std::cout << " under the unique <vsensorid>." << std::endl;
std::cout << " LIST - List all public sensors." << std::endl;
std::cout << " LISTPUBLIC - Same as LIST, includes patterns." << std::endl;
std::cout << " SHOW <public name> - Show details for a given sensor." << std::endl;
std::cout << " SCALINGFACTOR <public name> <fac> - Set scaling factor to <fac>." << std::endl;
std::cout << " UNIT <public name> <unit> - Set unit to <unit>." << std::endl;
std::cout << " SENSORPROPERTY <public name> <sensor property>,<sensor property>,..." << std::endl;
std::cout << " - Set sensor properties. Currently defined are: " << std::endl;
std::cout << " 'integrable' and 'monotonic'." << std::endl;
std::cout << " EXPRESSION <public name> <expr> - Change expression of virt sensor." << std::endl;
std::cout << " TZERO <public name> <t0> - Change t0 of virt sensor." << std::endl;
std::cout << " FREQUENCY <public name> <freq> - Change frequency of virt sensor." << std::endl;
std::cout << " UNPUBLISH <public name> - Unpublish a sensor." << std::endl;
}
/*
......@@ -131,13 +133,13 @@ int SensorAction::executeCommand(int argc, char* argv[], int argvidx, const char
}
doUnit(argv[argvidx+1], argv[argvidx+2]);
}
else if (strcasecmp(argv[argvidx], "INTEGRABLE") == 0) {
else if (strcasecmp(argv[argvidx], "SENSORPROPERTY") == 0) {
/* INTEGRABLE needs two more parameters */
if (argvidx+2 >= argc) {
std::cout << "INTEGRABLE needs two more parameters!" << std::endl;
std::cout << "SENSORPROPERTY needs two more parameters!" << std::endl;
goto executeCommandError;
}
doIntegrable(argv[argvidx+1], argv[argvidx+2]);
doSensorProperty(argv[argvidx+1], argv[argvidx+2]);
}
else if (strcasecmp(argv[argvidx], "EXPRESSION") == 0) {
/* EXPRESSION needs two more parameters */
......@@ -292,7 +294,7 @@ void SensorAction::doListPublicSensors()
}
/*
* Show the details for a given sensor
* Show the details for a given sensor TODO:Change Integrable
*/
void SensorAction::doShow(const char* publicName)
{
......@@ -316,7 +318,12 @@ void SensorAction::doShow(const char* publicName)
}
std::cout << "Unit: " << publicSensor.unit << std::endl;
std::cout << "Scaling factor: " << publicSensor.scaling_factor << std::endl;
std::cout << "Integrable: " << (publicSensor.integrable ? "true" : "false") << std::endl;
std::cout << "Sensor Properties: ";
if((publicSensor.sensor_mask & INTEGRABLE) == INTEGRABLE)
std::cout << "Integrable ";
if((publicSensor.sensor_mask & MONOTONIC) == MONOTONIC)
std::cout << "Monotonic ";
std::cout << std::endl;
break;
case DCDB::SC_UNKNOWNSENSOR:
std::cout << "Unknown sensor name: " << publicName << std::endl;
......@@ -381,7 +388,7 @@ void SensorAction::doUnit(const char* publicName, const char* unit)
/*
* Set or unset the integrable flag for a sensor
*/
void SensorAction::doIntegrable(const char* publicName, const char* cmd)
void SensorAction::doSensorProperty(const char* publicName, const char* cmd)
{
DCDB::SensorConfig sensorConfig(connection);
DCDB::PublicSensor publicSensor;
......@@ -389,27 +396,25 @@ void SensorAction::doIntegrable(const char* publicName, const char* cmd)
switch (err) {
case DCDB::SC_OK:
if ((strcasecmp(cmd, "TRUE") == 0) ||
(strcasecmp(cmd, "ON") == 0) ||
(strcasecmp(cmd, "ENABLE") == 0) ||
(strcasecmp(cmd, "1") == 0)) {
if (publicSensor.integrable == false) {
sensorConfig.setSensorIntegrable(publicName, true);
}
}
else if ((strcasecmp(cmd, "FALSE") == 0) ||
(strcasecmp(cmd, "OFF") == 0) ||
(strcasecmp(cmd, "DISABLE") == 0) ||
(strcasecmp(cmd, "0") == 0)) {
if (publicSensor.integrable == true) {
sensorConfig.setSensorIntegrable(publicName, false);
}
}
else {
std::cout << "Unknown option: " << cmd << std::endl;
std::cout << "Please specify TRUE or FALSE" << std::endl;
}
break;
{
uint64_t mask = publicSensor.sensor_mask;
if(strcasestr(cmd,"integrable") && (mask & INTEGRABLE) != INTEGRABLE)
mask = mask | INTEGRABLE;
if(strcasestr(cmd, "monotonic") && (mask & MONOTONIC) != MONOTONIC)
mask = mask | MONOTONIC;
if(!strcasestr(cmd, "integrable") && !strcasestr(cmd, "monotonic")) {
std::cout << "Unknown option: " << cmd << std::endl;
std::cout << "Please specify a sensor property: INTEGRABLE and/or MONOTONIC" << std::endl;
}
if(mask != publicSensor.sensor_mask)
sensorConfig.setSensorMask(publicName, mask);
break;
}
case DCDB::SC_UNKNOWNSENSOR:
std::cout << "Unknown sensor name: " << publicName << std::endl;
break;
......
......@@ -51,7 +51,7 @@ protected:
void doShow(const char* publicName);
void doScalingfactor(const char* publicName, const char* factor);
void doUnit(const char* publicName, const char* unit);
void doIntegrable(const char* publicName, const char* cmd);
void doSensorProperty(const char* publicName, const char* cmd);
void doExpression(const char* publicName, const char* expression);
void doTZero(const char* publicName, const char* tZero);
void doFrequency(const char* publicName, const char *frequency);
......
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