Kea 2.7.6
d2_controller.cc
Go to the documentation of this file.
1// Copyright (C) 2013-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
12#include <d2/d2_controller.h>
13#include <d2/d2_process.h>
14#include <d2/parser_context.h>
16#include <stats/stats_mgr.h>
17
18#include <stdlib.h>
19
20using namespace isc::config;
21using namespace isc::process;
22using namespace isc::stats;
23namespace ph = std::placeholders;
24
25namespace isc {
26namespace d2 {
27
30const char* D2Controller::d2_app_name_ = "DhcpDdns";
31
33const char* D2Controller::d2_bin_name_ = "kea-dhcp-ddns";
34
37 // If the instance hasn't been created yet, create it. Note this method
38 // must use the base class singleton instance methods.
39 if (!getController()) {
40 DControllerBasePtr controller_ptr(new D2Controller());
41 setController(controller_ptr);
42 }
43
44 return (getController());
45}
46
47DProcessBase* D2Controller::createProcess() {
48 // Instantiate and return an instance of the D2 application process. Note
49 // that the process is passed the controller's io_service.
50 return (new D2Process(getAppName().c_str(), getIOService()));
51}
52
53D2Controller::D2Controller()
54 : DControllerBase(d2_app_name_, d2_bin_name_) {
55}
56
57void
59 // These are the commands always supported by the D2 server.
60 // Please keep the list in alphabetic order.
61 CommandMgr::instance().registerCommand(BUILD_REPORT_COMMAND,
62 std::bind(&D2Controller::buildReportHandler, this, ph::_1, ph::_2));
63
64 CommandMgr::instance().registerCommand(CONFIG_GET_COMMAND,
65 std::bind(&D2Controller::configGetHandler, this, ph::_1, ph::_2));
66
67 CommandMgr::instance().registerCommand(CONFIG_HASH_GET_COMMAND,
68 std::bind(&D2Controller::configHashGetHandler, this, ph::_1, ph::_2));
69
70 CommandMgr::instance().registerCommand(CONFIG_RELOAD_COMMAND,
71 std::bind(&D2Controller::configReloadHandler, this, ph::_1, ph::_2));
72
73 CommandMgr::instance().registerCommand(CONFIG_SET_COMMAND,
74 std::bind(&D2Controller::configSetHandler, this, ph::_1, ph::_2));
75
76 CommandMgr::instance().registerCommand(CONFIG_TEST_COMMAND,
77 std::bind(&D2Controller::configTestHandler, this, ph::_1, ph::_2));
78
79 CommandMgr::instance().registerCommand(CONFIG_WRITE_COMMAND,
80 std::bind(&D2Controller::configWriteHandler, this, ph::_1, ph::_2));
81
82 CommandMgr::instance().registerCommand(SHUT_DOWN_COMMAND,
83 std::bind(&D2Controller::shutdownHandler, this, ph::_1, ph::_2));
84
85 CommandMgr::instance().registerCommand(STATUS_GET_COMMAND,
86 std::bind(&DControllerBase::statusGetHandler, this, ph::_1, ph::_2));
87
88 CommandMgr::instance().registerCommand(VERSION_GET_COMMAND,
89 std::bind(&D2Controller::versionGetHandler, this, ph::_1, ph::_2));
90
91 // Register statistic related commands.
92 CommandMgr::instance().registerCommand("statistic-get",
93 std::bind(&StatsMgr::statisticGetHandler, ph::_1, ph::_2));
94
95 CommandMgr::instance().registerCommand("statistic-get-all",
96 std::bind(&StatsMgr::statisticGetAllHandler, ph::_1, ph::_2));
97
98 CommandMgr::instance().registerCommand("statistic-reset",
99 std::bind(&StatsMgr::statisticResetHandler, ph::_1, ph::_2));
100
101 CommandMgr::instance().registerCommand("statistic-reset-all",
102 std::bind(&StatsMgr::statisticResetAllHandler, ph::_1, ph::_2));
103}
104
105void
107 try {
108 // Close command sockets.
111
112 // Deregister any registered commands (please keep in alphabetic order)
113 CommandMgr::instance().deregisterCommand(BUILD_REPORT_COMMAND);
114 CommandMgr::instance().deregisterCommand(CONFIG_GET_COMMAND);
115 CommandMgr::instance().deregisterCommand(CONFIG_HASH_GET_COMMAND);
116 CommandMgr::instance().deregisterCommand(CONFIG_RELOAD_COMMAND);
117 CommandMgr::instance().deregisterCommand(CONFIG_SET_COMMAND);
118 CommandMgr::instance().deregisterCommand(CONFIG_TEST_COMMAND);
119 CommandMgr::instance().deregisterCommand(CONFIG_WRITE_COMMAND);
120 CommandMgr::instance().deregisterCommand(SHUT_DOWN_COMMAND);
121 CommandMgr::instance().deregisterCommand("statistic-get");
122 CommandMgr::instance().deregisterCommand("statistic-get-all");
123 CommandMgr::instance().deregisterCommand("statistic-reset");
124 CommandMgr::instance().deregisterCommand("statistic-reset-all");
125 CommandMgr::instance().deregisterCommand(STATUS_GET_COMMAND);
126 CommandMgr::instance().deregisterCommand(VERSION_GET_COMMAND);
127
128 } catch (...) {
129 // What to do? Simply ignore...
130 }
131}
132
134D2Controller::parseFile(const std::string& file_name) {
136
137 // Read contents of the file and parse it as JSON
138 D2ParserContext parser;
139 elements = parser.parseFile(file_name, D2ParserContext::PARSER_DHCPDDNS);
140 if (!elements) {
141 isc_throw(isc::BadValue, "no configuration found in file");
142 }
143
144 return (elements);
145}
146
149
150} // end namespace isc::d2
151} // end namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
void registerCommand(const std::string &cmd, CommandHandler handler)
Registers specified command handler for a given command.
void deregisterCommand(const std::string &cmd)
Deregisters specified command handler.
static CommandMgr & instance()
CommandMgr is a singleton class.
static HttpCommandMgr & instance()
HttpCommandMgr is a singleton class.
void close(bool remove=true)
Close http control socket.
static UnixCommandMgr & instance()
UnixCommandMgr is a singleton class.
void closeCommandSocket()
Shuts down any open unix control sockets.
Process Controller for D2 Process This class is the DHCP-DDNS specific derivation of DControllerBase.
static process::DControllerBasePtr & instance()
Static singleton instance method.
static const char * d2_app_name_
Defines the application name, this is passed into base class and appears in log statements.
static const char * d2_bin_name_
Defines the executable name.
void registerCommands()
Register commands.
void deregisterCommands()
Deregister commands.
virtual ~D2Controller()
Destructor.
Evaluation context, an interface to the expression evaluation.
@ PARSER_DHCPDDNS
Used for parsing content of DhcpDdns.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
DHCP-DDNS Application Process.
Definition d2_process.h:24
Application Controller.
isc::data::ConstElementPtr configReloadHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-reload command
isc::data::ConstElementPtr buildReportHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for 'build-report' command
isc::data::ConstElementPtr statusGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for status-get command
asiolink::IOServicePtr & getIOService()
Getter for fetching the controller's IOService.
static DControllerBasePtr & getController()
Static getter which returns the singleton instance.
isc::data::ConstElementPtr configWriteHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-write command
static void setController(const DControllerBasePtr &controller)
Static setter which sets the singleton instance.
isc::data::ConstElementPtr versionGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for version-get command
isc::data::ConstElementPtr configSetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-set command
isc::data::ConstElementPtr configGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-get command
isc::data::ConstElementPtr configHashGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-hash-get command
isc::data::ConstElementPtr configTestHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-test command
std::string getAppName() const
Fetches the name of the application under control.
isc::data::ConstElementPtr shutdownHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for 'shutdown' command
Application Process Interface.
Definition d_process.h:75
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
static isc::data::ConstElementPtr statisticResetHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-reset command.
static isc::data::ConstElementPtr statisticGetAllHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-get-all command.
static isc::data::ConstElementPtr statisticGetHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-get command.
static isc::data::ConstElementPtr statisticResetAllHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-reset-all command.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< DControllerBase > DControllerBasePtr
Defines the logger used by the top-level component of kea-lfc.