22 const size_t CfgMgr::CONFIG_LIST_SIZE = 10;
31 CfgMgr::getDataDir()
const {
36 CfgMgr::setDataDir(
const std::string& datadir,
bool unspecified) {
42 ensureCurrentAllocated();
46 d2_client_mgr_.setD2ClientConfig(new_config);
52 configuration_->setD2ClientConfig(new_config);
56 CfgMgr::ddnsEnabled() {
57 return (d2_client_mgr_.ddnsEnabled());
61 CfgMgr::getD2ClientConfig()
const {
62 return (d2_client_mgr_.getD2ClientConfig());
66 CfgMgr::getD2ClientMgr() {
67 return (d2_client_mgr_);
71 CfgMgr::ensureCurrentAllocated() {
72 if (!configuration_ || configs_.empty()) {
74 configs_.push_back(configuration_);
81 configuration_->removeStatistics();
84 external_configs_.clear();
86 setD2ClientConfig(d2_default_conf);
91 ensureCurrentAllocated();
96 configuration_->removeStatistics();
98 if (!configs_.back()->sequenceEquals(*configuration_)) {
99 configuration_ = configs_.back();
102 if (configs_.size() > CONFIG_LIST_SIZE) {
103 SrvConfigList::iterator it = configs_.begin();
104 std::advance(it, configs_.size() - CONFIG_LIST_SIZE);
105 configs_.erase(configs_.begin(), it);
110 auto now = boost::posix_time::second_clock::universal_time();
111 configuration_->setLastCommitTime(now);
114 configuration_->updateStatistics();
116 configuration_->configureLowerLevelLibraries();
121 ensureCurrentAllocated();
122 if (!configuration_->sequenceEquals(*configs_.back())) {
128 CfgMgr::revert(
const size_t index) {
129 ensureCurrentAllocated();
132 " to an old configuration");
133 }
else if (index > configs_.size() - 1) {
135 << index <<
"', only '" << configs_.size() - 1
136 <<
"' previous commits available");
148 SrvConfigList::const_reverse_iterator it = configs_.rbegin();
149 std::advance(it, index);
154 (*it)->copy(*getStagingCfg());
161 CfgMgr::getCurrentCfg() {
162 ensureCurrentAllocated();
163 return (configuration_);
167 CfgMgr::getStagingCfg() {
168 ensureCurrentAllocated();
169 if (configuration_->sequenceEquals(*configs_.back())) {
170 uint32_t sequence = configuration_->getSequence();
173 return (configs_.back());
177 CfgMgr::createExternalCfg() {
180 if (!external_configs_.empty()) {
181 seq = external_configs_.rbegin()->second->getSequence() + 1;
185 external_configs_[seq] = srv_config;
190 CfgMgr::mergeIntoStagingCfg(
const uint32_t seq) {
191 mergeIntoCfg(getStagingCfg(), seq);
195 CfgMgr::mergeIntoCurrentCfg(
const uint32_t seq) {
198 getCurrentCfg()->removeStatistics();
199 mergeIntoCfg(getCurrentCfg(), seq);
203 getCurrentCfg()->updateStatistics();
206 getCurrentCfg()->updateStatistics();
210 CfgMgr::mergeIntoCfg(
const SrvConfigPtr& target_config,
const uint32_t seq) {
211 auto source_config = external_configs_.find(seq);
212 if (source_config != external_configs_.end()) {
213 target_config->merge(*source_config->second);
214 external_configs_.erase(source_config);
218 "of " << seq <<
" was not found");
223 : datadir_(DHCP_DATA_DIR, true), d2_client_mgr_(), family_(AF_INET) {
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Acts as a storage vault for D2 client configuration.
virtual ~CfgMgr()
virtual destructor
Specifies current DHCP configuration.
Defines the logger used by the top-level component of kea-dhcp-ddns.
D2ClientMgr isolates Kea from the details of being a D2 client.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
boost::shared_ptr< D2ClientConfig > D2ClientConfigPtr
Defines a pointer for D2ClientConfig instances.