From f02cbb5909b71da9fd31b49329a7a5c42c62e8f0 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 16 Jul 2019 16:30:47 +0200 Subject: [PATCH] [208-finish-move-logging] Addressed comment --- src/lib/process/d_controller.cc | 90 +++++++++++++-------------------- src/lib/process/d_controller.h | 9 ++++ 2 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc index 8938d542bd..735a9181ba 100644 --- a/src/lib/process/d_controller.cc +++ b/src/lib/process/d_controller.cc @@ -528,6 +528,38 @@ DControllerBase::configWriteHandler(const std::string&, + filename + " successful", params)); } +void +DControllerBase::handleOtherObjects(ConstElementPtr args) { + // Check obsolete or unknown (aka unsupported) objects. + const std::string& app_name = getAppName(); + for (auto obj : args->mapValue()) { + const std::string& obj_name = obj.first; + if (obj_name == app_name) { + continue; + } + if (obj_name == "Logging") { + LOG_WARN(dctl_logger, DCTL_CONFIG_DEPRECATED) + .arg("'Logging' defined in top level. This is deprecated." + " Please define it in the '" + app_name + "' scope."); + continue; + } + LOG_WARN(dctl_logger, DCTL_CONFIG_DEPRECATED) + .arg("'" + obj_name + "', defining anything in global level besides '" + + app_name + "' is no longer supported."); + } + + // Relocate Logging: if there is a global Logging object takes its + // loggers entry, move the entry to AppName object and remove + // now empty Logging. + Daemon::relocateLogging(args, app_name); + + // We are starting the configuration process so we should remove any + // staging configuration that has been created during previous + // configuration attempts. + // We're not using cfgmgr to store logging information anymore. + // isc::dhcp::CfgMgr::instance().rollback(); +} + ConstElementPtr DControllerBase::configTestHandler(const std::string&, ConstElementPtr args) { const int status_code = COMMAND_ERROR; // 1 indicates an error @@ -555,33 +587,8 @@ DControllerBase::configTestHandler(const std::string&, ConstElementPtr args) { return (result); } - // Check obsolete or unknown (aka unsupported) objects. - for (auto obj : args->mapValue()) { - const std::string& obj_name = obj.first; - if (obj_name == app_name) { - continue; - } - if (obj_name == "Logging") { - LOG_WARN(dctl_logger, DCTL_CONFIG_DEPRECATED) - .arg("'Logging' defined in top level. This is deprecated." - " Please define it in the '" + app_name + "' scope."); - continue; - } - LOG_WARN(dctl_logger, DCTL_CONFIG_DEPRECATED) - .arg("'" + obj_name + "', defining anything in global level besides '" - + app_name + "' is no longer supported."); - } - - // Relocate Logging: if there is a global Logging object takes its - // loggers entry, move the entry to AppName object and remove - // now empty Logging. - Daemon::relocateLogging(args, getAppName()); - - // We are starting the configuration process so we should remove any - // staging configuration that has been created during previous - // configuration attempts. - // We're not using cfgmgr to store logging information anymore. - // isc::dhcp::CfgMgr::instance().rollback(); + // Handle other (i.e. not application name) objects (e.g. Logging). + handleOtherObjects(args); // Now we check the server proper. return (checkConfig(module_config)); @@ -622,33 +629,8 @@ DControllerBase::configSetHandler(const std::string&, ConstElementPtr args) { try { - // Check obsolete or unknown (aka unsupported) objects. - for (auto obj : args->mapValue()) { - const std::string& obj_name = obj.first; - if (obj_name == app_name) { - continue; - } - if (obj_name == "Logging") { - LOG_WARN(dctl_logger, DCTL_CONFIG_DEPRECATED) - .arg("'Logging' defined in top level. This is deprecated." - " Please define it in the '" + app_name + "' scope."); - continue; - } - LOG_WARN(dctl_logger, DCTL_CONFIG_DEPRECATED) - .arg("'" + obj_name + "', defining anything in global level besides '" - + app_name + "' is no longer supported."); - } - - // Relocate Logging: if there is a global Logging object takes its - // loggers entry, move the entry to AppName object and remove - // now empty Logging. - Daemon::relocateLogging(args, getAppName()); - - // We are starting the configuration process so we should remove any - // staging configuration that has been created during previous - // configuration attempts. - // We're not using cfgmgr to store logging information anymore. - // isc::dhcp::CfgMgr::instance().rollback(); + // Handle other (i.e. not application name) objects (e.g. Logging). + handleOtherObjects(args); // Temporary storage for logging configuration ConfigPtr storage(new ConfigBase()); diff --git a/src/lib/process/d_controller.h b/src/lib/process/d_controller.h index 8f971a0451..8093bcf4ba 100644 --- a/src/lib/process/d_controller.h +++ b/src/lib/process/d_controller.h @@ -601,6 +601,15 @@ protected: /// @return a string containing additional version info virtual std::string getVersionAddendum() { return (""); } + /// @brief Deals with other (i.e. not application name) global objects. + /// + /// Code shared between config-test and config-set command handlers: + /// - check obsolete or unknown (aka unsupported) objects. + /// - relocate Logging. + /// + /// @param args Command arguments. + void handleOtherObjects(isc::data::ConstElementPtr args); + private: /// @brief Name of the service under control. /// This name is used as the configuration module name and appears in log -- 2.47.2