/// @brief Compares two configuration.
///
/// @param other the other configuration to compare to
- virtual bool equals(const ConfigBase& other) const;
+ bool equals(const ConfigBase& other) const;
/// @brief Converts to Element representation
///
/// by descendant classes.
///
/// @param new_config this configuration will be copied to new_config
- virtual void copy(ConfigBase& new_config) const;
+ void copy(ConfigBase& new_config) const;
private:
/// @brief Logging specific information.
/// // Restore from backup
/// context_ = backup_copy;
///
-class DCfgContextBase : public isc::dhcp::UserContext, public isc::data::CfgToElement {
+class DCfgContextBase : public isc::data::UserContext, public isc::data::CfgToElement {
public:
/// @brief Indicator that a configuration parameter is optional.
static const bool OPTIONAL = true;
try {
createPIDFile();
- } catch (const dhcp::DaemonPIDExists& ex) {
+ } catch (const DaemonPIDExists& ex) {
LOG_FATAL(dctl_logger, DCTL_ALREADY_RUNNING)
.arg(bin_name_).arg(ex.what());
isc_throw (LaunchError, "Launch Failed: " << ex.what());
#include <asiolink/io_service.h>
#include <cc/data.h>
-#include <dhcpsrv/daemon.h>
#include <exceptions/exceptions.h>
#include <log/logger_support.h>
+#include <process/daemon.h>
#include <process/d_log.h>
#include <process/d_process.h>
#include <process/io_service_signal.h>
/// NOTE: Derivations must supply their own static singleton instance method(s)
/// for creating and fetching the instance. The base class declares the instance
/// member in order for it to be available for static callback functions.
-class DControllerBase : public dhcp::Daemon {
+class DControllerBase : public Daemon {
public:
/// @brief Constructor
///
-// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 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
#include <config.h>
#include <cc/data.h>
-#include <dhcpsrv/cfgmgr.h>
-#include <dhcpsrv/daemon.h>
+#include <process/daemon.h>
+#include <process/log_parser.h>
#include <exceptions/exceptions.h>
#include <log/logger_name.h>
#include <log/logger_support.h>
-#include <logging.h>
+#include <process/cfg_base.h>
#include <util/filename.h>
#include <boost/bind.hpp>
/// This file provides stub implementations that are expected to be redefined
/// in derived classes (e.g. ControlledDhcpv6Srv)
namespace isc {
-namespace dhcp {
+namespace process {
+
+bool Daemon::verbose_ = false;
+
+std::string Daemon::default_logger_name_("kea");
Daemon::Daemon()
: signal_set_(), signal_handler_(), config_file_(""), proc_name_(""),
- pid_file_dir_(DHCP_DATA_DIR), pid_file_(), am_file_author_(false) {
+ pid_file_dir_(DATA_DIR), pid_file_(), am_file_author_(false) {
// The pid_file_dir can be overridden via environment variable
// This is primarily intended to simplify testing
}
void Daemon::configureLogger(const isc::data::ConstElementPtr& log_config,
- const SrvConfigPtr& storage) {
+ const ConfigPtr& storage) {
if (log_config) {
isc::data::ConstElementPtr loggers = log_config->get("loggers");
if (loggers) {
LogConfigParser parser(storage);
- parser.parseConfiguration(loggers, CfgMgr::instance().isVerbose());
+ parser.parseConfiguration(loggers, verbose_);
}
}
}
void
Daemon::setVerbose(bool verbose) {
- CfgMgr::instance().setVerbose(verbose);
+ verbose_ = verbose;
}
bool
-Daemon::getVerbose() const {
- return (CfgMgr::instance().isVerbose());
+Daemon::getVerbose() {
+ return (verbose_);
}
void Daemon::loggerInit(const char* name, bool verbose) {
size_t
Daemon::writeConfigFile(const std::string& config_file,
isc::data::ConstElementPtr cfg) const {
- if (!cfg) {
- cfg = CfgMgr::instance().getCurrentCfg()->toElement();
- }
-
if (!cfg) {
isc_throw(Unexpected, "Can't write configuration: conversion to JSON failed");
}
-// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 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
#define DAEMON_H
#include <cc/data.h>
-#include <dhcpsrv/srv_config.h>
+#include <process/config_base.h>
#include <util/pid_file.h>
#include <util/signal_set.h>
#include <boost/noncopyable.hpp>
#include <string>
namespace isc {
-namespace dhcp {
+namespace process {
/// @brief Exception thrown when a the PID file points to a live PID
class DaemonPIDExists : public Exception {
/// @param log_config JSON structures that describe logging
/// @param storage configuration will be stored here
static void configureLogger(const isc::data::ConstElementPtr& log_config,
- const isc::dhcp::SrvConfigPtr& storage);
+ const isc::process::ConfigPtr& storage);
/// @brief Sets or clears verbose mode
///
/// config file are ignored.
///
/// @param verbose specifies if verbose should be set or not
- void setVerbose(const bool verbose);
+ static void setVerbose(const bool verbose);
/// @brief Returns if running in verbose mode
///
/// @return verbose mode
- bool getVerbose() const;
+ static bool getVerbose();
/// @brief returns Kea version on stdout and exits.
///
/// PID of the current process is used.
void createPIDFile(int pid = 0);
+ /// @brief Returns default logger name.
+ static std::string getDefaultLoggerName() {
+ return (default_logger_name_);
+ }
+
+ /// @brief Sets the default logger name.
+ ///
+ /// This name is used in cases when a user doesn't provide a configuration
+ /// for logger in the Kea configuration file.
+ static void setDefaultLoggerName(const std::string& logger) {
+ default_logger_name_ = logger;
+ }
+
protected:
/// @brief Invokes handler for the next received signal.
/// @brief Pointer to the PID file for this process
isc::util::PIDFilePtr pid_file_;
+ /// @brief Indicates whether verbose mode is turned on or not.
+ static bool verbose_;
+
+ /// @brief Stores default logger name
+ static std::string default_logger_name_;
+
/// @brief Flag indicating if this instance created the file
bool am_file_author_;
};
-// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 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
#include <config.h>
#include <cc/data.h>
-#include <dhcpsrv/logging.h>
+#include <process/log_parser.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <log/logger_specification.h>
using namespace isc::log;
namespace isc {
-namespace dhcp {
+namespace process {
-LogConfigParser::LogConfigParser(const SrvConfigPtr& storage)
+LogConfigParser::LogConfigParser(const ConfigPtr& storage)
:config_(storage), verbose_(false) {
if (!storage) {
isc_throw(BadValue, "LogConfigParser needs a pointer to the "
-// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 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
#define DHCPSRV_LOGGING_H
#include <cc/data.h>
-#include <dhcpsrv/srv_config.h>
+#include <process/logging_info.h>
+#include <process/config_base.h>
#include <vector>
namespace isc {
-namespace dhcp {
+namespace process {
/// @brief Configures log4cplus by translating Kea configuration structures
///
/// @brief Constructor
///
/// @param storage parsed logging configuration will be stored here
- LogConfigParser(const SrvConfigPtr& storage);
+ LogConfigParser(const ConfigPtr& storage);
/// @brief Parses specified configuration
///
/// @brief Configuration is stored here
///
/// LogConfigParser class uses only config_->logging_info_ field.
- SrvConfigPtr config_;
+ ConfigPtr config_;
/// @brief Verbose mode
///
-// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
-#include <dhcpsrv/cfgmgr.h>
-#include <dhcpsrv/logging_info.h>
+#include <process/logging_info.h>
+#include <process/daemon.h>
#include <log/logger_name.h>
using namespace isc::log;
using namespace isc::data;
namespace isc {
-namespace dhcp {
+namespace process {
bool
LoggingDestination::equals(const LoggingDestination& other) const {
: name_("kea"), severity_(isc::log::INFO), debuglevel_(0) {
// If configuration Manager is in the verbose mode, we need to modify the
// default settings.
- if (CfgMgr::instance().isVerbose()) {
+ if (Daemon::getVerbose()) {
severity_ = isc::log::DEBUG;
debuglevel_ = 99;
}
// If the process has set the non-empty name for the default logger,
// let's use this name.
- std::string logger_name = CfgMgr::instance().getDefaultLoggerName();
- if (!logger_name.empty()) {
- name_ = logger_name;
+ std::string default_logger = Daemon::getDefaultLoggerName();
+ if (!default_logger.empty()) {
+ name_ = default_logger;
}
// Add a default logging destination in case use hasn't provided a
-// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 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
#include <vector>
namespace isc {
-namespace dhcp {
+namespace process {
/// @brief Defines single logging destination
///
/// "severity": "WARN",
/// "debuglevel": 99
/// },
-class LoggingInfo : public UserContext, public isc::data::CfgToElement {
+class LoggingInfo : public isc::data::UserContext, public isc::data::CfgToElement {
public:
/// @brief logging name
};
/// @brief storage for logging information in log4cplus format
-typedef std::vector<isc::dhcp::LoggingInfo> LoggingInfoStorage;
+typedef std::vector<isc::process::LoggingInfo> LoggingInfoStorage;
}
}
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/process/tests\"
+AM_CPPFLAGS += -DDATA_DIR="\"$(dhcp_data_dir)\""
AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
AM_CXXFLAGS = $(KEA_CXXFLAGS)
libprocess_unittests_SOURCES += d_controller_unittests.cc
libprocess_unittests_SOURCES += daemon_unittest.cc
libprocess_unittests_SOURCES += io_service_signal_unittests.cc
+libprocess_unittests_SOURCES += log_parser_unittests.cc
+libprocess_unittests_SOURCES += logging_info_unittests.cc
libprocess_unittests_SOURCES += run_unittests.cc
libprocess_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
libprocess_unittests_LDADD = $(top_builddir)/src/lib/process/testutils/libprocesstest.la
libprocess_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
libprocess_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
+libprocess_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
libprocess_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
libprocess_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
libprocess_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
#include <exceptions/exceptions.h>
#include <cc/data.h>
#include <dhcpsrv/cfgmgr.h>
-#include <dhcpsrv/daemon.h>
-#include <dhcpsrv/logging.h>
+#include <process/daemon.h>
+#include <process/config_base.h>
+#include <process/log_parser.h>
#include <log/logger_support.h>
#include <gtest/gtest.h>
#include <sys/wait.h>
using namespace isc;
-using namespace isc::dhcp;
+using namespace isc::process;
using namespace isc::data;
namespace isc {
-namespace dhcp {
+namespace process {
// @brief Derived Daemon class
class DaemonImpl : public Daemon {
EXPECT_TRUE(instance2.getConfigFile().empty());
EXPECT_TRUE(instance2.getProcName().empty());
- EXPECT_EQ(CfgMgr::instance().getDataDir(),instance2.getPIDFileDir());
+ EXPECT_EQ(std::string(DATA_DIR), instance2.getPIDFileDir());
EXPECT_TRUE(instance2.getPIDFileName().empty());
}
// More dedicated tests are available for LogConfigParser class.
// See logger_unittest.cc
TEST_F(DaemonTest, parsingConsoleOutput) {
- CfgMgr::instance().setVerbose(false);
+ Daemon::setVerbose(false);
// Storage - parsed configuration will be stored here
- SrvConfigPtr storage(new SrvConfig());
+ ConfigPtr storage(new ConfigBase());
const char* config_txt =
"{ \"loggers\": ["
-// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 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
#include <config.h>
#include <cc/data.h>
-#include <dhcpsrv/dhcpsrv_log.h>
-#include <dhcpsrv/logging.h>
+#include <process/log_parser.h>
+#include <process/process_messages.h>
#include <exceptions/exceptions.h>
#include <log/logger_support.h>
+#include <process/d_log.h>
#include <testutils/io_utils.h>
#include <gtest/gtest.h>
using namespace isc;
-using namespace isc::dhcp;
+using namespace isc::process;
using namespace isc::data;
namespace {
// Checks that the constructor is able to process specified storage properly.
TEST_F(LoggingTest, constructor) {
- SrvConfigPtr null_ptr;
+ ConfigPtr null_ptr;
EXPECT_THROW(LogConfigParser parser(null_ptr), BadValue);
- SrvConfigPtr nonnull(new SrvConfig());
+ ConfigPtr nonnull(new ConfigBase());
EXPECT_NO_THROW(LogConfigParser parser(nonnull));
}
" }"
"]}";
- SrvConfigPtr storage(new SrvConfig());
+ ConfigPtr storage(new ConfigBase());
LogConfigParser parser(storage);
" }"
"]}";
- SrvConfigPtr storage(new SrvConfig());
+ ConfigPtr storage(new ConfigBase());
LogConfigParser parser(storage);
" }"
"]}";
- SrvConfigPtr storage(new SrvConfig());
+ ConfigPtr storage(new ConfigBase());
LogConfigParser parser(storage);
" }"
"]}";
- SrvConfigPtr storage(new SrvConfig());
+ ConfigPtr storage(new ConfigBase());
LogConfigParser parser(storage);
"]}";
// Create our server config container.
- SrvConfigPtr server_cfg(new SrvConfig());
+ ConfigPtr server_cfg(new ConfigBase());
// LogConfigParser expects a list of loggers, so parse
// the JSON text and extract the "loggers" element from it
for (int i = 1; i < TEST_MAX_VERS + 1; i++) {
// Output the big log and make sure we get the expected rotation file.
- LOG_INFO(logger, DHCPSRV_CFGMGR_ADD_IFACE).arg(big_arg);
+ LOG_INFO(logger, DCTL_CONFIG_COMPLETE).arg(big_arg);
EXPECT_TRUE(isc::test::fileExists(logName(i).c_str()));
}
-// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
-#include <dhcpsrv/cfgmgr.h>
-#include <dhcpsrv/logging_info.h>
+#include <process/daemon.h>
+#include <process/logging_info.h>
#include <testutils/test_to_element.h>
#include <gtest/gtest.h>
-using namespace isc::dhcp;
+using namespace isc::process;
using namespace isc::test;
using namespace isc::data;
/// @brief Setup the test.
virtual void SetUp() {
- CfgMgr::instance().setVerbose(false);
+ Daemon::setVerbose(false);
}
/// @brief Clear after the test.
virtual void TearDown() {
- CfgMgr::instance().setVerbose(false);
+ Daemon::setVerbose(false);
}
};
expected = header + comment + ",\n" + begin + "INFO" + dbglvl + "0" + trailer;
runToElementTest<LoggingInfo>(expected, info_non_verbose);
- CfgMgr::instance().setVerbose(true);
+ Daemon::setVerbose(true);
LoggingInfo info_verbose;
EXPECT_EQ("kea", info_verbose.name_);
EXPECT_EQ(isc::log::DEBUG, info_verbose.severity_);