Kea 2.7.5
netconf_process.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2024 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 <asiolink/io_address.h>
11#include <asiolink/io_error.h>
14#include <config/timeouts.h>
15#include <netconf/netconf.h>
17#include <netconf/netconf_log.h>
19
20using namespace isc::asiolink;
21using namespace isc::config;
22using namespace isc::data;
23using namespace isc::http;
24using namespace isc::process;
25
26namespace isc {
27namespace netconf {
28
30 const asiolink::IOServicePtr& io_service)
31 : DProcessBase(name, io_service, DCfgMgrBasePtr(new NetconfCfgMgr())) {
32}
33
34void
37
38void
41
42 try {
43 // Call init.
44 agent_.init(getNetconfCfgMgr());
45
46 // Let's process incoming data or expiring timers in a loop until
47 // shutdown condition is detected.
48 while (!shouldShutdown()) {
49 runIO();
50 }
52
53 } catch (const std::exception& ex) {
55 try {
57 } catch (...) {
58 // Ignore double errors
59 }
60 isc_throw(DProcessBaseError, "Process run method failed: " << ex.what());
61 }
62
64}
65
66size_t
67NetconfProcess::runIO() {
68 // Handle events registered by hooks using external IOService objects.
69 IOServiceMgr::instance().pollIOServices();
70 size_t cnt = getIOService()->poll();
71 if (!cnt) {
72 cnt = getIOService()->runOne();
73 }
74 return (cnt);
75}
76
82
85 bool check_only) {
86 ConstElementPtr answer =
87 getCfgMgr()->simpleParseConfig(config_set, check_only);
88 int rcode = 0;
89 config::parseAnswer(rcode, answer);
90
92 try {
93 // Handle events registered by hooks using external IOService objects.
94 IOServiceMgr::instance().pollIOServices();
95 } catch (const std::exception& ex) {
96 std::ostringstream err;
97 err << "Error initializing hooks: " << ex.what();
99 }
100
101 return (answer);
102}
103
106 return (boost::dynamic_pointer_cast<NetconfCfgMgr>(getCfgMgr()));
107}
108
109} // namespace netconf
110} // namespace isc
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void init(NetconfCfgMgrPtr cfg_mgr)
Initialization.
Definition netconf.cc:155
Ctrl Netconf Configuration Manager.
NetconfCfgMgrPtr getNetconfCfgMgr()
Returns a pointer to the configuration manager.
void init() override final
Initialize the Netconf process.
void run() override final
Implements the process's event loop.
isc::data::ConstElementPtr shutdown(isc::data::ConstElementPtr args) override final
Initiates the process's shutdown process.
NetconfProcess(const char *name, const asiolink::IOServicePtr &io_service)
Constructor.
isc::data::ConstElementPtr configure(isc::data::ConstElementPtr config_set, bool check_only=false) override final
Processes the given configuration.
Exception thrown if the process encountered an operational error.
Definition d_process.h:24
Application Process Interface.
Definition d_process.h:75
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition d_process.h:162
void stopIOService()
Convenience method for stopping IOservice processing.
Definition d_process.h:184
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition d_process.h:155
asiolink::IOServicePtr & getIOService()
Fetches the controller's IOService.
Definition d_process.h:176
DCfgMgrBasePtr & getCfgMgr()
Fetches the process's configuration manager.
Definition d_process.h:191
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Definition macros.h:38
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
const int DBGLVL_START_SHUT
This is given a value of 0 as that is the level selected if debugging is enabled without giving a lev...
const isc::log::MessageID NETCONF_FAILED
isc::log::Logger netconf_logger(NETCONF_LOGGER_NAME)
Base logger for the netconf agent.
Definition netconf_log.h:49
const isc::log::MessageID NETCONF_STARTED
const isc::log::MessageID NETCONF_RUN_EXIT
boost::shared_ptr< NetconfCfgMgr > NetconfCfgMgrPtr
Defines a shared pointer to NetconfCfgMgr.
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition d_cfg_mgr.h:247
Defines the logger used by the top-level component of kea-lfc.
Contains declarations for loggers used by the Kea netconf agent.