Commit eb01e3dc authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2862] Subscribe in case of remote segment

parent 87c3781c
......@@ -306,6 +306,8 @@ public:
MessageAttributes& stats_attrs,
const bool done);
/// Are we currently subscribed to the SegmentReader group?
bool readers_subscribed_;
private:
bool xfrout_connected_;
AbstractXfroutClient& xfrout_client_;
......@@ -322,6 +324,7 @@ AuthSrvImpl::AuthSrvImpl(AbstractXfroutClient& xfrout_client,
datasrc_clients_mgr_(io_service_),
ddns_base_forwarder_(ddns_forwarder),
ddns_forwarder_(NULL),
readers_subscribed_(false),
xfrout_connected_(false),
xfrout_client_(xfrout_client)
{}
......@@ -940,7 +943,38 @@ AuthSrv::setTCPRecvTimeout(size_t timeout) {
dnss_->setTCPRecvTimeout(timeout);
}
namespace {
bool
hasRemoteSegment(auth::DataSrcClientsMgr& mgr) {
auth::DataSrcClientsMgr::Holder holder(mgr);
const std::vector<dns::RRClass>& classes(holder.getClasses());
BOOST_FOREACH(const dns::RRClass& rrclass, classes) {
const boost::shared_ptr<datasrc::ConfigurableClientList>&
list(holder.findClientList(rrclass));
const std::vector<DataSourceStatus>& states(list->getStatus());
BOOST_FOREACH(const datasrc::DataSourceStatus& status, states) {
if (status.getSegmentState() != datasrc::SEGMENT_UNUSED &&
status.getSegmentType() != "local")
// We use some segment and it's not a local one, so it
// must be remote.
return true;
}
}
// No remote segment found in any of the lists
return false;
}
}
void
AuthSrv::listsReconfigured() {
// TODO: Here comes something.
const bool has_remote = hasRemoteSegment(impl_->datasrc_clients_mgr_);
if (has_remote && !impl_->readers_subscribed_) {
impl_->config_session_->subscribe("SegmentReader");
impl_->readers_subscribed_ = true;
} else if (!has_remote && impl_->readers_subscribed_) {
impl_->config_session_->unsubscribe("SegmentReader");
impl_->readers_subscribed_ = false;
}
}
......@@ -2166,6 +2166,18 @@ TEST_F(AuthSrvTest, postReconfigure) {
}
server.listsReconfigured();
EXPECT_TRUE(session.haveSubscription("SegmentReader", "*"));
// Set the segment to local again
updateInMemory(server, "example.", CONFIG_INMEMORY_EXAMPLE);
{
DataSrcClientsMgr &mgr(server.getDataSrcClientsMgr());
DataSrcClientsMgr::Holder holder(mgr);
EXPECT_EQ(SEGMENT_INUSE, holder.findClientList(RRClass::IN())->
getStatus()[0].getSegmentState());
EXPECT_EQ("local", holder.findClientList(RRClass::IN())->
getStatus()[0].getSegmentType());
}
server.listsReconfigured();
EXPECT_FALSE(session.haveSubscription("SegmentReader", "*"));
}
}
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