Kea 2.7.6
isc::agent::CtrlAgentCommandMgr Class Reference

Command Manager for Control Agent. More...

#include <ca_command_mgr.h>

+ Inheritance diagram for isc::agent::CtrlAgentCommandMgr:

Public Member Functions

virtual isc::data::ConstElementPtr handleCommand (const std::string &cmd_name, const isc::data::ConstElementPtr &params, const isc::data::ConstElementPtr &original_cmd)
 Handles the command having a given name and arguments.
 
virtual isc::data::ConstElementPtr processCommand (const isc::data::ConstElementPtr &cmd)
 Triggers command processing.
 
- Public Member Functions inherited from isc::config::HookedCommandMgr
 HookedCommandMgr ()
 Constructor.
 
- Public Member Functions inherited from isc::config::BaseCommandMgr
 BaseCommandMgr ()
 Constructor.
 
virtual ~BaseCommandMgr ()
 Destructor.
 
void deregisterAll ()
 Auxiliary method that removes all installed commands.
 
void deregisterCommand (const std::string &cmd)
 Deregisters specified command handler.
 
void registerCommand (const std::string &cmd, CommandHandler handler)
 Registers specified command handler for a given command.
 
void registerExtendedCommand (const std::string &cmd, ExtendedCommandHandler handler)
 Registers specified command handler for a given command.
 

Static Public Member Functions

static CtrlAgentCommandMgrinstance ()
 Returns sole instance of the Command Manager.
 
- Static Public Member Functions inherited from isc::config::BaseCommandMgr
static std::string getHash (const isc::data::ConstElementPtr &config)
 returns a hash of a given Element structure
 

Additional Inherited Members

- Public Types inherited from isc::config::BaseCommandMgr
typedef std::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr &params)> CommandHandler
 Defines command handler type.
 
typedef std::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr &params, const isc::data::ConstElementPtr &original)> ExtendedCommandHandler
 Defines extended command handler type.
 
- Protected Types inherited from isc::config::BaseCommandMgr
typedef std::map< std::string, HandlersPairHandlerContainer
 Type of the container for command handlers.
 
- Protected Member Functions inherited from isc::config::HookedCommandMgr
bool delegateCommandToHookLibrary (const std::string &cmd_name, const isc::data::ConstElementPtr &params, const isc::data::ConstElementPtr &original_cmd, isc::data::ElementPtr &answer)
 Handles the command within the hooks libraries.
 
- Protected Member Functions inherited from isc::config::BaseCommandMgr
- Protected Attributes inherited from isc::config::BaseCommandMgr
HandlerContainer handlers_
 Container for command handlers.
 

Detailed Description

Command Manager for Control Agent.

This is an implementation of the Command Manager within Control Agent. In addition to the standard capabilities of the HookedCommandMgr it is also intended to forward commands to the respective Kea servers when the command is not supported directly by the Control Agent.

The CtrlAgentCommandMgr is implemented as a singleton. The commands are registered using CtrlAgentCommandMgr::instance().registerCommand(). The CtrlAgentResponseCreator uses the sole instance of the Command Manager to handle incoming commands.

Definition at line 37 of file ca_command_mgr.h.

Member Function Documentation

◆ handleCommand()

ConstElementPtr isc::agent::CtrlAgentCommandMgr::handleCommand ( const std::string & cmd_name,
const isc::data::ConstElementPtr & params,
const isc::data::ConstElementPtr & original_cmd )
virtual

Handles the command having a given name and arguments.

This method extends the base implementation with the ability to forward commands to Kea servers.

If the received command doesn't include 'service' parameter or this parameter is blank, the command is first handled by the attached hooks libraries, and if still unhandled, the Control Agent itself.

If the non-blank 'service' parameter has been specified the hooks are executed. If the hooks process the command the result is returned to the controlling client. Otherwise, the command is forwarded to each Kea server listed in the 'service' parameter.

Parameters
cmd_nameCommand name.
paramsCommand arguments.
original_cmdOriginal command being processed.
Returns
Pointer to the const data element representing a list of responses to the command. If the command has been handled by the CA, this list includes one response.

Reimplemented from isc::config::HookedCommandMgr.

Definition at line 64 of file ca_command_mgr.cc.

References isc::agent::agent_logger, isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED, isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_TEXT, isc::data::Element::create(), isc::config::createAnswer(), isc::data::Element::createList(), isc::agent::CTRL_AGENT_COMMAND_FORWARD_BEGIN, isc::agent::CTRL_AGENT_COMMAND_FORWARD_FAILED, isc::agent::CTRL_AGENT_COMMAND_RECEIVED, isc::log::DBGLVL_COMMAND, isc::config::HookedCommandMgr::delegateCommandToHookLibrary(), isc::config::HookedCommandMgr::handleCommand(), isc::data::Element::list, LOG_DEBUG, LOG_INFO, isc::config::parseAnswer(), isc::data::Element::string, and isc::Exception::what().

+ Here is the call graph for this function:

◆ instance()

CtrlAgentCommandMgr & isc::agent::CtrlAgentCommandMgr::instance ( )
static

Returns sole instance of the Command Manager.

Definition at line 38 of file ca_command_mgr.cc.

Referenced by isc::agent::CtrlAgentController::deregisterCommands(), and isc::agent::CtrlAgentController::registerCommands().

◆ processCommand()

isc::data::ConstElementPtr isc::agent::CtrlAgentCommandMgr::processCommand ( const isc::data::ConstElementPtr & cmd)
virtual

Triggers command processing.

This method overrides the BaseCommandMgr::processCommand to ensure that the response is always wrapped in a list. The base implementation returns a response map. Kea Control Agent forwards commands to multiple daemons behind it and thus it must return a list of responses from respective daemons. If an error occurs during command processing the error response must also be wrapped in a list because caller expects that CA always returns a list.

This method is an entry point for dealing with a command. Internally it calls CtrlAgentCommandMgr::handleCommand.

Parameters
cmdPointer to the data element representing command in JSON format.
Returns
Pointer to the response.

Reimplemented from isc::config::BaseCommandMgr.

Definition at line 48 of file ca_command_mgr.cc.

References isc::data::Element::createList(), and isc::data::Element::list.

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: