Commit eb15a7a9 authored by Michael Ott's avatar Michael Ott
Browse files

Merge branch 'master' of ssh://deep-ras.srv.lrz.de/git/dcdb

parents e95d68ea 9569fef2
......@@ -126,7 +126,7 @@ void SensorDataStoreImpl::init(std::string hostname, int port) {
csBackend->createColumnFamily(CF_SENSORALIASES,
"name varchar, pattern varchar",
"name",
"CACHING = all");
"COMPACT STORAGE AND CACHING = all");
}
/* Keyspace and column family for raw sensor data */
......
......@@ -2,7 +2,7 @@ include ../../config.mk
CXXFLAGS = -O0 -g --std=c++11 -Wall -Wno-unused-local-typedefs -Wno-unknown-warning-option -fmessage-length=0 -I$(DCDBDEPLOYPATH)/include/ -I$(DCDBBASEPATH)/include/
OBJS = dcdbconfig.o sensoraction.o useraction.o casshelper.o
LIBS = -L$(DCDBDEPLOYPATH)/lib/ -ldcdb -lcassandra -lboost_random
LIBS = -L$(DCDBDEPLOYPATH)/lib/ -ldcdb -lcassandra -lboost_random -lboost_system -luv
#-lpthread -lboost_system -lboost_thread -lthrift
TARGET = dcdbconfig
......
......@@ -21,7 +21,7 @@ void usage(int argc, char* argv[])
std::cout << "Usage: " << argv[0] << " [-h host] <command> [<arguments> ... ]" << std::endl << std::endl;
std::cout << "Valid commands are: " << std::endl;
std::cout << " help <command name> - print help for given command" << std::endl;
std::cout << " sensors - list and configure sensors" << std::endl;
std::cout << " sensor - list and configure sensors" << std::endl;
}
int main(int argc, char* argv[])
......
......@@ -6,6 +6,7 @@
*/
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstring>
......@@ -15,6 +16,9 @@
#include "sensoraction.h"
#include "casshelper.h"
/*
* Print the help for the SENSOR command
*/
void SensorAction::printHelp(int argc, char* argv[])
{
std::cout << "SENSOR command help" << std::endl;
......@@ -24,7 +28,9 @@ void SensorAction::printHelp(int argc, char* argv[])
std::cout << " aliaslist - List all configured aliases." << std::endl;
}
/*
* Execute any of the SENSOR commands
*/
int SensorAction::executeCommand(int argc, char* argv[], int argvidx, const char* hostname)
{
/* Independent from the command, we need to connect to the server */
......@@ -74,14 +80,23 @@ executeCommandError:
return EXIT_FAILURE;
}
/*
* Add a Sensor Alias entry into the database
*/
void SensorAction::doAddAlias(CassSession* session, const char* aliasName, const char* aliasPattern)
{
/*
* FIXME: Should do some sanity checks before allowing this into the DB.
* FIXME: Merge the core functionality into DCDBLib and stick to the
* CONFIG_KEYSPACE_NAME/CF_SENSORALIASES instead of hard coding to
* dcdb_config.sensoralias
*/
/* Check if the pattern matches the requirements */
if (!validateAliasPattern(aliasPattern)) {
std::cout << "Invalid pattern. Alias was not added to database." << std::endl;
return;
}
CassError rc = CASS_OK;
CassStatement* statement = nullptr;
CassFuture* future = nullptr;
......@@ -116,6 +131,9 @@ void SensorAction::doAddAlias(CassSession* session, const char* aliasName, const
cass_statement_free(statement);
}
/*
* List all Sensor Alias entries from the database
*/
void SensorAction::doListAliases(CassSession* session)
{
CassError rc = CASS_OK;
......@@ -140,10 +158,85 @@ void SensorAction::doListAliases(CassSession* session)
const CassRow* row = cass_iterator_get_row(iterator);
cass_value_get_string(cass_row_get_column_by_name(row, "name"), &name);
cass_value_get_string(cass_row_get_column_by_name(row, "pattern"), &pattern);
std::cout << name.data << " : " << pattern.data << std::endl;
std::cout << std::string(name.data, name.length) << " : " << std::string(pattern.data, pattern.length) << std::endl;
}
cass_result_free(result);
cass_iterator_free(iterator);
}
}
/*
* Validate the pattern for a Sensor Alias
* Alias patterns may only consist of hex numbers and forward slashes
* and at most one wildcard character (*). Also, the total number of
* bits may not exceed 128.
*/
bool SensorAction::validateAliasPattern(const char* aliasPattern)
{
unsigned int wildcards, bits;
/* 128 bits in HEX is at most 32 characters. Considering forward-slash separators, 64 is a reasonable maxmimum string length */
if (strlen(aliasPattern) > 64) {
return false;
}
/* Iterate through the string and validate/count the characters */
bits = 0;
wildcards = 0;
for (unsigned int c = 0; c < strlen(aliasPattern); c++) {
switch (aliasPattern[c]) {
/* Regular HEX digit */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'a':
case 'A':
case 'b':
case 'B':
case 'c':
case 'C':
case 'd':
case 'D':
case 'e':
case 'E':
case 'f':
case 'F':
bits += 4;
break;
/* Wildcard */
case '*':
wildcards++;
break;
/* Forward slash */
case '/':
break;
/* Everything else is not allowed */
default:
return false;
}
}
/* More than one wildcard is not allowed */
if (wildcards > 1)
return false;
/* In case of a wildcard, there should be some bits left for the wildcard to fill in */
if (wildcards == 1 && bits >= 128)
return false;
/* Looks good */
return true;
}
......@@ -21,6 +21,8 @@ public:
protected:
void doListAliases(CassSession* session);
void doAddAlias(CassSession* session, const char* aliasName, const char* aliasPattern);
bool validateAliasPattern(const char* aliasPattern);
};
#endif
......@@ -254,8 +254,9 @@ $(DCDBDEPSPATH)/.prerequesites: $(DCDBDEPSPATH)/.extract-distfiles
fi; \
mkdir -p $(DCDBDEPSPATH)/cpp-driver_build; \
cd $(DCDBDEPSPATH)/cpp-driver_build && \
cmake -DCMAKE_CXX_FLAGS="$(CXX11FLAGS)" \
cmake -DCMAKE_CXX_FLAGS="$(CXX11FLAGS) -Wno-unused-command-line-argument -L$(DCDBDEPLOYPATH)/lib " \
-DCASS_USE_EXTERNAL_BOOST=YES \
-DCASS_BUILD_EXAMPLES=NO \
-DINSTALL_LIB_DIR=lib \
-DCMAKE_INSTALL_PREFIX=$(DCDBDEPLOYPATH)/ \
-DCMAKE_EXE_LINKER_FLAGS="-L$(DCDBDEPLOYPATH)/lib -lboost_random" \
......
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