Kea  2.3.4-git
netconf_process.cc
Go to the documentation of this file.
1 // Copyright (C) 2018-2022 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(0, "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
void run() override final
Implements the process&#39;s event loop.
isc::data::ConstElementPtr configure(isc::data::ConstElementPtr config_set, bool check_only=false) override final
Processes the given configuration.
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition: d_process.h:166
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition: macros.h:20
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition: d_cfg_mgr.h:247
const isc::log::MessageID NETCONF_STARTED
const isc::log::MessageID NETCONF_FAILED
Ctrl Netconf Configuration Manager.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void init() override final
Initialize the Netconf process.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
DCfgMgrBasePtr & getCfgMgr()
Fetches the process&#39;s configuration manager.
Definition: d_process.h:195
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
const isc::log::MessageID NETCONF_RUN_EXIT
isc::log::Logger netconf_logger(NETCONF_LOGGER_NAME)
Base logger for the netconf agent.
Definition: netconf_log.h:49
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:188
isc::data::ConstElementPtr shutdown(isc::data::ConstElementPtr args) override final
Initiates the process&#39;s shutdown process.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Defines the logger used by the top-level component of kea-lfc.
This file contains several functions and constants that are used for handling commands and responses ...
asiolink::IOServicePtr & getIoService()
Fetches the controller&#39;s IOService.
Definition: d_process.h:180
Exception thrown if the process encountered an operational error.
Definition: d_process.h:24
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition: macros.h:14
Contains declarations for loggers used by the Kea netconf agent.
boost::shared_ptr< NetconfCfgMgr > NetconfCfgMgrPtr
Defines a shared pointer to NetconfCfgMgr.
Application Process Interface.
Definition: d_process.h:81
NetconfCfgMgrPtr getNetconfCfgMgr()
Returns a pointer to the configuration manager.
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Definition: macros.h:38
void init(NetconfCfgMgrPtr cfg_mgr)
Initialization.
Definition: netconf.cc:150
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
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition: d_process.h:159