Kea  2.5.3
netconf_process.cc
Go to the documentation of this file.
1 // Copyright (C) 2018-2023 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>
12 #include <cc/command_interpreter.h>
13 #include <config/timeouts.h>
14 #include <netconf/netconf.h>
16 #include <netconf/netconf_log.h>
18 
19 using namespace isc::asiolink;
20 using namespace isc::config;
21 using namespace isc::data;
22 using namespace isc::http;
23 using namespace isc::process;
24 
25 namespace isc {
26 namespace netconf {
27 
28 NetconfProcess::NetconfProcess(const char* name,
29  const asiolink::IOServicePtr& io_service)
30  : DProcessBase(name, io_service, DCfgMgrBasePtr(new NetconfCfgMgr())) {
31 }
32 
33 void
35 }
36 
37 void
40 
41  try {
42  // Call init.
43  agent_.init(getNetconfCfgMgr());
44 
45  // Let's process incoming data or expiring timers in a loop until
46  // shutdown condition is detected.
47  while (!shouldShutdown()) {
48  runIO();
49  }
50  stopIOService();
51 
52  } catch (const std::exception& ex) {
53  LOG_FATAL(netconf_logger, NETCONF_FAILED).arg(ex.what());
54  try {
55  stopIOService();
56  } catch (...) {
57  // Ignore double errors
58  }
60  "Process run method failed: " << ex.what());
61  }
62 
64 }
65 
66 size_t
67 NetconfProcess::runIO() {
68  size_t cnt = getIoService()->get_io_service().poll();
69  if (!cnt) {
70  cnt = getIoService()->get_io_service().run_one();
71  }
72  return (cnt);
73 }
74 
77  setShutdownFlag(true);
78  return (isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Netconf is shutting down"));
79 }
80 
83  bool check_only) {
84  ConstElementPtr answer =
85  getCfgMgr()->simpleParseConfig(config_set, check_only);
86  int rcode = 0;
87  config::parseAnswer(rcode, answer);
88  return (answer);
89 }
90 
93  return (boost::dynamic_pointer_cast<NetconfCfgMgr>(getCfgMgr()));
94 }
95 
96 } // namespace netconf
97 } // 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:150
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.
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:160
asiolink::IOServicePtr & getIoService()
Fetches the controller's IOService.
Definition: d_process.h:174
DCfgMgrBasePtr & getCfgMgr()
Fetches the process's configuration manager.
Definition: d_process.h:189
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:182
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition: d_process.h:153
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
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
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...
Definition: log_dbglevels.h:50
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.