Commit 300c6809 authored by Francis Dupont's avatar Francis Dupont Committed by Marcin Siodelski

[#1041] Checkpoint: moved uptime/reload to libprocess

parent f3f5125e
......@@ -28,6 +28,8 @@
"support": [
"kea-dhcp4",
"kea-dhcp6"
"kea-dhcp6",
"kea-dhcp-ddns",
"kea-ctrl-agent"
]
}
......@@ -619,6 +619,8 @@ The D2 server supports only a subset of DHCPv4 / DHCPv6 server commands:
- shutdown
- status-get
- version-get
.. _agent-commands:
......@@ -646,4 +648,6 @@ commands are handled by the CA and they relate to the CA process itself:
- shutdown
- status-get
- version-get
......@@ -295,6 +295,7 @@ The D2 server supports the following operational commands:
- config-write
- list-commands
- shutdown
- status-get
- version-get
.. _d2-tsig-key-list-config:
......
......@@ -5536,6 +5536,7 @@ The DHCPv4 server supports the following operational commands:
- leases-reclaim
- list-commands
- shutdown
- status-get
- version-get
as described in :ref:`commands-common`. In addition, it supports the
......
......@@ -5548,6 +5548,7 @@ The DHCPv6 server supports the following operational commands:
- leases-reclaim
- list-commands
- shutdown
- status-get
- version-get
as described in :ref:`commands-common`. In addition, it supports the
......
......@@ -14,7 +14,6 @@
#include <database/database_connection.h>
#include <dhcpsrv/timer_mgr.h>
#include <dhcp4/dhcp4_srv.h>
#include <boost/date_time/posix_time/posix_time.hpp>
namespace isc {
namespace dhcp {
......@@ -122,6 +121,7 @@ public:
return (server_);
}
private:
/// @brief Callback that will be called from iface_mgr when data
/// is received over control socket.
......@@ -427,9 +427,6 @@ private:
/// Shared pointer to the instance of timer @c TimerMgr is held here to
/// make sure that the @c TimerMgr outlives instance of this class.
TimerMgrPtr timer_mgr_;
/// @brief Timestamp of the start of the server.
boost::posix_time::ptime start_;
};
}; // namespace isc::dhcp
......
......@@ -14,7 +14,6 @@
#include <database/database_connection.h>
#include <dhcpsrv/timer_mgr.h>
#include <dhcp6/dhcp6_srv.h>
#include <boost/date_time/posix_time/posix_time.hpp>
namespace isc {
namespace dhcp {
......@@ -425,9 +424,6 @@ private:
/// Shared pointer to the instance of timer @c TimerMgr is held here to
/// make sure that the @c TimerMgr outlives instance of this class.
TimerMgrPtr timer_mgr_;
/// @brief Timestamp of the start of the server.
boost::posix_time::ptime start_;
};
}; // namespace isc::dhcp
......
......@@ -30,7 +30,6 @@
#include <cc/user_context.h>
#include <cc/simple_parser.h>
#include <boost/shared_ptr.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <vector>
#include <stdint.h>
......@@ -680,18 +679,6 @@ public:
/// @param srv_elem server top level map to alter
static void moveDdnsParams(isc::data::ElementPtr srv_elem);
/// @brief Returns the last commit timestamp.
/// @return the last commit timestamp.
boost::posix_time::ptime getLastCommitTime() const {
return (last_commit_time_);
}
/// @brief Sets the last commit timestamp.
/// @param last_commit_time last commit timestamp.
void setLastCommitTime(const boost::posix_time::ptime& last_commit_time) {
last_commit_time_ = last_commit_time;
}
/// @brief Unparse a configuration object
///
/// @return a pointer to unparsed configuration
......@@ -845,9 +832,6 @@ private:
/// @brief Pointer to the configuration consistency settings
CfgConsistencyPtr cfg_consist_;
/// @brief Stores the last commit timestamp.
boost::posix_time::ptime last_commit_time_;
};
/// @name Pointers to the @c SrvConfig object.
......
......@@ -12,6 +12,7 @@
#include <process/config_ctl_info.h>
#include <process/logging_info.h>
#include <util/optional.h>
#include <boost/date_time/posix_time/posix_time.hpp>
namespace isc {
namespace process {
......@@ -134,6 +135,18 @@ public:
return (server_tag_);
}
/// @brief Returns the last commit timestamp.
/// @return the last commit timestamp.
boost::posix_time::ptime getLastCommitTime() const {
return (last_commit_time_);
}
/// @brief Sets the last commit timestamp.
/// @param last_commit_time last commit timestamp.
void setLastCommitTime(const boost::posix_time::ptime& last_commit_time) {
last_commit_time_ = last_commit_time;
}
protected:
/// @brief Copies the current configuration to a new configuration.
///
......@@ -154,6 +167,9 @@ private:
/// @brief Logical name of the server
util::Optional<std::string> server_tag_;
/// @brief Stores the last commit timestamp.
boost::posix_time::ptime last_commit_time_;
};
/// @brief Non-const pointer to the @c ConfigBase.
......
......@@ -99,6 +99,9 @@ DCfgMgrBase::simpleParseConfig(isc::data::ConstElementPtr config_set,
post_config_cb();
}
LOG_INFO(dctl_logger, DCTL_CONFIG_COMPLETE).arg(getConfigSummary(0));
// Set the last commit timestamp.
auto now = boost::posix_time::second_clock::universal_time();
context_->setLastCommitTime(now);
} else {
rollback = true;
}
......
......@@ -135,6 +135,9 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) {
<< comment->stringValue());
}
// Note that the controller was started.
start_ = boost::posix_time::second_clock::universal_time();
// Everything is clear for launch, so start the application's
// event loop.
try {
......@@ -636,6 +639,26 @@ DControllerBase::serverTagGetHandler(const std::string&, ConstElementPtr) {
return (createAnswer(COMMAND_SUCCESS, response));
}
ConstElementPtr
DControllerBase::statusGetHandler(const std::string&, ConstElementPtr) {
ElementPtr status = Element::createMap();
status->set("pid", Element::create(static_cast<int>(getpid())));
auto now = boost::posix_time::second_clock::universal_time();
if (!start_.is_not_a_date_time()) {
auto uptime = now - start_;
status->set("uptime", Element::create(uptime.total_seconds()));
}
auto last_commit = process_->getCfgMgr()->getContext()->getLastCommitTime();
if (!last_commit.is_not_a_date_time()) {
auto reload = now - last_commit;
status->set("reload", Element::create(reload.total_seconds()));
}
return (createAnswer(COMMAND_SUCCESS, status));
}
ConstElementPtr
DControllerBase::versionGetHandler(const std::string&, ConstElementPtr) {
ConstElementPtr answer;
......
......@@ -123,9 +123,10 @@ public:
/// 1. parse command line arguments
/// 2. instantiate and initialize the application process
/// 3. load the configuration file
/// 4. initialize signal handling
/// 5. start and wait on the application process event loop
/// 6. exit to the caller
/// 4. record the start timestamp
/// 5. initialize signal handling
/// 6. start and wait on the application process event loop
/// 7. exit to the caller
///
/// It is intended to be called from main() and be given the command line
/// arguments.
......@@ -340,6 +341,19 @@ public:
serverTagGetHandler(const std::string& command,
isc::data::ConstElementPtr args);
/// @brief handler for status-get command
///
/// This method handles the status-get command, which retrieves
/// the server process information i.e. the pid and returns it in
/// response.
///
/// @param command (ignored)
/// @param args (ignored)
/// @return process information wrapped in a response
isc::data::ConstElementPtr
statusGetHandler(const std::string& command,
isc::data::ConstElementPtr args);
protected:
/// @brief Virtual method that provides derivations the opportunity to
/// support additional command line options. It is invoked during command
......
......@@ -134,7 +134,7 @@ public:
/// Certainly once during process startup, and possibly later if the user
/// alters configuration. This method must not throw, it should catch any
/// processing errors and return a success or failure answer as described
/// below.
/// below. On success the last commit timestamp must be updated.
///
/// @param config_set a new configuration (JSON) for the process
/// @param check_only true if configuration is to be verified only, not applied
......
......@@ -12,6 +12,7 @@
#include <util/pid_file.h>
#include <util/signal_set.h>
#include <boost/noncopyable.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <string>
namespace isc {
......@@ -260,6 +261,9 @@ protected:
/// @brief Manufacture the pid file name
std::string makePIDFileName() const;
/// @brief Timestamp of the start of the daemon.
boost::posix_time::ptime start_;
private:
/// @brief Config file name or empty if config file not used.
std::string config_file_;
......
// 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
......
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