Skip to content

Commit

Permalink
Check the return value of Sandesh::InitGenerator and exit if sandesh
Browse files Browse the repository at this point in the history
initialization fails. Added kafka timer shutdown in contrail-query-engine
shutdown. Increased the startsecs time for contrail-dns since it was
taking around 7 secs for it to exit and hence supervisor needs to wait
for that much time to declare it up. Tested by returning false from
sandesh HTTP initialization.
Closes-Bug: #1474258

Conflicts:
	src/control-node/main.cc
	src/query_engine/qed.cc

Change-Id: Ie1a9d62dc53d8fe9f28b537130d9e03b5fba2e89
(cherry picked from commit 7d11927)
  • Loading branch information
Megh Bhatt committed Sep 28, 2015
1 parent 376d957 commit 6a68d65
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 37 deletions.
13 changes: 12 additions & 1 deletion src/analytics/OpServerProxy.cc
Expand Up @@ -546,12 +546,16 @@ class OpServerProxy::OpServerImpl {
return true;
}

~OpServerImpl() {
void Shutdown() {
TimerManager::DeleteTimer(kafka_timer_);
kafka_timer_ = NULL;
StopKafka();
}

~OpServerImpl() {
assert(kafka_timer_ == NULL);
}

RedisInfo redis_uve_;
private:
/* these are made public, so they are accessed by OpServerProxy */
Expand Down Expand Up @@ -591,6 +595,13 @@ OpServerProxy::~OpServerProxy() {
delete impl_;
}

void
OpServerProxy::Shutdown() {
if (impl_) {
impl_->Shutdown();
}
}

bool
OpServerProxy::UVENotif(const std::string &type,
const std::string &source, const std::string &node_type,
Expand Down
1 change: 1 addition & 0 deletions src/analytics/OpServerProxy.h
Expand Up @@ -32,6 +32,7 @@ class OpServerProxy {
uint16_t partitions);
OpServerProxy() : impl_(NULL) { }
virtual ~OpServerProxy();
virtual void Shutdown();

virtual bool UVEUpdate(const std::string &type, const std::string &attr,
const std::string &source, const std::string &node_type,
Expand Down
17 changes: 13 additions & 4 deletions src/analytics/main.cc
Expand Up @@ -186,8 +186,11 @@ static void ShutdownServers(VizCollector *viz_collector,

viz_collector->Shutdown();

TimerManager::DeleteTimer(collector_info_log_timer);
delete collector_info_trigger;
if (collector_info_log_timer) {
TimerManager::DeleteTimer(collector_info_log_timer);
delete collector_info_trigger;
collector_info_log_timer = NULL;
}

ConnectionStateManager<NodeStatusUVE, NodeStatus>::
GetInstance()->Shutdown();
Expand Down Expand Up @@ -356,13 +359,19 @@ int main(int argc, char *argv[])
unsigned short coll_port = analytics.GetCollector()->GetPort();
VizSandeshContext vsc(&analytics);
Sandesh::set_send_rate_limit(options.sandesh_send_rate_limit());
Sandesh::InitCollector(
bool success(Sandesh::InitCollector(
module_id,
analytics.name(),
g_vns_constants.NodeTypeNames.find(node_type)->second,
instance_id,
a_evm, "127.0.0.1", coll_port,
options.http_server_port(), &vsc);
options.http_server_port(), &vsc));
if (!success) {
LOG(ERROR, "SANDESH: Initialization FAILED ... exiting");
ShutdownServers(&analytics, NULL);
delete a_evm;
exit(1);
}

Sandesh::SetLoggingParams(options.log_local(), options.log_category(),
options.log_level());
Expand Down
1 change: 1 addition & 0 deletions src/analytics/viz_collector.cc
Expand Up @@ -123,6 +123,7 @@ void VizCollector::Shutdown() {
}
TcpServerManager::DeleteServer(collector_);

osp_->Shutdown();
syslog_listener_->Shutdown();
WaitForIdle();

Expand Down
30 changes: 23 additions & 7 deletions src/control-node/main.cc
Expand Up @@ -152,8 +152,9 @@ static void ShutdownServers(

channel_manager->reset();
TcpServerManager::DeleteServer(xmpp_server);
TimerManager::DeleteTimer(node_info_log_timer);

if (node_info_log_timer) {
TimerManager::DeleteTimer(node_info_log_timer);
}
// Shutdown Discovery Service Client
ShutdownDiscoveryClient(dsclient);

Expand Down Expand Up @@ -537,8 +538,9 @@ int main(int argc, char *argv[]) {
if (sandesh_generator_init) {
NodeType::type node_type =
g_vns_constants.Module2NodeType.find(module)->second;
bool success;
if (options.collectors_configured()) {
Sandesh::InitGenerator(
success = Sandesh::InitGenerator(
module_name,
options.hostname(),
g_vns_constants.NodeTypeNames.find(node_type)->second,
Expand All @@ -548,7 +550,7 @@ int main(int argc, char *argv[]) {
options.collector_server_list(),
&sandesh_context);
} else {
Sandesh::InitGenerator(
success = Sandesh::InitGenerator(
g_vns_constants.ModuleNames.find(module)->second,
options.hostname(),
g_vns_constants.NodeTypeNames.find(node_type)->second,
Expand All @@ -557,6 +559,11 @@ int main(int argc, char *argv[]) {
options.http_server_port(),
&sandesh_context);
}
if (!success) {
LOG(ERROR, "SANDESH: Initialization FAILED ... exiting");
Sandesh::Uninit();
exit(1);
}
}

Sandesh::SetLoggingParams(options.log_local(), options.log_category(),
Expand Down Expand Up @@ -678,11 +685,20 @@ int main(int argc, char *argv[]) {
csf = boost::bind(&DiscoveryServiceClient::Subscribe,
ds_client, _1, _2, _3);
vector<string> list;
Sandesh::InitGenerator(subscriber_name, options.hostname(),
bool success(Sandesh::InitGenerator(subscriber_name,
options.hostname(),
node_type_name,
g_vns_constants.INSTANCE_ID_DEFAULT,
&evm, options.http_server_port(),
csf, list, &sandesh_context);
&evm,
options.http_server_port(),
csf,
list,
&sandesh_context));
if (!success) {
LOG(ERROR, "SANDESH: Initialization FAILED ... exiting");
ShutdownServers(&bgp_peer_manager, ds_client, NULL);
exit(1);
}
}
} else {
LOG(ERROR, "Invalid Discovery Server hostname or address " <<
Expand Down
2 changes: 1 addition & 1 deletion src/dns/contrail-dns.ini
Expand Up @@ -8,6 +8,6 @@ stdout_capture_maxbytes=1MB
redirect_stderr=true
stdout_logfile=/var/log/contrail/contrail-dns-stdout.log
stderr_logfile=/dev/null
startsecs=5
startsecs=10
exitcodes=0 ; 'expected' exit codes for process (default 0,2)
user=contrail
19 changes: 15 additions & 4 deletions src/dns/main.cc
Expand Up @@ -134,15 +134,20 @@ int main(int argc, char *argv[]) {
if (options.discovery_server().empty()) {
NodeType::type node_type =
g_vns_constants.Module2NodeType.find(module)->second;
Sandesh::InitGenerator(
bool success(Sandesh::InitGenerator(
module_name,
options.hostname(),
g_vns_constants.NodeTypeNames.find(node_type)->second,
g_vns_constants.INSTANCE_ID_DEFAULT,
Dns::GetEventManager(),
options.http_server_port(), 0,
options.collector_server_list(),
NULL);
NULL));
if (!success) {
LOG(ERROR, "SANDESH: Initialization FAILED ... exiting");
Sandesh::Uninit();
exit(1);
}
}
Sandesh::SetLoggingParams(options.log_local(), options.log_category(),
options.log_level());
Expand Down Expand Up @@ -234,15 +239,21 @@ int main(int argc, char *argv[]) {
_1, _2, _3);
vector<string> list;
list.clear();
Sandesh::InitGenerator(subscriber_name,
bool success(Sandesh::InitGenerator(subscriber_name,
options.hostname(),
node_type_name,
g_vns_constants.INSTANCE_ID_DEFAULT,
Dns::GetEventManager(),
options.http_server_port(),
csf,
list,
NULL);
NULL));
if (!success) {
LOG(ERROR, "SANDESH: Initialization FAILED ... exiting");
Sandesh::Uninit();
Dns::ShutdownDiscoveryClient(ds_client);
exit(1);
}
}
} else {
LOG(ERROR, "Invalid Discovery Server hostname or ip " <<
Expand Down
51 changes: 31 additions & 20 deletions src/query_engine/qed.cc
Expand Up @@ -120,6 +120,23 @@ static bool OptionsParse(Options &options, EventManager &evm,
return false;
}

static void ShutdownQe(DiscoveryServiceClient *ds_client,
Timer *qe_info_log_timer) {
if (ds_client) {
ds_client->Shutdown();
delete ds_client;
}
if (qe_info_log_timer) {
qe_info_log_timer->Cancel();
TimerManager::DeleteTimer(qe_info_log_timer);
}
WaitForIdle();
Sandesh::Uninit();
ConnectionStateManager<NodeStatusUVE, NodeStatus>::
GetInstance()->Shutdown();
WaitForIdle();
}

int
main(int argc, char *argv[]) {
EventManager evm;
Expand Down Expand Up @@ -208,7 +225,7 @@ main(int argc, char *argv[]) {
instance_id,
boost::bind(&GetProcessStateCb, _1, _2, _3, 3));
Sandesh::set_send_rate_limit(options.sandesh_send_rate_limit());
Sandesh::InitGenerator(
bool success(Sandesh::InitGenerator(
module_name,
options.hostname(),
g_vns_constants.NodeTypeNames.find(node_type)->second,
Expand All @@ -217,7 +234,13 @@ main(int argc, char *argv[]) {
options.http_server_port(),
csf,
options.collector_server_list(),
NULL);
NULL));
if (!success) {
LOG(ERROR, "SANDESH: Initialization FAILED ... exiting");
ShutdownQe(ds_client, NULL);
exit(1);
}

Sandesh::SetLoggingParams(options.log_local(), options.log_category(),
options.log_level());

Expand Down Expand Up @@ -249,19 +272,19 @@ main(int argc, char *argv[]) {
ostream_iterator<string>(css, " "));
LOG(INFO, "Cassandra Servers: " << css.str());

QueryEngine *qe;
boost::scoped_ptr<QueryEngine> qe;
if (cassandra_ports.size() == 1 && cassandra_ports[0] == 0) {
qe = new QueryEngine(&evm,
qe.reset(new QueryEngine(&evm,
options.redis_server(),
options.redis_port(),
options.redis_password(),
max_tasks,
options.max_slice(),
options.analytics_data_ttl(),
options.cassandra_user(),
options.cassandra_password());
options.cassandra_password()));
} else {
qe = new QueryEngine(&evm,
qe.reset(new QueryEngine(&evm,
cassandra_ips,
cassandra_ports,
options.redis_server(),
Expand All @@ -272,9 +295,8 @@ main(int argc, char *argv[]) {
options.analytics_data_ttl(),
options.cassandra_user(),
options.cassandra_password(),
options.start_time());
options.start_time()));
}
(void) qe;

CpuLoadData::Init();
qe_info_trigger =
Expand All @@ -286,17 +308,6 @@ main(int argc, char *argv[]) {
signal(SIGTERM, terminate_qe);
evm.Run();

if (ds_client) {
ds_client->Shutdown();
delete ds_client;
}
qe_info_log_timer->Cancel();
TimerManager::DeleteTimer(qe_info_log_timer);
WaitForIdle();
delete qe;
Sandesh::Uninit();
ConnectionStateManager<NodeStatusUVE, NodeStatus>::
GetInstance()->Shutdown();
WaitForIdle();
ShutdownQe(ds_client, qe_info_log_timer);
return 0;
}

0 comments on commit 6a68d65

Please sign in to comment.