Commit 128d533d authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3880] statistic-* commands are now registered in Dhcpv4Srv

parent a3856901
......@@ -20,10 +20,12 @@
#include <dhcp4/json_config_parser.h>
#include <dhcpsrv/cfgmgr.h>
#include <config/command_mgr.h>
#include <stats/stats_mgr.h>
using namespace isc::data;
using namespace isc::hooks;
using namespace isc::config;
using namespace isc::stats;
using namespace std;
namespace isc {
......@@ -168,16 +170,29 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t port /*= DHCP4_SERVER_PORT*/)
// Register supported commands in CommandMgr
CommandMgr::instance().registerCommand("shutdown",
boost::bind(&ControlledDhcpv4Srv::commandShutdownHandler, this, _1, _2));
boost::bind(&ControlledDhcpv4Srv::commandShutdownHandler, this, _1, _2));
/// @todo: register config-reload (see CtrlDhcpv4Srv::commandConfigReloadHandler)
/// @todo: register libreload (see CtrlDhcpv4Srv::commandLibReloadHandler)
/// @todo: register statistic-get (see StatsMgr::get(name))
/// @todo: register statistic-reset (see StatsMgr::reset(name))
/// @todo: register statistic-get-all (see StatsMgr::getAll())
/// @todo: register statistic-reset-all (see StatsMgr::resetAll())
/// @todo: register statistic-remove (see StatsMgr::del(name))
/// @todo: register statistic-remove-all (see StatsMgr::removeAll())
// Register statistic related commands
CommandMgr::instance().registerCommand("statistic-get",
boost::bind(&StatsMgr::statisticGetHandler, _1, _2));
CommandMgr::instance().registerCommand("statistic-reset",
boost::bind(&StatsMgr::statisticResetHandler, _1, _2));
CommandMgr::instance().registerCommand("statistic-remove",
boost::bind(&StatsMgr::statisticRemoveHandler, _1, _2));
CommandMgr::instance().registerCommand("statistic-get-all",
boost::bind(&StatsMgr::statisticGetAllHandler, _1, _2));
CommandMgr::instance().registerCommand("statistic-reset-all",
boost::bind(&StatsMgr::statisticResetAllHandler, _1, _2));
CommandMgr::instance().registerCommand("statistic-remove-all",
boost::bind(&StatsMgr::statisticRemoveAllHandler, _1, _2));
}
void ControlledDhcpv4Srv::shutdown() {
......@@ -193,6 +208,12 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() {
// Deregister any registered commands
CommandMgr::instance().deregisterCommand("shutdown");
CommandMgr::instance().deregisterCommand("statistic-get");
CommandMgr::instance().deregisterCommand("statistic-reset");
CommandMgr::instance().deregisterCommand("statistic-remove");
CommandMgr::instance().deregisterCommand("statistic-get-all");
CommandMgr::instance().deregisterCommand("statistic-reset-all");
CommandMgr::instance().deregisterCommand("statistic-remove-all");
server_ = NULL; // forget this instance. Noone should call any handlers at
// this stage.
......
......@@ -118,6 +118,8 @@ dhcp4_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/util/io/libkea-util-io.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
endif
noinst_EXTRA_DIST = configs-list.txt
......
......@@ -243,7 +243,11 @@ TEST_F(CtrlDhcpv4SrvTest, commandsRegistration) {
EXPECT_NO_THROW(answer = CommandMgr::instance().processCommand(list_cmds));
ASSERT_TRUE(answer);
ASSERT_TRUE(answer->get("arguments"));
EXPECT_EQ("[ \"list-commands\", \"shutdown\" ]", answer->get("arguments")->str());
EXPECT_EQ("[ \"list-commands\", \"shutdown\", "
"\"statistic-get\", \"statistic-get-all\", "
"\"statistic-remove\", \"statistic-remove-all\", "
"\"statistic-reset\", \"statistic-reset-all\" ]",
answer->get("arguments")->str());
// Ok, and now delete the server. It should deregister its commands.
srv.reset();
......
......@@ -162,7 +162,8 @@ StatsMgr::statisticGetHandler(const std::string& /*name*/,
return (createAnswer(CONTROL_RESULT_ERROR,
"'name' parameter expected to be a string."));
}
return (createAnswer(CONTROL_RESULT_SUCCESS, get(stat_name->stringValue())));
return (createAnswer(CONTROL_RESULT_SUCCESS,
instance().get(stat_name->stringValue())));
}
isc::data::ConstElementPtr
......@@ -182,7 +183,7 @@ StatsMgr::statisticResetHandler(const std::string& /*name*/,
"'name' parameter expected to be a string."));
}
if (reset(stat_name->stringValue())) {
if (instance().reset(stat_name->stringValue())) {
return (createAnswer(CONTROL_RESULT_SUCCESS,
"Statistic '" + stat_name->stringValue() + "' reset."));
} else {
......@@ -203,7 +204,7 @@ StatsMgr::statisticRemoveHandler(const std::string& /*name*/,
return (createAnswer(CONTROL_RESULT_ERROR,
"Missing mandatory 'name' parameter."));
}
if (del(stat_name->stringValue())) {
if (instance().del(stat_name->stringValue())) {
return (createAnswer(CONTROL_RESULT_SUCCESS,
"Statistic '" + stat_name->stringValue() + "' removed."));
} else {
......@@ -216,7 +217,7 @@ StatsMgr::statisticRemoveHandler(const std::string& /*name*/,
isc::data::ConstElementPtr
StatsMgr::statisticRemoveAllHandler(const std::string& /*name*/,
const isc::data::ConstElementPtr& /*params*/) {
removeAll();
instance().removeAll();
return (createAnswer(CONTROL_RESULT_SUCCESS,
"All statistics removed."));
}
......@@ -224,14 +225,14 @@ StatsMgr::statisticRemoveAllHandler(const std::string& /*name*/,
isc::data::ConstElementPtr
StatsMgr::statisticGetAllHandler(const std::string& /*name*/,
const isc::data::ConstElementPtr& /*params*/) {
ConstElementPtr all_stats = getAll();
ConstElementPtr all_stats = instance().getAll();
return (createAnswer(CONTROL_RESULT_SUCCESS, all_stats));
}
isc::data::ConstElementPtr
StatsMgr::statisticResetAllHandler(const std::string& /*name*/,
const isc::data::ConstElementPtr& /*params*/) {
resetAll();
instance().resetAll();
return (createAnswer(CONTROL_RESULT_SUCCESS,
"All statistics reset to neutral values."));
}
......
......@@ -217,7 +217,7 @@ class StatsMgr : public boost::noncopyable {
/// @param name name of the command (ignored, should be "statistic-get")
/// @param params structure containing a map that contains "name"
/// @param return answer containing details of specified statistic
isc::data::ConstElementPtr
static isc::data::ConstElementPtr
statisticGetHandler(const std::string& name,
const isc::data::ConstElementPtr& params);
......@@ -235,7 +235,7 @@ class StatsMgr : public boost::noncopyable {
/// @param name name of the command (ignored, should be "statistic-reset")
/// @param params structure containing a map that contains "name"
/// @param return answer containing confirmation
isc::data::ConstElementPtr
static isc::data::ConstElementPtr
statisticResetHandler(const std::string& name,
const isc::data::ConstElementPtr& params);
......@@ -253,7 +253,7 @@ class StatsMgr : public boost::noncopyable {
/// @param name name of the command (ignored, should be "statistic-remove")
/// @param params structure containing a map that contains "name" element
/// @param return answer containing confirmation
isc::data::ConstElementPtr
static isc::data::ConstElementPtr
statisticRemoveHandler(const std::string& name,
const isc::data::ConstElementPtr& params);
......@@ -265,7 +265,7 @@ class StatsMgr : public boost::noncopyable {
/// @param name name of the command (ignored, should be "statistic-get-all")
/// @param params ignored
/// @param return answer containing values of all statistic
isc::data::ConstElementPtr
static isc::data::ConstElementPtr
statisticGetAllHandler(const std::string& name,
const isc::data::ConstElementPtr& params);
......@@ -277,7 +277,7 @@ class StatsMgr : public boost::noncopyable {
/// @param name name of the command (ignored, should be "statistic-reset-all")
/// @param params ignored
/// @param return answer confirming success of this operation
isc::data::ConstElementPtr
static isc::data::ConstElementPtr
statisticResetAllHandler(const std::string& name,
const isc::data::ConstElementPtr& params);
......@@ -289,7 +289,7 @@ class StatsMgr : public boost::noncopyable {
/// @param name name of the command (ignored, should be "statistic-remove-all")
/// @param params ignored
/// @param return answer confirming success of this operation
isc::data::ConstElementPtr
static isc::data::ConstElementPtr
statisticRemoveAllHandler(const std::string& name,
const isc::data::ConstElementPtr& params);
......
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