22 #include <boost/pointer_cast.hpp> 38 CtrlAgentCommandMgr::instance() {
43 CtrlAgentCommandMgr::CtrlAgentCommandMgr()
54 if (answer->getType() == Element::list) {
57 ElementPtr answer_list = Element::createList();
58 answer_list->add(boost::const_pointer_cast<Element>(answer));
64 CtrlAgentCommandMgr::handleCommand(
const std::string& cmd_name,
69 if (raddr_ptr && (raddr_ptr->getType() == Element::string)) {
70 remote_addr_ = raddr_ptr->stringValue();
72 remote_addr_ =
"(unknown)";
82 if (original_cmd && original_cmd->contains(
"service")) {
83 services = original_cmd->get(
"service");
86 if (services->getType() != Element::list) {
95 if (services->empty()) {
110 (HookedCommandMgr::handleCommand(cmd_name, params, original_cmd));
122 std::ostringstream s;
123 s << text->stringValue();
124 s <<
" You did not include \"service\" parameter in the command," 125 " which indicates that Kea Control Agent should process this" 126 " command rather than forward it to one or more Kea servers. If you" 127 " aimed to send this command to one of the Kea servers you" 128 " should include the \"service\" parameter in your request, e.g." 129 " \"service\": [ \"dhcp4\" ] to forward the command to the DHCPv4" 130 " server, or \"service\": [ \"dhcp4\", \"dhcp6\", \"d2\" ] to forward it to" 131 " DHCPv4, DHCPv6 and D2 servers etc.";
144 ElementPtr answer_list = Element::createList();
148 if (HookedCommandMgr::delegateCommandToHookLibrary(cmd_name, params, original_cmd,
151 return (answer_list);
156 answer_list = Element::createList();
159 for (
unsigned i = 0; i < services->size(); ++i) {
165 .arg(cmd_name).arg(services->get(i)->stringValue());
167 answer = forwardCommand(services->get(i)->stringValue(),
168 cmd_name, original_cmd);
173 .arg(cmd_name).arg(ex.
what());
177 answer_list->add(boost::const_pointer_cast<Element>(answer));
181 return (answer_list);
185 CtrlAgentCommandMgr::forwardCommand(
const std::string& service,
186 const std::string& cmd_name,
195 boost::shared_ptr<CtrlAgentController> controller =
202 ctx = cfgmgr->getCtrlAgentCfgContext();
211 " Control Agent configuration information");
220 " for the server type " << service);
225 std::string socket_name = socket_info->get(
"socket-name")->stringValue();
230 boost::system::error_code received_ec;
234 [&io_service, &received_ec, &received_feed]
238 received_feed = feed;
241 io_service->stopWork();
247 << service <<
" service: " << received_ec.message()
248 <<
". The server is likely to be offline");
254 if (!received_feed) {
256 " received from the unix domain socket");
261 answer = received_feed->toElement();
268 }
catch (
const std::exception& ex) {
270 " server's answer to the forwarded message: " << ex.
what());
const isc::log::MessageID CTRL_AGENT_COMMAND_FORWARD_BEGIN
Exception thrown when an error occurred during control command forwarding.
const isc::log::MessageID CTRL_AGENT_COMMAND_FORWARD_FAILED
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CtrlAgentCfgMgr > CtrlAgentCfgMgrPtr
Defines a shared pointer to CtrlAgentCfgMgr.
Represents client side connection over the unix domain socket.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
boost::shared_ptr< CtrlAgentProcess > CtrlAgentProcessPtr
Defines a shared pointer to CtrlAgentProcess.
The IOService class is a wrapper for the ASIO io_service class.
isc::log::Logger agent_logger("ctrl-agent")
Control Agent logger.
Command Manager which can delegate commands to a hook library.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
CtrlAgentProcessPtr getCtrlAgentProcess()
Returns pointer to an instance of the underlying process object.
Command Manager for Control Agent.
const isc::log::MessageID CTRL_AGENT_COMMAND_RECEIVED
const char * CONTROL_TEXT
String used for storing textual description ("text")
Process Controller for Control Agent Process.
boost::shared_ptr< const Element > ConstElementPtr
constexpr long TIMEOUT_AGENT_FORWARD_COMMAND
Timeout for the Control Agent to forward command to a Kea server, e.g.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Defines the logger used by the top-level component of kea-lfc.
boost::shared_ptr< const JSONFeed > ConstJSONFeedPtr
Pointer to the const JSONFeed.
const isc::log::MessageID CTRL_AGENT_COMMAND_FORWARDED
This file contains several functions and constants that are used for handling commands and responses ...
const int DBGLVL_COMMAND
This debug level is reserved for logging the exchange of messages/commands between processes...
The Element class represents a piece of data, used by the command channel and configuration parts...
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Encapsulates socket path.
boost::shared_ptr< CtrlAgentCfgContext > CtrlAgentCfgContextPtr
Pointer to a configuration context.
Encapsulates timeout value.
void start(const SocketPath &socket_path, const ControlCommand &command, Handler handler, const Timeout &timeout=Timeout(5000))
Starts asynchronous transaction with a remote endpoint.
Encapsulates control command.
const int CONTROL_RESULT_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.