Kea 2.5.6
d2_controller.cc
Go to the documentation of this file.
1// Copyright (C) 2013-2023 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
10#include <d2/d2_controller.h>
11#include <d2/d2_process.h>
12#include <d2/parser_context.h>
14#include <stats/stats_mgr.h>
15
16#include <stdlib.h>
17
18using namespace isc::config;
19using namespace isc::process;
20using namespace isc::stats;
21namespace ph = std::placeholders;
22
23namespace isc {
24namespace d2 {
25
28const char* D2Controller::d2_app_name_ = "DhcpDdns";
29
31const char* D2Controller::d2_bin_name_ = "kea-dhcp-ddns";
32
35 // If the instance hasn't been created yet, create it. Note this method
36 // must use the base class singleton instance methods.
37 if (!getController()) {
38 DControllerBasePtr controller_ptr(new D2Controller());
39 setController(controller_ptr);
40 }
41
42 return (getController());
43}
44
45DProcessBase* D2Controller::createProcess() {
46 // Instantiate and return an instance of the D2 application process. Note
47 // that the process is passed the controller's io_service.
48 return (new D2Process(getAppName().c_str(), getIOService()));
49}
50
51D2Controller::D2Controller()
52 : DControllerBase(d2_app_name_, d2_bin_name_) {
53}
54
55void
57 // These are the commands always supported by the D2 server.
58 // Please keep the list in alphabetic order.
59 CommandMgr::instance().registerCommand(BUILD_REPORT_COMMAND,
60 std::bind(&D2Controller::buildReportHandler, this, ph::_1, ph::_2));
61
62 CommandMgr::instance().registerCommand(CONFIG_GET_COMMAND,
63 std::bind(&D2Controller::configGetHandler, this, ph::_1, ph::_2));
64
65 CommandMgr::instance().registerCommand(CONFIG_HASH_GET_COMMAND,
66 std::bind(&D2Controller::configHashGetHandler, this, ph::_1, ph::_2));
67
68 CommandMgr::instance().registerCommand(CONFIG_RELOAD_COMMAND,
69 std::bind(&D2Controller::configReloadHandler, this, ph::_1, ph::_2));
70
71 CommandMgr::instance().registerCommand(CONFIG_SET_COMMAND,
72 std::bind(&D2Controller::configSetHandler, this, ph::_1, ph::_2));
73
74 CommandMgr::instance().registerCommand(CONFIG_TEST_COMMAND,
75 std::bind(&D2Controller::configTestHandler, this, ph::_1, ph::_2));
76
77 CommandMgr::instance().registerCommand(CONFIG_WRITE_COMMAND,
78 std::bind(&D2Controller::configWriteHandler, this, ph::_1, ph::_2));
79
80 CommandMgr::instance().registerCommand(SHUT_DOWN_COMMAND,
81 std::bind(&D2Controller::shutdownHandler, this, ph::_1, ph::_2));
82
83 CommandMgr::instance().registerCommand(STATUS_GET_COMMAND,
84 std::bind(&DControllerBase::statusGetHandler, this, ph::_1, ph::_2));
85
86 CommandMgr::instance().registerCommand(VERSION_GET_COMMAND,
87 std::bind(&D2Controller::versionGetHandler, this, ph::_1, ph::_2));
88
89 // Register statistic related commands.
90 CommandMgr::instance().registerCommand("statistic-get",
91 std::bind(&StatsMgr::statisticGetHandler, ph::_1, ph::_2));
92
93 CommandMgr::instance().registerCommand("statistic-get-all",
94 std::bind(&StatsMgr::statisticGetAllHandler, ph::_1, ph::_2));
95
96 CommandMgr::instance().registerCommand("statistic-reset",
97 std::bind(&StatsMgr::statisticResetHandler, ph::_1, ph::_2));
98
99 CommandMgr::instance().registerCommand("statistic-reset-all",
100 std::bind(&StatsMgr::statisticResetAllHandler, ph::_1, ph::_2));
101}
102
103void
105 try {
106 // Close the command socket (if it exists).
108
109 // Deregister any registered commands (please keep in alphabetic order)
110 CommandMgr::instance().deregisterCommand(BUILD_REPORT_COMMAND);
111 CommandMgr::instance().deregisterCommand(CONFIG_GET_COMMAND);
112 CommandMgr::instance().deregisterCommand(CONFIG_HASH_GET_COMMAND);
113 CommandMgr::instance().deregisterCommand(CONFIG_RELOAD_COMMAND);
114 CommandMgr::instance().deregisterCommand(CONFIG_SET_COMMAND);
115 CommandMgr::instance().deregisterCommand(CONFIG_TEST_COMMAND);
116 CommandMgr::instance().deregisterCommand(CONFIG_WRITE_COMMAND);
117 CommandMgr::instance().deregisterCommand(SHUT_DOWN_COMMAND);
118 CommandMgr::instance().deregisterCommand("statistic-get");
119 CommandMgr::instance().deregisterCommand("statistic-get-all");
120 CommandMgr::instance().deregisterCommand("statistic-reset");
121 CommandMgr::instance().deregisterCommand("statistic-reset-all");
122 CommandMgr::instance().deregisterCommand(STATUS_GET_COMMAND);
123 CommandMgr::instance().deregisterCommand(VERSION_GET_COMMAND);
124
125 } catch (...) {
126 // What to do? Simply ignore...
127 }
128}
129
131D2Controller::parseFile(const std::string& file_name) {
133
134 // Read contents of the file and parse it as JSON
135 D2ParserContext parser;
136 elements = parser.parseFile(file_name, D2ParserContext::PARSER_DHCPDDNS);
137 if (!elements) {
138 isc_throw(isc::BadValue, "no configuration found in file");
139 }
140
141 return (elements);
142}
143
145}
146
147std::string
149 std::stringstream stream;
150 // Currently the only dependency D2 adds to base is cryptolink
151 stream << isc::cryptolink::CryptoLink::getVersion() << std::endl;
152 return (stream.str());
153
154}
155
156} // end namespace isc::d2
157} // 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.
void closeCommandSocket()
Shuts down any open control sockets.
Definition: command_mgr.cc:626
static CommandMgr & instance()
CommandMgr is a singleton class.
Definition: command_mgr.cc:649
Process Controller for D2 Process This class is the DHCP-DDNS specific derivation of DControllerBase.
Definition: d2_controller.h:29
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.
Definition: d2_controller.h:43
static const char * d2_bin_name_
Defines the executable name.
Definition: d2_controller.h:47
virtual std::string getVersionAddendum()
Returns version info specific to D2.
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.
Definition: d_controller.h:103
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.
Definition: d_controller.h:469
static DControllerBasePtr & getController()
Static getter which returns the singleton instance.
Definition: d_controller.h:477
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.
Definition: d_controller.cc:49
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.
Definition: d_controller.h:221
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
Definition: d_controller.h:78
Defines the logger used by the top-level component of kea-lfc.