Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
260e8814
Commit
260e8814
authored
Oct 28, 2014
by
Axel Auweter
Browse files
Namespace cleanups...
parent
68e42b36
Changes
3
Hide whitespace changes
Inline
Side-by-side
DCDBLib/include_internal/cassandraBackend.h
View file @
260e8814
...
...
@@ -18,6 +18,8 @@
#include
<sys/socket.h>
#include
<netinet/in.h>
#include
<string>
#include
<boost/lexical_cast.hpp>
#include
<thrift/Thrift.h>
...
...
@@ -35,7 +37,6 @@ using namespace apache::thrift;
using
namespace
apache
::
thrift
::
transport
;
using
namespace
apache
::
thrift
::
protocol
;
using
namespace
org
::
apache
::
cassandra
;
using
namespace
std
;
/**
* @brief The CassandraBackend class provides low-level
...
...
@@ -47,7 +48,7 @@ class CassandraBackend
protected:
CassandraClient
*
myClient
;
/**< The main object provided by the Thrift API for us */
std
::
vector
<
KsDef
>
keySpaces
;
/**< A vector containing a local copy of the keyspace definitions */
string
clusterName
;
/**< The name of the cluster that we're connecting to */
std
::
string
clusterName
;
/**< The name of the cluster that we're connecting to */
boost
::
shared_ptr
<
TSocket
>
sock
;
/**< A boost TSocket object for our connection */
boost
::
shared_ptr
<
TTransport
>
tr
;
/**< A boost TTransport object sitting on top of the TSocket sock */
boost
::
shared_ptr
<
TProtocol
>
prot
;
/**< A boost TProtocol object sitting on top of the TTransport tr */
...
...
@@ -58,7 +59,7 @@ protected:
* @param name A string to check
* @return True if the name is alphanumeric, false otherwise
*/
bool
validateName
(
string
name
);
bool
validateName
(
std
::
string
name
);
/**
* @brief This function converts a uint64_t into a big-endian
...
...
@@ -66,7 +67,7 @@ protected:
* @param n The value to convert
* @return The string containing the big-endian byte array.
*/
string
int64Convert
(
uint64_t
n
);
std
::
string
int64Convert
(
uint64_t
n
);
public:
/* FIXME - make currentKeySpace protected! */
...
...
@@ -79,7 +80,7 @@ public:
* @param hostname The hostname to connect to.
* @param port The TCP port number on which Cassandra is listening for Thrift clients.
*/
void
connect
(
string
hostname
,
int
port
);
void
connect
(
std
::
string
hostname
,
int
port
);
/**
* @brief Fetch the list of Key Spaces from the Cassandra server.
...
...
@@ -91,20 +92,20 @@ public:
* @param name The name of the keyspace to look for.
* @return True if the keyspace exists, false otherwise.
*/
bool
existsKeyspace
(
string
name
);
bool
existsKeyspace
(
std
::
string
name
);
/**
* @brief Create a new keyspace.
* @param name The name of the new keyspace
* @param replicationFactor The Cassandra replication factor
*/
void
createKeyspace
(
string
name
,
int
replicationFactor
);
void
createKeyspace
(
std
::
string
name
,
int
replicationFactor
);
/**
* @brief Specify a keyspace to use in this connection.
* @param name The name of the keyspace to select.
*/
void
selectKeyspace
(
string
name
);
void
selectKeyspace
(
std
::
string
name
);
/**
* @brief Check if a column family with a given name
...
...
@@ -112,7 +113,7 @@ public:
* @param name The name of the column family to look for.
* @return True if the column family exists in the current keyspace, false otherwise.
*/
bool
existsColumnFamily
(
string
name
);
bool
existsColumnFamily
(
std
::
string
name
);
/**
* @brief Create a new column family in the currently
...
...
@@ -122,7 +123,7 @@ public:
* @param primaryKey A primary key definition (one or more fields)
* @param options A Cassandra WITH statement for keyspace generation
*/
void
createColumnFamily
(
string
name
,
string
fields
,
string
primaryKey
,
string
options
);
void
createColumnFamily
(
std
::
string
name
,
std
::
string
fields
,
std
::
string
primaryKey
,
std
::
string
options
);
/* Database data access operations */
...
...
@@ -134,7 +135,7 @@ public:
* @param ts The data time stamp (used for column name and time information in Cassandra
* @param value The data itself
*/
void
insert
(
string
columnFamily
,
string
key
,
uint64_t
ts
,
uint64_t
value
);
void
insert
(
std
::
string
columnFamily
,
std
::
string
key
,
uint64_t
ts
,
uint64_t
value
);
/* Class constructor / desctructor */
...
...
DCDBLib/src/cassandraBackend.cpp
View file @
260e8814
...
...
@@ -5,6 +5,8 @@
* Author: Axel Auweter
*/
#include
<iostream>
#include
"cassandraBackend.h"
/**
...
...
@@ -16,7 +18,7 @@
* It also fetches some information about the database
* cluster.
*/
void
CassandraBackend
::
connect
(
string
hostname
,
int
port
)
void
CassandraBackend
::
connect
(
std
::
string
hostname
,
int
port
)
{
sock
=
boost
::
shared_ptr
<
TSocket
>
(
new
TSocket
(
hostname
,
port
));
tr
=
boost
::
shared_ptr
<
TFramedTransport
>
(
new
TFramedTransport
(
sock
));
...
...
@@ -26,7 +28,7 @@ void CassandraBackend::connect(string hostname, int port)
tr
->
open
();
myClient
->
describe_cluster_name
(
clusterName
);
cout
<<
"Connected to cluster: "
<<
clusterName
<<
"
\n
"
;
std
::
cout
<<
"Connected to cluster: "
<<
clusterName
<<
"
\n
"
;
}
/**
...
...
@@ -46,7 +48,7 @@ void CassandraBackend::updateKeySpaces()
* This function iterates all known keyspaces to check
* if a keyspace with a given name can be found.
*/
bool
CassandraBackend
::
existsKeyspace
(
string
name
)
bool
CassandraBackend
::
existsKeyspace
(
std
::
string
name
)
{
updateKeySpaces
();
for
(
std
::
vector
<
KsDef
>::
iterator
it
=
keySpaces
.
begin
();
it
!=
keySpaces
.
end
();
++
it
)
{
...
...
@@ -64,11 +66,11 @@ bool CassandraBackend::existsKeyspace(string name)
* We are using CQL3 to do this as its syntax is less likely
* to change in future versions than the native API.
*/
void
CassandraBackend
::
createKeyspace
(
string
name
,
int
replicationFactor
)
void
CassandraBackend
::
createKeyspace
(
std
::
string
name
,
int
replicationFactor
)
{
CqlResult
res
;
string
query
;
string
rFact
=
boost
::
lexical_cast
<
string
>
(
replicationFactor
);
std
::
string
query
;
std
::
string
rFact
=
boost
::
lexical_cast
<
std
::
string
>
(
replicationFactor
);
if
(
validateName
(
name
))
{
query
=
"CREATE KEYSPACE "
+
name
+
" WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '"
+
rFact
+
"' };"
;
...
...
@@ -82,10 +84,10 @@ void CassandraBackend::createKeyspace(string name, int replicationFactor)
* statement and setting the currentKeySpace class member to point
* to the newly selected keyspace.
*/
void
CassandraBackend
::
selectKeyspace
(
string
name
)
void
CassandraBackend
::
selectKeyspace
(
std
::
string
name
)
{
CqlResult
res
;
string
query
;
std
::
string
query
;
if
(
validateName
(
name
))
{
query
=
"USE "
+
name
+
";"
;
...
...
@@ -105,7 +107,7 @@ void CassandraBackend::selectKeyspace(string name)
* space that was selected by selectKeyspace to check if a
* column family with the given name exists.
*/
bool
CassandraBackend
::
existsColumnFamily
(
string
name
)
bool
CassandraBackend
::
existsColumnFamily
(
std
::
string
name
)
{
for
(
std
::
vector
<
CfDef
>::
iterator
it
=
currentKeySpace
.
cf_defs
.
begin
();
it
!=
currentKeySpace
.
cf_defs
.
end
();
++
it
)
{
if
((
*
it
).
name
.
compare
(
name
)
==
0
)
...
...
@@ -119,10 +121,10 @@ bool CassandraBackend::existsColumnFamily(string name)
* This functions assembles the parameters into a CQL CREATE
* TABLE query and submits the query to the server.
*/
void
CassandraBackend
::
createColumnFamily
(
string
name
,
string
fields
,
string
primaryKey
,
string
options
)
void
CassandraBackend
::
createColumnFamily
(
std
::
string
name
,
std
::
string
fields
,
std
::
string
primaryKey
,
std
::
string
options
)
{
CqlResult
res
;
stringstream
query
;
std
::
stringstream
query
;
/* FIXME: Secure this and use proper types for fields, primaryKey, and options. */
query
<<
"CREATE TABLE "
<<
name
...
...
@@ -137,7 +139,7 @@ void CassandraBackend::createColumnFamily(string name, string fields, string pri
* The validation for alphanumeric is implemented by using C++ STL's
* find_if function. Pretty nice piece of C++!
*/
bool
CassandraBackend
::
validateName
(
string
name
)
bool
CassandraBackend
::
validateName
(
std
::
string
name
)
{
/*
* Make sure name only consists of alphabetical characters (super ugly)...
...
...
@@ -161,10 +163,10 @@ bool CassandraBackend::validateName(string name)
* dcdbendian.h header file. Conversion to std::string
* is straightforward.
*/
string
CassandraBackend
::
int64Convert
(
uint64_t
n
)
std
::
string
CassandraBackend
::
int64Convert
(
uint64_t
n
)
{
n
=
Endian
::
hostToBE
(
n
);
return
string
((
char
*
)
&
n
,
8
);
return
std
::
string
((
char
*
)
&
n
,
8
);
}
/**
...
...
@@ -173,12 +175,12 @@ string CassandraBackend::int64Convert(uint64_t n)
* this function converts the ts and value parameters to big-endian
* byte arrays using the int64convert function.
*/
void
CassandraBackend
::
insert
(
string
columnFamily
,
string
key
,
uint64_t
ts
,
uint64_t
value
)
void
CassandraBackend
::
insert
(
std
::
string
columnFamily
,
std
::
string
key
,
uint64_t
ts
,
uint64_t
value
)
{
try
{
ColumnParent
cparent
;
Column
c
;
string
name
,
cvalue
;
std
::
string
name
,
cvalue
;
cparent
.
column_family
=
columnFamily
;
...
...
@@ -206,15 +208,15 @@ void CassandraBackend::insert(string columnFamily, string key, uint64_t ts, uint
* possible.
*/
catch
(
const
TTransportException
&
te
){
cout
<<
"TP Exception: "
<<
te
.
what
()
<<
"["
<<
te
.
getType
()
<<
"]
\n
"
;
std
::
cout
<<
"TP Exception: "
<<
te
.
what
()
<<
"["
<<
te
.
getType
()
<<
"]
\n
"
;
exit
(
EXIT_FAILURE
);
}
catch
(
const
InvalidRequestException
&
ire
){
cout
<<
"IRE Exception: "
<<
ire
.
what
()
<<
"["
<<
ire
.
why
<<
"]
\n
"
;
std
::
cout
<<
"IRE Exception: "
<<
ire
.
what
()
<<
"["
<<
ire
.
why
<<
"]
\n
"
;
exit
(
EXIT_FAILURE
);
}
catch
(
const
NotFoundException
&
nfe
){
cout
<<
"NF Exception: "
<<
nfe
.
what
()
<<
"
\n
"
;
std
::
cout
<<
"NF Exception: "
<<
nfe
.
what
()
<<
"
\n
"
;
exit
(
EXIT_FAILURE
);
}
}
...
...
DCDBLib/src/sensordatastore.cpp
View file @
260e8814
...
...
@@ -29,6 +29,11 @@
* an object of the SensorDataStore class.
*/
#include
<string>
#include
<iostream>
#include
<stdint.h>
#include
"sensordatastore_internal.h"
/**
...
...
@@ -37,12 +42,12 @@
* big-endian 128-bit character array represented as
* std::string.
*/
string
SensorDataStoreImpl
::
sidConvert
(
SensorId
*
sid
)
std
::
string
SensorDataStoreImpl
::
sidConvert
(
SensorId
*
sid
)
{
uint64_t
ll
[
2
];
ll
[
0
]
=
Endian
::
hostToBE
(
sid
->
raw
[
0
]);
ll
[
1
]
=
Endian
::
hostToBE
(
sid
->
raw
[
1
]);
return
string
((
char
*
)
ll
,
16
);
return
std
::
string
((
char
*
)
ll
,
16
);
}
/**
...
...
@@ -58,7 +63,7 @@ string SensorDataStoreImpl::sidConvert(SensorId *sid)
* use the topicToSid function provided by the
* SensorDataStore class.
*/
bool
SensorDataStoreImpl
::
topicToSid
(
SensorId
*
sid
,
string
topic
)
bool
SensorDataStoreImpl
::
topicToSid
(
SensorId
*
sid
,
std
::
string
topic
)
//template <typename T> bool SensorDataStoreImpl::topicToSid(T* sid, string topic)
{
uint64_t
pos
=
0
;
...
...
@@ -94,7 +99,7 @@ bool SensorDataStoreImpl::topicToSid(SensorId* sid, string topic)
* Applications should not call this function directly, but
* use the init function provideed by the SensorDataStore class.
*/
void
SensorDataStoreImpl
::
init
(
string
hostname
,
int
port
)
{
void
SensorDataStoreImpl
::
init
(
std
::
string
hostname
,
int
port
)
{
/*
* Open the connection to the Cassandra database and
...
...
@@ -104,19 +109,19 @@ void SensorDataStoreImpl::init(string hostname, int port) {
csBackend
->
connect
(
hostname
,
port
);
if
(
!
csBackend
->
existsKeyspace
(
KEYSPACE_NAME
))
{
cout
<<
"Creating Keyspace "
<<
KEYSPACE_NAME
<<
"...
\n
"
;
std
::
cout
<<
"Creating Keyspace "
<<
KEYSPACE_NAME
<<
"...
\n
"
;
csBackend
->
createKeyspace
(
KEYSPACE_NAME
,
1
);
}
csBackend
->
selectKeyspace
(
KEYSPACE_NAME
);
if
(
!
(
csBackend
->
currentKeySpace
.
name
.
compare
(
KEYSPACE_NAME
)
==
0
))
{
cout
<<
"Cannot select keyspace "
<<
KEYSPACE_NAME
<<
"
\n
"
;
std
::
cout
<<
"Cannot select keyspace "
<<
KEYSPACE_NAME
<<
"
\n
"
;
exit
(
EXIT_FAILURE
);
}
if
(
!
csBackend
->
existsColumnFamily
(
CF_SENSORDATA
))
{
cout
<<
"Creating Column Familiy "
CF_SENSORDATA
"...
\n
"
;
std
::
cout
<<
"Creating Column Familiy "
CF_SENSORDATA
"...
\n
"
;
csBackend
->
createColumnFamily
(
CF_SENSORDATA
,
"sid blob, ts bigint, value bigint"
,
"sid, ts"
,
...
...
@@ -124,15 +129,15 @@ void SensorDataStoreImpl::init(string hostname, int port) {
}
}
catch
(
const
TTransportException
&
te
){
cout
<<
"TP Exception: "
<<
te
.
what
()
<<
"["
<<
te
.
getType
()
<<
"]
\n
"
;
std
::
cout
<<
"TP Exception: "
<<
te
.
what
()
<<
"["
<<
te
.
getType
()
<<
"]
\n
"
;
exit
(
EXIT_FAILURE
);
}
catch
(
const
InvalidRequestException
&
ire
){
cout
<<
"IRE Exception: "
<<
ire
.
what
()
<<
"["
<<
ire
.
why
<<
"]
\n
"
;
std
::
cout
<<
"IRE Exception: "
<<
ire
.
what
()
<<
"["
<<
ire
.
why
<<
"]
\n
"
;
exit
(
EXIT_FAILURE
);
}
catch
(
const
NotFoundException
&
nfe
){
cout
<<
"NF Exception: "
<<
nfe
.
what
()
<<
"
\n
"
;
std
::
cout
<<
"NF Exception: "
<<
nfe
.
what
()
<<
"
\n
"
;
exit
(
EXIT_FAILURE
);
}
}
...
...
@@ -186,7 +191,7 @@ SensorDataStoreImpl::~SensorDataStoreImpl()
* Once this is ensured, the actual initialization work is
* performed by the init function of SensorDataStoreImpl.
*/
void
SensorDataStore
::
init
(
string
hostname
,
int
port
)
void
SensorDataStore
::
init
(
std
::
string
hostname
,
int
port
)
{
/* Allocate new SensorDataStoreImpl Object if necessary */
if
(
!
impl
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment