Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
9b49a6d2
Commit
9b49a6d2
authored
Dec 17, 2019
by
Alessio Netti
Browse files
Added dcdbconfig clearOperations action
- Allows to remove all existing operations from a certain sensor
parent
835657e6
Changes
5
Hide whitespace changes
Inline
Side-by-side
lib/include/dcdb/sensorconfig.h
View file @
9b49a6d2
...
...
@@ -288,6 +288,14 @@ public:
*/
SCError
setOperations
(
std
::
string
publicName
,
std
::
set
<
std
::
string
>
operations
);
/**
* @brief Removes all operations of the sensor.
*
* @param publicName Name of the sensor.
* @return See SCError.
*/
SCError
clearOperations
(
std
::
string
publicName
);
/**
* @brief Set a new sensor expression for a virtual sensor.
*
...
...
lib/include_internal/sensorconfig_internal.h
View file @
9b49a6d2
...
...
@@ -81,6 +81,7 @@ public:
SCError
setSensorUnit
(
std
::
string
publicName
,
std
::
string
unit
);
SCError
setSensorMask
(
std
::
string
publicName
,
uint64_t
mask
);
SCError
setOperations
(
std
::
string
publicName
,
std
::
set
<
std
::
string
>
operations
);
SCError
clearOperations
(
std
::
string
publicName
);
SCError
setTimeToLive
(
std
::
string
publicName
,
uint64_t
ttl
);
SCError
setSensorInterval
(
std
::
string
publicName
,
uint64_t
interval
);
...
...
lib/src/sensorconfig.cpp
View file @
9b49a6d2
...
...
@@ -176,6 +176,11 @@ SCError SensorConfig::setOperations(std::string publicName, std::set<std::string
return
impl
->
setOperations
(
publicName
,
operations
);
}
SCError
SensorConfig
::
clearOperations
(
std
::
string
publicName
)
{
return
impl
->
clearOperations
(
publicName
);
}
SCError
SensorConfig
::
setTimeToLive
(
std
::
string
publicName
,
uint64_t
ttl
)
{
return
impl
->
setTimeToLive
(
publicName
,
ttl
);
...
...
@@ -1520,6 +1525,50 @@ SCError SensorConfigImpl::setOperations(std::string publicName, std::set<std::st
return
error
;
}
SCError
SensorConfigImpl
::
clearOperations
(
std
::
string
publicName
)
{
SCError
error
=
SC_UNKNOWNERROR
;
CassError
rc
=
CASS_OK
;
CassStatement
*
statement
=
nullptr
;
CassFuture
*
future
=
nullptr
;
const
CassPrepared
*
prepared
=
nullptr
;
const
char
*
query
=
"UPDATE "
CONFIG_KEYSPACE_NAME
"."
CF_PUBLISHEDSENSORS
" SET operations = {} WHERE name = ? ;"
;
future
=
cass_session_prepare
(
session
,
query
);
cass_future_wait
(
future
);
rc
=
cass_future_error_code
(
future
);
if
(
rc
!=
CASS_OK
)
{
connection
->
printError
(
future
);
return
SC_UNKNOWNERROR
;
}
prepared
=
cass_future_get_prepared
(
future
);
cass_future_free
(
future
);
statement
=
cass_prepared_bind
(
prepared
);
cass_statement_bind_string
(
statement
,
0
,
publicName
.
c_str
());
future
=
cass_session_execute
(
session
,
statement
);
cass_future_wait
(
future
);
rc
=
cass_future_error_code
(
future
);
if
(
rc
!=
CASS_OK
)
{
connection
->
printError
(
future
);
error
=
SC_UNKNOWNERROR
;
}
else
{
error
=
SC_OK
;
}
cass_statement_free
(
statement
);
cass_prepared_free
(
prepared
);
return
error
;
}
SCError
SensorConfigImpl
::
setTimeToLive
(
std
::
string
publicName
,
uint64_t
ttl
)
{
SCError
error
=
SC_UNKNOWNERROR
;
...
...
tools/dcdbconfig/sensoraction.cpp
View file @
9b49a6d2
...
...
@@ -70,6 +70,7 @@ void SensorAction::printHelp(int argc, char* argv[])
std
::
cout
<<
" TTL <public name> <ttl> - Change time to live of a sensor."
<<
std
::
endl
;
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
<<
" UNPUBLISH <public name> - Unpublish a sensor."
<<
std
::
endl
;
}
...
...
@@ -187,6 +188,14 @@ int SensorAction::executeCommand(int argc, char* argv[], int argvidx, const char
}
doOperations
(
argv
[
argvidx
+
1
],
argv
[
argvidx
+
2
]);
}
else
if
(
strcasecmp
(
argv
[
argvidx
],
"CLEAROPERATIONS"
)
==
0
)
{
/* CLEAROPERATIONS needs one more parameter */
if
(
argvidx
+
1
>=
argc
)
{
std
::
cout
<<
"CLEAROPERATIONS needs one more parameter!"
<<
std
::
endl
;
goto
executeCommandError
;
}
doClearOperations
(
argv
[
argvidx
+
1
]);
}
else
if
(
strcasecmp
(
argv
[
argvidx
],
"UNPUBLISH"
)
==
0
)
{
/* UNPUBLISH needs one more parameter */
if
(
argvidx
+
1
>=
argc
)
{
...
...
@@ -583,6 +592,25 @@ void SensorAction::doOperations(const char* publicName, const char *operations)
}
}
void
SensorAction
::
doClearOperations
(
const
char
*
publicName
)
{
DCDB
::
SensorConfig
sensorConfig
(
connection
);
DCDB
::
SCError
err
=
sensorConfig
.
clearOperations
(
publicName
);
switch
(
err
)
{
case
DCDB
::
SC_OK
:
break
;
case
DCDB
::
SC_UNKNOWNSENSOR
:
std
::
cout
<<
"Unknown sensor name: "
<<
publicName
<<
std
::
endl
;
break
;
case
DCDB
::
SC_INVALIDSESSION
:
std
::
cout
<<
"Invalid session!"
<<
std
::
endl
;
break
;
default:
std
::
cout
<<
"Internal error."
<<
std
::
endl
;
}
}
/*
* Unpublish a sensor
*/
...
...
tools/dcdbconfig/sensoraction.h
View file @
9b49a6d2
...
...
@@ -58,6 +58,7 @@ protected:
void
doInterval
(
const
char
*
publicName
,
const
char
*
interval
);
void
doTTL
(
const
char
*
publicName
,
const
char
*
ttl
);
void
doOperations
(
const
char
*
publicName
,
const
char
*
operations
);
void
doClearOperations
(
const
char
*
publicName
);
void
doUnPublishSensor
(
const
char
*
publicName
);
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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