Commit 834246bb authored by Alessio Netti's avatar Alessio Netti

libdcdb: unpublishing sensors and clearing operations by wildcard

parent 5cb934b8
......@@ -166,6 +166,14 @@ public:
*/
SCError unPublishSensor(const char* publicName);
/**
* @brief Removes one or more sensors from the list of public sensors using a wildcard.
*
* @param wildcard Wildcard used to identify the sensors to be removed
* @return See SCError.
*/
SCError unPublishSensorsByWildcard(const char* wildcard);
/**
* @brief Get the entire list of (virtual or non-virtual) public sensors.
*
......@@ -296,6 +304,14 @@ public:
*/
SCError clearOperations(std::string publicName);
/**
* @brief Removes all operations of all sensors matching a given wildcard.
*
* @param wildcard Wildcard to identify sensors whose operations must be cleared.
* @return See SCError.
*/
SCError clearOperationsByWildcard(std::string wildcard);
/**
* @brief Set a new sensor expression for a virtual sensor.
*
......
......@@ -64,6 +64,7 @@ public:
SCError publishSensor(const SensorMetadata& sensor);
SCError publishVirtualSensor(std::string publicName, std::string vSensorExpression, std::string vSensorId, TimeStamp tZero, uint64_t interval);
SCError unPublishSensor(std::string publicName);
SCError unPublishSensorsByWildcard(std::string wildcard);
SCError getPublicSensorNames(std::list<std::string>& publicSensors);
SCError getPublicSensorsVerbose(std::list<PublicSensor>& publicSensors);
......@@ -82,6 +83,7 @@ public:
SCError setSensorMask(std::string publicName, uint64_t mask);
SCError setOperations(std::string publicName, std::set<std::string> operations);
SCError clearOperations(std::string publicName);
SCError clearOperationsByWildcard(std::string wildcard);
SCError setTimeToLive(std::string publicName, uint64_t ttl);
SCError setSensorInterval(std::string publicName, uint64_t interval);
......
......@@ -112,6 +112,11 @@ SCError SensorConfig::unPublishSensor(const char* publicName)
return impl->unPublishSensor(publicName);
}
SCError SensorConfig::unPublishSensorsByWildcard(const char* wildcard)
{
return impl->unPublishSensorsByWildcard(wildcard);
}
SCError SensorConfig::getPublicSensorNames(std::list<std::string>& publicSensors)
{
return impl->getPublicSensorNames(publicSensors);
......@@ -181,6 +186,11 @@ SCError SensorConfig::clearOperations(std::string publicName)
return impl->clearOperations(publicName);
}
SCError SensorConfig::clearOperationsByWildcard(std::string wildcard)
{
return impl->clearOperationsByWildcard(wildcard);
}
SCError SensorConfig::setTimeToLive(std::string publicName, uint64_t ttl)
{
return impl->setTimeToLive(publicName, ttl);
......@@ -674,6 +684,21 @@ SCError SensorConfigImpl::unPublishSensor(std::string publicName)
return SC_OK;
}
SCError SensorConfigImpl::unPublishSensorsByWildcard(std::string wildcard)
{
std::list<PublicSensor> sensors;
if(getPublicSensorsByWildcard(sensors, wildcard.c_str())!=SC_OK)
return SC_UNKNOWNERROR;
for(const auto& s : sensors) {
if (unPublishSensor(s.name.c_str()) != SC_OK) {
return SC_UNKNOWNERROR;
}
}
return SC_OK;
}
SCError SensorConfigImpl::getPublicSensorNames(std::list<std::string>& publicSensors)
{
/* Check if the session is valid */
......@@ -1593,6 +1618,21 @@ SCError SensorConfigImpl::clearOperations(std::string publicName)
return error;
}
SCError SensorConfigImpl::clearOperationsByWildcard(std::string wildcard)
{
std::list<PublicSensor> sensors;
if(getPublicSensorsByWildcard(sensors, wildcard.c_str())!=SC_OK)
return SC_UNKNOWNERROR;
for(const auto& s : sensors) {
if(clearOperations(s.name) != SC_OK) {
return SC_UNKNOWNERROR;
}
}
return SC_OK;
}
SCError SensorConfigImpl::setTimeToLive(std::string publicName, uint64_t ttl)
{
SCError error = SC_UNKNOWNERROR;
......
......@@ -45,7 +45,7 @@ _dcdbconfig_options()
fi
elif [ "${COMP_WORDS[${toplevel_command_at}]}" = "sensor" ]; then
if [ "${num_args}" -eq "$((${toplevel_command_at}+2))" ]; then
comrep="publish vcreate list listpublic show scalingfactor unit integrable expression tzero frequency unpublish"
comrep="publish vcreate list listpublic show scalingfactor unit ttl integrable expression operations clearoperations clearoperationsw tzero frequency unpublish unpublishw"
fi
if [ "${COMP_WORDS[$((${toplevel_command_at}+1))]}" = "show" ] && [ "${num_args}" -eq "$((${toplevel_command_at}+3))" ]; then
comrep=$(dcdbconfig ${hostname_str} sensor list 2> /dev/null)
......@@ -74,6 +74,9 @@ _dcdbconfig_options()
if [ "${COMP_WORDS[$((${toplevel_command_at}+1))]}" = "unpublish" ] && [ "${num_args}" -eq "$((${toplevel_command_at}+3))" ]; then
comrep=$(dcdbconfig ${hostname_str} sensor list 2> /dev/null)
fi
if [ "${COMP_WORDS[$((${toplevel_command_at}+1))]}" = "unpublishw" ] && [ "${num_args}" -eq "$((${toplevel_command_at}+3))" ]; then
comrep=$(dcdbconfig ${hostname_str} sensor list 2> /dev/null)
fi
elif [ "${COMP_WORDS[${toplevel_command_at}]}" = "db" ]; then
if [ "${num_args}" -eq "$((${toplevel_command_at}+2))" ]; then
comrep="insert fuzzytrunc"
......
......@@ -71,7 +71,9 @@ void SensorAction::printHelp(int argc, char* argv[])
std::cout << " OPERATIONS <public name> <operation>,<operation>,..." << std::endl;
std::cout << " - Set operations for the sensor (e.g., avg, stddev,...)." << std::endl;
std::cout << " CLEAROPERATIONS <public name> - Remove all existing operations for the sensor." << std::endl;
std::cout << " CLEAROPERATIONSW <wildcard> - Remove operations from sensors using a wildcard." << std::endl;
std::cout << " UNPUBLISH <public name> - Unpublish a sensor." << std::endl;
std::cout << " UNPUBLISHW <wildcard> - Unpublish sensors using a wildcard." << std::endl;
}
/*
......@@ -196,13 +198,29 @@ int SensorAction::executeCommand(int argc, char* argv[], int argvidx, const char
}
doClearOperations(argv[argvidx+1]);
}
else if (strcasecmp(argv[argvidx], "CLEAROPERATIONSW") == 0) {
/* CLEAROPERATIONSW needs one more parameter */
if (argvidx+1 >= argc) {
std::cout << "CLEAROPERATIONSW needs one more parameter!" << std::endl;
goto executeCommandError;
}
doClearOperationsByWildcard(argv[argvidx+1]);
}
else if (strcasecmp(argv[argvidx], "UNPUBLISH") == 0) {
/* UNPUBLISH needs one more parameter */
if (argvidx+1 >= argc) {
if (argvidx + 1 >= argc) {
std::cout << "UNPUBLISH needs a parameter!" << std::endl;
goto executeCommandError;
}
doUnPublishSensor(argv[argvidx+1]);
doUnPublishSensor(argv[argvidx + 1]);
}
else if (strcasecmp(argv[argvidx], "UNPUBLISHW") == 0) {
/* UNPUBLISHW needs one more parameter */
if (argvidx+1 >= argc) {
std::cout << "UNPUBLISHW needs a parameter!" << std::endl;
goto executeCommandError;
}
doUnPublishSensorsByWildcard(argv[argvidx+1]);
}
else {
std::cout << "Invalid SENSOR command: " << argv[argvidx] << std::endl;
......@@ -611,6 +629,22 @@ void SensorAction::doClearOperations(const char* publicName)
}
}
void SensorAction::doClearOperationsByWildcard(const char* wildcard)
{
DCDB::SensorConfig sensorConfig(connection);
DCDB::SCError err = sensorConfig.clearOperationsByWildcard(wildcard);
switch (err) {
case DCDB::SC_OK:
break;
case DCDB::SC_INVALIDSESSION:
std::cout << "Invalid session!" << std::endl;
break;
default:
std::cout << "Internal error." << std::endl;
}
}
/*
* Unpublish a sensor
*/
......@@ -619,3 +653,9 @@ void SensorAction::doUnPublishSensor(const char* publicName)
DCDB::SensorConfig sensorConfig(connection);
sensorConfig.unPublishSensor(publicName);
}
void SensorAction::doUnPublishSensorsByWildcard(const char* wildcard)
{
DCDB::SensorConfig sensorConfig(connection);
sensorConfig.unPublishSensorsByWildcard(wildcard);
}
......@@ -59,7 +59,9 @@ protected:
void doTTL(const char* publicName, const char *ttl);
void doOperations(const char* publicName, const char *operations);
void doClearOperations(const char* publicName);
void doClearOperationsByWildcard(const char* wildcard);
void doUnPublishSensor(const char* publicName);
void doUnPublishSensorsByWildcard(const char* wildcard);
};
#endif
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