ca_command_mgr.h 4.61 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef CTRL_AGENT_COMMAND_MGR_H
#define CTRL_AGENT_COMMAND_MGR_H

#include <config/hooked_command_mgr.h>
11
#include <exceptions/exceptions.h>
12
13
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
14
#include <array>
15
16
17
18

namespace isc {
namespace agent {

19
20
21
22
23
24
25
26
/// @brief Exception thrown when an error occurred during control command
/// forwarding.
class CommandForwardingError : public Exception {
public:
    CommandForwardingError(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) { };
};

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/// @brief Command Manager for Control Agent.
///
/// This is an implementation of the Command Manager within Control Agent.
/// In addition to the standard capabilities of the @ref HookedCommandMgr
/// it is also intended to forward commands to the respective Kea servers
/// when the command is not supported directly by the Control Agent.
///
/// @todo This Command Manager doesn't yet support forwarding commands.
///
/// The @ref CtrlAgentCommandMgr is implemented as a singleton. The commands
/// are registered using @c CtrlAgentCommandMgr::instance().registerCommand().
/// The @ref CtrlAgentResponseCreator uses the sole instance of the Command
/// Manager to handle incoming commands.
class CtrlAgentCommandMgr : public config::HookedCommandMgr,
                            public boost::noncopyable {
public:

    /// @brief Returns sole instance of the Command Manager.
    static CtrlAgentCommandMgr& instance();

    /// @brief Handles the command having a given name and arguments.
    ///
    /// This method extends the base implementation with the ability to forward
50
    /// commands to Kea servers.
51
    ///
52
    /// If the received command doesn't include 'service' parameter or this
53
54
    /// parameter is blank, the command is first handled by the attached hooks
    /// libraries, and if still unhandled, the Control Agent itself.
55
    ///
56
57
    /// If the non-blank 'service' parameter has been specified the hooks
    /// are executed. If the hooks process the command the result is returned
58
59
    /// to the controlling client. Otherwise, the command is forwarded to each
    /// Kea server listed in the 'service' parameter.
60
61
62
    ///
    /// @param cmd_name Command name.
    /// @param params Command arguments.
63
    /// @param original_cmd Original command being processed.
64
    ///
65
66
67
    /// @return 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.
68
69
    virtual isc::data::ConstElementPtr
    handleCommand(const std::string& cmd_name,
70
                  const isc::data::ConstElementPtr& params,
71
                  const isc::data::ConstElementPtr& original_cmd);
72

73
private:
74

75
    /// @brief Implements the logic for @ref CtrlAgentCommandMgr::handleCommand.
76
    ///
77
78
    /// All parameters are passed by value because they may be modified within
    /// the method.
79
    ///
80
81
82
    /// @param cmd_name Command name.
    /// @param params Command arguments.
    /// @param original_cmd Original command being processed.
83
    ///
84
85
86
87
88
89
90
91
92
    /// @return Pointer to the const data element representing a list of responses
    /// to the command or a single response (not wrapped in a list). The
    /// @ref CtrlAgentCommandMgr::handleCommand will wrap non-list value returned
    /// in a single element list.
    isc::data::ConstElementPtr
    handleCommandInternal(std::string cmd_name,
                          isc::data::ConstElementPtr params,
                          isc::data::ConstElementPtr original_cmd);

93
    /// @brief Tries to forward received control command to a specified server.
94
    ///
95
96
    /// @param service Contains name of the service where the command should be
    /// forwarded.
97
98
99
100
101
102
    /// @param cmd_name Command name.
    /// @param command Pointer to the object representing the forwarded command.
    ///
    /// @return Response to forwarded command.
    /// @throw CommandForwardingError when an error occurred during forwarding.
    isc::data::ConstElementPtr
103
    forwardCommand(const std::string& service, const std::string& cmd_name,
104
                   const isc::data::ConstElementPtr& command);
105

106
107
108
109
110
111
112
113
114
115
116
117
    /// @brief Private constructor.
    ///
    /// The instance should be created using @ref CtrlAgentCommandMgr::instance,
    /// thus the constructor is private.
    CtrlAgentCommandMgr();

};

} // end of namespace isc::agent
} // end of namespace isc

#endif