1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 | // Copyright (C) 2016-2024 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_PROCESS_H
#define CTRL_AGENT_PROCESS_H
#include <agent/ca_cfg_mgr.h>
#include <http/listener.h>
#include <process/d_process.h>
#include <vector><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
namespace isc {
namespace agent {
/// @brief Kea Control Agent Application Process
///
/// CtrlAgentProcess provides top level application logic for the Control
/// Agent, a process managing Kea servers.
///
/// The Control Agent receives JSON control commands over HTTP and forwards
/// the JSON commands to the respective Kea servers. The JSON command
/// includes a name of the server to which the command pertains. After
/// receiving a response from the Kea server it is sent back over HTTP
/// to the control API client.
///
/// Some commands are handled by the Control Agent process itself, rather than
/// forwarded to the Kea servers. An example of such command is the one that
/// instructs the agent to start a specific service.
class CtrlAgentProcess : public process::DProcessBase {
public:
/// @brief Constructor
///
/// @param name name is a text label for the process. Generally used
/// in log statements, but otherwise arbitrary.
/// @param io_service is the io_service used by the caller for
/// asynchronous event handling.
CtrlAgentProcess(const char* name, const asiolink::IOServicePtr& io_service);
/// @brief Destructor
virtual ~CtrlAgentProcess();<--- Destructor in derived class
/// @brief Initialize the Control Agent process.
///
/// This is invoked by the controller after command line arguments but
/// prior to configuration reception. The base class provides this method
/// as a place to perform any derivation-specific initialization steps
/// that are inappropriate for the constructor but necessary prior to
/// launch.
virtual void init();<--- Function in derived class
/// @brief Implements the process's event loop.
///
/// @throw DProcessBaseError if an operational error is encountered.
virtual void run();<--- Function in derived class
/// @brief Initiates the process's shutdown process.
///
/// This is last step in the shutdown event callback chain, that is
/// intended to notify the process it is to begin its shutdown process.
///
/// @param args an Element set of shutdown arguments (if any) that are
/// supported by the process derivation.
///
/// @return an Element that contains the results of argument processing,
/// consisting of an integer status value (0 means successful,
/// non-zero means failure), and a string explanation of the outcome.
///
/// @throw DProcessBaseError if an operational error is encountered.
virtual isc::data::ConstElementPtr
shutdown(isc::data::ConstElementPtr args);<--- Function in derived class
/// @brief Processes the given configuration.
///
/// This method may be called multiple times during the process lifetime.
/// Certainly once during process startup, and possibly later if the user
/// alters configuration. This method must not throw, it should catch any
/// processing errors and return a success or failure answer as described
/// below.
///
/// A usual problem related to the system reconfiguration is how to preserve
/// configuration integrity in case of errors. In this case, when the
/// HTTP listener's configuration is modified there is a need to close all
/// existing connections and gracefully shutdown the listener's instance.
/// This, however, makes it possible that the control agent looses
/// connectivity if opening a new listener is unsuccessful. In fact, this
/// is quite possible scenario when the user is setting up the listener to
/// use a restricted port range or non-existing IP address. In this case,
/// the configuration parser will not signal the problem because IP address
/// and/or port are syntactically correct.
///
/// This method deals with this problem by opening a new listener aside of
/// the currently running listener (if the new listener settings are
/// different than current settings). Both instances are held until the
/// CtrlAgentProcess::garbageCollectListeners is invoked, which
/// removes any listeners which are no longer used.
///
/// @param config_set a new configuration (JSON) for the process
/// @param check_only true if configuration is to be verified only, not applied
/// @return an Element that contains the results of configuration composed
/// of an integer status value (0 means successful, non-zero means failure),
/// and a string explanation of the outcome.
virtual isc::data::ConstElementPtr
configure(isc::data::ConstElementPtr config_set,<--- Function in derived class
bool check_only = false);
/// @brief Returns a pointer to the configuration manager.
CtrlAgentCfgMgrPtr getCtrlAgentCfgMgr();
/// @brief Returns a const pointer to the HTTP listener used by the process.
///
/// @return Const pointer to the currently used listener or null pointer if
/// we're not listening. In fact, the latter should never be the case given
/// that we provide default listener configuration.
http::ConstHttpListenerPtr getHttpListener() const;
/// @brief Checks if the process is listening to the HTTP requests.
///
/// @return true if the process is listening.
bool isListening() const;
private:
/// @brief Removes listeners which are no longer in use.
///
/// This method should be called after executing
/// @ref CtrlAgentProcess::configure to remove listeners used previously
/// (no longer used because the listening address and port has changed as
// a result of the reconfiguration). If there are no listeners additional
/// to the one that is currently in use, the method has no effect.
/// This method is reused to remove all listeners at shutdown time.
///
/// @param leaving The number of listener to leave (default one).
void garbageCollectListeners(size_t leaving = 1);
/// @brief Polls all ready handlers and then runs one handler if none
/// handlers have been executed as a result of polling.
///
/// @return Number of executed handlers.
size_t runIO();
/// @brief Holds a list of pointers to the active listeners.
std::vector<http::HttpListenerPtr> http_listeners_;
};
/// @brief Defines a shared pointer to CtrlAgentProcess.
typedef boost::shared_ptr<CtrlAgentProcess> CtrlAgentProcessPtr;
} // namespace isc::agent
} // namespace isc
#endif // CTRL_AGENT_PROCESS_H
|