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
4fd356ec
Commit
4fd356ec
authored
Jan 14, 2016
by
Axel Auweter
Browse files
Tiny test program to evaluate the querySum API function.
parent
0f93891c
Changes
2
Hide whitespace changes
Inline
Side-by-side
DCDBTools/dcdbquerysum/Makefile
0 → 100644
View file @
4fd356ec
include
../../config.mk
CXXFLAGS
=
-O2
-ggdb
--std
=
c++11
-Wall
-Wno-unused-local-typedefs
-Wno-unknown-warning-option
-Wno-unknown-warning
-fmessage-length
=
0
-I
$(DCDBDEPLOYPATH)
/include/
-I
$(DCDBBASEPATH)
/include/
-DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
OBJS
=
dcdbquerysum.o
LIBS
=
-L
$(DCDBDEPLOYPATH)
/lib/
-ldcdb
-lcassandra
-luv
-lboost_random
-lboost_system
-lboost_date_time
-lboost_regex
-lssl
-lcrypto
TARGET
=
dcdbquerysum
.PHONY
:
clean install
$(TARGET)
:
$(OBJS)
$(CXX)
-o
$(TARGET)
$(OBJS)
$(LIBS)
all
:
$(TARGET)
clean
:
rm
-f
$(TARGET)
rm
-f
$(OBJS)
install
:
$(TARGET)
install
$(TARGET)
$(DCDBDEPLOYPATH)
/bin/
DCDBTools/dcdbquerysum/dcdbquerysum.cpp
0 → 100644
View file @
4fd356ec
/*
* dcdbquerysum.cpp
*
* Created on: Jan 14, 2016
* Author: Axel Auweter
*/
/* C++ standard headers */
#include <list>
#include <iostream>
#include <stdexcept>
/* C standard headers */
#include <cstdlib>
#include <ctime>
#include <cstdint>
#include <unistd.h>
/* Custom headers */
#include "dcdb/timestamp.h"
#include "dcdb/c_api.h"
void
usage
()
{
std
::
cout
<<
"Usage: dcdbquerysum [-h <hostname>] [-l] <sensor 1> [<sensor 2> ...] <start> <end>"
<<
std
::
endl
<<
" with <hostname> - host name of database host"
<<
std
::
endl
<<
" -l - interpret <start>, <end> as local time instead of utc"
<<
std
::
endl
<<
" <sensor n> - public name of sensor"
<<
std
::
endl
<<
" <start> - interval start time"
<<
std
::
endl
<<
" <end> - interval end time"
<<
std
::
endl
<<
std
::
endl
<<
" Start and end times may be specified in the same forms as in dcdbquery."
<<
std
::
endl
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
/* Check command line arguments */
if
(
argc
<=
3
)
{
usage
();
exit
(
EXIT_FAILURE
);
}
/* Get the options */
int
ret
;
const
char
*
host
=
getenv
(
"DCDB_HOSTNAME"
);
bool
localtime
=
false
;
if
(
!
host
)
{
host
=
"localhost"
;
}
while
((
ret
=
getopt
(
argc
,
argv
,
"+h:l"
))
!=-
1
)
{
switch
(
ret
)
{
case
'h'
:
host
=
optarg
;
break
;
case
'l'
:
localtime
=
true
;
break
;
default:
usage
();
exit
(
EXIT_FAILURE
);
}
}
/* Try to create DCDBTimeStamp objects from the arguments */
DCDBTimeStamp
start
,
end
;
try
{
start
=
DCDBTimeStamp
(
argv
[
argc
-
2
],
localtime
);
end
=
DCDBTimeStamp
(
argv
[
argc
-
1
],
localtime
);
}
catch
(
std
::
exception
&
e
)
{
std
::
cout
<<
"Wrong time format."
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
/* Ensure start < end */
if
(
start
>=
end
)
{
std
::
cout
<<
"Start time must be earlier than end time."
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
/* Build a list of sensor names */
std
::
list
<
std
::
string
>
sensors
;
for
(
int
arg
=
optind
;
arg
<
argc
-
2
;
arg
++
)
{
sensors
.
push_back
(
argv
[
arg
]);
}
/* Since we want to test the C API, we now have to convert all the lovely C++ data structures into C */
/* DCDBTimeStamp -> time_t (TODO: this should be implemented in DCDBLib) */
//std::cout << "Start: " << start.getString() << std::endl;
//std::cout << "End: " << end.getString() << std::endl;
struct
tm
tstart
=
{},
tend
=
{};
time_t
cstart
,
cend
;
/* Format is 2016-01-14T09:41:06.455049000 */
strptime
(
start
.
getString
().
c_str
(),
"%Y-%m-%dT%T"
,
&
tstart
);
strptime
(
end
.
getString
().
c_str
(),
"%Y-%m-%dT%T"
,
&
tend
);
cstart
=
mktime
(
&
tstart
);
cend
=
mktime
(
&
tend
);
/* std::list<std::string> sensors -> const char* csensors[] */
const
char
**
csensors
=
(
const
char
**
)
calloc
(
sensors
.
size
(),
sizeof
(
char
*
));
int
i
=
0
;
for
(
std
::
list
<
std
::
string
>::
iterator
it
=
sensors
.
begin
();
it
!=
sensors
.
end
();
it
++
)
{
csensors
[
i
]
=
it
->
c_str
();
i
++
;
}
/* Call the C API Query Sum Multiple */
int64_t
result
;
switch
(
dcdbQuerySumMultipleThreaded
(
&
result
,
/* Here goes the intgrated result */
host
,
/* Database host name */
9042
,
/* Cassandra CQL Port */
csensors
,
/* Pointer to sensor name array */
sensors
.
size
(),
/* Length of csensors array */
cstart
,
/* Start time */
cend
,
/* End time */
0
,
/* No special options */
4
/* Use 4 threads */
))
{
case
DCDB_C_OK
:
std
::
cout
<<
result
<<
std
::
endl
;
break
;
case
DCDB_C_CONNERR
:
std
::
cerr
<<
"Error: Cannot connect to data base."
<<
std
::
endl
;
break
;
case
DCDB_C_SENSORNOTFOUND
:
std
::
cerr
<<
"Error: One or more sensors not found."
<<
std
::
endl
;
break
;
case
DCDB_C_EMPTYSET
:
std
::
cerr
<<
"Error: Empty set."
<<
std
::
endl
;
break
;
case
DCDB_C_NOTINTEGRABLE
:
std
::
cerr
<<
"Error: One or more sensors are marked non-integrable."
<<
std
::
endl
;
break
;
case
DCDB_C_NOSENSOR
:
case
DCDB_C_UNKNOWN
:
std
::
cerr
<<
"Error: Unknown error."
<<
std
::
endl
;
break
;
}
/* Clean up */
free
(
csensors
);
return
0
;
}
Write
Preview
Markdown
is supported
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