Skip to content

Commit

Permalink
Advertise DNS-Server status as up conditionally to discovery-server.
Browse files Browse the repository at this point in the history
Conditions are based on config read completely from IfMap Server
and connection to named is UP.

Added checks for pid recirculation by associating to named process.
(diffs from Hari Prasad Killi)

Change-Id: I24510c77ac1fa00dfcc48b4ac087e7cc164bc579
Closes-Bug:1477742
Closes-Bug:1489610
  • Loading branch information
nipak committed Oct 27, 2015
1 parent 0cf976a commit 5894997
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
35 changes: 31 additions & 4 deletions src/dns/bind/named_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,28 @@ bool BindStatus::SetTrigger() {
return false;
}

// Check if a given pid belongs to contrail-named
bool BindStatus::IsBindPid(uint32_t pid) {
bool ret = false;
std::stringstream str;
str << "/proc/" << pid << "/cmdline";

ifstream ifile(str.str().c_str());
if (ifile.good()) {
std::string cmdline;
cmdline.assign((istreambuf_iterator<char>(ifile)),
istreambuf_iterator<char>());
istringstream cmdstream(cmdline);
if (cmdstream.str().find("/usr/bin/contrail-named") !=
std::string::npos) {
ret = true;
}
}

ifile.close();
return ret;
}

bool BindStatus::CheckBindStatus() {
uint32_t new_pid = -1;
NamedConfig *ncfg = NamedConfig::GetNamedConfigObject();
Expand All @@ -502,11 +524,16 @@ bool BindStatus::CheckBindStatus() {
pid_file.close();
}

if (new_pid != named_pid_) {
named_pid_ = new_pid;
if (new_pid == (uint32_t) -1) {
if (new_pid == (uint32_t) -1) {
handler_(Down);
} else if (!IsBindPid(new_pid)) {
if (named_pid_ != (uint32_t) -1) {
named_pid_ = -1;
handler_(Down);
} else {
}
} else {
if (named_pid_ != new_pid) {
named_pid_ = new_pid;
handler_(Up);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/dns/bind/named_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class BindStatus {
private:
friend class DnsBindTest;

bool IsBindPid(uint32_t pid);
bool CheckBindStatus();

uint32_t named_pid_;
Expand Down
22 changes: 21 additions & 1 deletion src/dns/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ bool DnsInfoLogger() {
return true;
}

bool DnsServerReEvaluatePublishCb(IFMapServer *ifmap_server,
std::string &message) {

IFMapManager *ifmap_manager = ifmap_server->get_ifmap_manager();
if (ifmap_manager && !ifmap_manager->GetEndOfRibComputed()) {
message = "IFMap Server End-Of-RIB not computed";
return false;
}

DnsManager *dns_manager = Dns::GetDnsManager();
if (dns_manager && !dns_manager->IsBindStatusUp()) {
message = "Connection to named DOWN";
return false;
}

message = "OK";
return true;
}

static string FileRead(const string &filename) {
ifstream file(filename.c_str());
string content((istreambuf_iterator<char>(file)),
Expand Down Expand Up @@ -222,7 +241,8 @@ int main(int argc, char *argv[]) {
"</port></" << sname << ">";
std::string pub_msg;
pub_msg = pub_ss.str();
ds_client->Publish(sname, pub_msg);
ds_client->Publish(sname, pub_msg,
boost::bind(&DnsServerReEvaluatePublishCb, &ifmap_server, _1));
}

//subscribe to collector service if not configured
Expand Down
1 change: 1 addition & 0 deletions src/dns/mgr/dns_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class DnsManager {
DnsConfigManager::EventType event);
void ProcessAgentUpdate(BindUtil::Operation event, const std::string &name,
const std::string &vdns_name, const DnsItem &item);
bool IsBindStatusUp() { return bind_status_.IsUp(); }

private:
friend class DnsBindTest;
Expand Down

0 comments on commit 5894997

Please sign in to comment.