Commit 2b94f6e6 authored by Francis Dupont's avatar Francis Dupont

[208-move-logging-from-global-objects-to-global-params] Some updates - checkpoint of the day

parent 7bc4cc18
// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2017-2019 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
......@@ -103,6 +103,8 @@ public:
D2GetConfigTest()
: rcode_(-1) {
srv_.reset(new D2CfgMgr());
// Enforce not verbose mode.
Daemon::setVerbose(false);
// Create fresh context.
resetConfiguration();
}
......
......@@ -32,6 +32,21 @@
]
},
"ip-address": "172.16.1.10",
"loggers": [
{
"debuglevel": 0,
"name": "kea-dhcp-ddns",
"output_options": [
{
"flush": true,
"maxsize": 204800,
"maxver": 4,
"output": "stdout"
}
],
"severity": "INFO"
}
],
"ncr-format": "JSON",
"ncr-protocol": "UDP",
"port": 53001,
......
......@@ -343,7 +343,7 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
Daemon::configureLogger(dhcp4, CfgMgr::instance().getStagingCfg());
// Let's apply the new logging. We do it early, so we'll be able to print
// out what exactly is wrong with the new socnfig in case of problems.
// out what exactly is wrong with the new config in case of problems.
CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
// Log deprecated objects.
......
......@@ -345,7 +345,7 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
Daemon::configureLogger(dhcp6, CfgMgr::instance().getStagingCfg());
// Let's apply the new logging. We do it early, so we'll be able to print
// out what exactly is wrong with the new socnfig in case of problems.
// out what exactly is wrong with the new config in case of problems.
CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
// Log deprecated objects.
......
......@@ -34,7 +34,7 @@ public:
/// @name Modifiers and accesors for the configuration objects.
///
/// @warning References to the objects returned by accessors are only
/// valid during the lifetime of the @c SrvConfig object which
/// valid during the lifetime of the @c ConfigBase object which
/// returned them.
///
//@{
......@@ -156,7 +156,7 @@ private:
util::Optional<std::string> server_tag_;
};
/// @brief Non-const pointer to the @c SrvConfig.
/// @brief Non-const pointer to the @c ConfigBase.
typedef boost::shared_ptr<ConfigBase> ConfigPtr;
};
......
// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2019 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
......@@ -10,6 +10,7 @@
#include <dhcp/libdhcp++.h>
#include <process/d_log.h>
#include <process/d_cfg_mgr.h>
#include <process/daemon.h>
#include <util/encode/hex.h>
#include <util/strutil.h>
......@@ -80,6 +81,9 @@ DCfgMgrBase::simpleParseConfig(isc::data::ConstElementPtr config_set,
ConstElementPtr answer;
try {
// Logging is common so factor it.
Daemon::configureLogger(config_set, context_);
// Let's call the actual implementation
answer = parse(config_set, check_only);
......
......@@ -379,29 +379,27 @@ DControllerBase::configFromFile() {
// so we can log things during configuration process.
// Temporary storage for logging configuration
ConfigPtr storage = process_->getCfgMgr()->getContext();
ConfigPtr storage(new ConfigBase());
// Get 'Logging' element from the config and use it to set up
// logging. If there's no such element, we'll just pass NULL.
Daemon::configureLogger(module_config, storage);
// Let's apply the new logging. We do it early, so we'll be able
// to print out what exactly is wrong with the new config in
// case of problems.
storage->applyLoggingCfg();
// Log deprecated objects.
// Log obsolete objects and return an error.
// Log obsolete objects and raise an error.
answer = updateConfig(module_config);
int rcode = 0;
parseAnswer(rcode, answer);
if (!rcode) {
// Configuration successful, so apply the logging configuration
// to log4cplus.
storage->applyLoggingCfg();
}
// In all cases the right logging configuration is in the context.
process_->getCfgMgr()->getContext()->applyLoggingCfg();
} catch (const std::exception& ex) {
// Rollback logging configuration.
// We don't use CfgMgr to store logging information anymore.
// isc::dhcp::CfgMgr::instance().rollback();
process_->getCfgMgr()->getContext()->applyLoggingCfg();
// build an error result
ConstElementPtr error = createAnswer(COMMAND_ERROR,
......
......@@ -53,6 +53,10 @@ may be provided.
This is an informational message emitted when the Kea server is about to begin
retrieving configuration data from one or more configuration backends.
% DCTL_CONFIG_DEPRECATED server configuration includes a deprecated object: %1
This warning message is issued when the configuration includes a deprecated
object (i.e. a top level element) which will be ignored.
% DCTL_CONFIG_FILE_LOAD_FAIL %1 reason: %2
This fatal error message indicates that the application attempted to load its
initial configuration from file and has failed. The service will exit.
......@@ -62,6 +66,10 @@ This critical error message indicates that the initial application
configuration has failed. The service will start, but will not
process requests until the configuration has been corrected.
% DCTL_CONFIG_OBSOLETE server configuration includes an obsolete object: %1
This error message is issued when the configuration includes an obsolete
object (i.e. a top level element).
% DCTL_CONFIG_START parsing new configuration: %1
A debug message indicating that the application process has received an
updated configuration and has passed it to its configuration manager
......
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2019 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
......@@ -622,6 +622,9 @@ AdaptorConfig::preProcess4(ConstElementPtr config) {
if (config->getType() != Element::map) {
isc_throw(BadValue, "preProcess4: not map: " << config->str());
}
if (config->contains("Logging")) {
isc_throw(BadValue, "preProcess4: got Logging object");
}
ConstElementPtr dhcp = config->get("Dhcp4");
if (!dhcp) {
return;
......@@ -638,6 +641,9 @@ AdaptorConfig::preProcess6(ConstElementPtr config) {
if (config->getType() != Element::map) {
isc_throw(BadValue, "preProcess6: not map: " << config->str());
}
if (config->contains("Logging")) {
isc_throw(BadValue, "preProcess6: got Logging object");
}
ConstElementPtr dhcp = config->get("Dhcp6");
if (!dhcp) {
return;
......
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2019 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
......@@ -40,7 +40,7 @@ public:
///
/// @param config The configuration.
/// @throw MissingKey when a required key is missing.
/// @throw BadValue when null or not a map
/// @throw BadValue when null or not a map or deprecated Logging present.
/// @note Does nothing if "Dhcp4" is not present in the map.
static void preProcess4(isc::data::ConstElementPtr config);
......@@ -52,7 +52,7 @@ public:
///
/// @param config The configuration.
/// @throw MissingKey when a required key is missing.
/// @throw BadValue when null or not a map
/// @throw BadValue when null or not a map or deprecated Logging present.
/// @note Does nothing if "Dhcp6" is not present in the map.
static void preProcess6(isc::data::ConstElementPtr config);
......
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2019 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
......@@ -85,14 +85,6 @@ TranslatorConfig::getConfigKea4() {
ElementPtr result = Element::createMap();
ElementPtr dhcp = getServerKeaDhcp4();
result->set("Dhcp4", dhcp);
ConstElementPtr loggers = dhcp->get("loggers");
if (loggers) {
dhcp->remove("loggers");
ElementPtr logging = Element::createMap();
logging->set("loggers", loggers);
result->set("Logging", logging);
}
return (result);
}
......@@ -101,14 +93,6 @@ TranslatorConfig::getConfigKea6() {
ElementPtr result = Element::createMap();
ElementPtr dhcp = getServerKeaDhcp6();
result->set("Dhcp6", dhcp);
ConstElementPtr loggers = dhcp->get("loggers");
if (loggers) {
dhcp->remove("loggers");
ElementPtr logging = Element::createMap();
logging->set("loggers", loggers);
result->set("Logging", logging);
}
return (result);
}
......@@ -467,10 +451,6 @@ TranslatorConfig::setConfigKea4(ConstElementPtr elem) {
if (dhcp) {
setServerKeaDhcp4(dhcp);
}
ConstElementPtr logging = elem->get("Logging");
if (logging) {
setServerKeaLogging(logging);
}
}
void
......@@ -479,10 +459,6 @@ TranslatorConfig::setConfigKea6(ConstElementPtr elem) {
if (dhcp) {
setServerKeaDhcp6(dhcp);
}
ConstElementPtr logging = elem->get("Logging");
if (logging) {
setServerKeaLogging(logging);
}
}
void
......@@ -717,6 +693,10 @@ TranslatorConfig::setServerKeaDhcpCommon(const string& xpath,
ConstElementPtr repr = Element::create(queue_ctrl->str());
setItem(xpath + "/dhcp-queue-control", repr, SR_STRING_T);
}
ConstElementPtr loggers = elem->get("loggers");
if (loggers) {
setLoggers(xpath, loggers);
}
}
void
......@@ -862,14 +842,5 @@ TranslatorConfig::setServerKeaDhcp6(ConstElementPtr elem) {
}
}
void
TranslatorConfig::setServerKeaLogging(ConstElementPtr elem) {
string xpath = "/" + model_ + ":config";
ConstElementPtr loggers = elem->get("loggers");
if (loggers) {
setLoggers(xpath, loggers);
}
}
}; // end of namespace isc::yang
}; // end of namespace isc
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2019 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
......@@ -59,9 +59,9 @@ namespace yang {
/// "reservations": [ <list of host reservations> ],
/// <config-control>,
/// "server-tag": <server tag>,
/// "dhcp-queue-control": { <DHCP queue control> }
/// "dhcp-queue-control": { <DHCP queue control> },
/// "loggers": [ <list of loggers> ]
/// },
/// "Logging": <logging>
/// @endcode
///
/// YANG syntax for kea-dhcp4-server:config is:
......@@ -195,9 +195,9 @@ namespace yang {
/// "reservations": [ <list of host reservations> ],
/// <config-control>,
/// "server-tag": <server tag>,
/// "dhcp-queue-control": { <DHCP queue control> }
/// "dhcp-queue-control": { <DHCP queue control> },
/// "loggers": [ <list of loggers> ]
/// },
/// "Logging": <logging>
/// @endcode
///
/// YANG syntax for kea-dhcp6-server:config is:
......@@ -293,55 +293,6 @@ namespace yang {
/// </config>
/// @endcode
/// JSON syntax for the logging part of kea servers is:
/// @code
/// "Logging": {
/// "loggers": [ <list of loggers> '
/// }
/// @endcode
///
/// Example of Logging simple configuration:
/// @code
/// {
/// ...
/// "Logging":
/// {
/// "loggers":
/// [
/// {
/// "name": "kea-dhcp6",
/// "output_options":
/// [
/// {
/// "output": "stderr"
/// }
/// ],
/// "severity": "DEBUG",
/// "debuglevel": 99
/// }
/// ]
/// }
/// }
/// @endcode
///
/// The same configuration wrote into YANG datastore using @c setConfig()
/// with a kea server model and exported to XML format:
/// @code
/// <config xmlns="urn:ietf:params:xml:ns:yang:kea-dhcp4-server">
/// ...
/// <logger>
/// <name>kea-dhcp6</name>
/// <output-options>
/// <option>
/// <output>stderr</output>
/// </option>
/// </output-options>
/// <debuglevel>99</debuglevel>
/// <severity>DEBUG</severity>
/// </logger>
/// </config>
/// @endcode
/// Inheritance graph between translators is:
///
/// +-----------------------------------------+
......@@ -531,11 +482,6 @@ protected:
/// @param elem The JSON element.
void setServerKeaDhcp6(isc::data::ConstElementPtr elem);
/// @brief set Logging part for kea-*:config.
///
/// @param elem The JSON element.
void setServerKeaLogging(isc::data::ConstElementPtr elem);
/// @brief Retrieves an item and stores in the specified storage.
///
/// This will attempt to retrieve an item and, if exists, will
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment