9 #include <boost/program_options.hpp>
10 #include "nodeinfo_types.h"
25 #include <vnc_cfg_types.h>
35 #include <sandesh/common/vns_types.h>
36 #include <sandesh/common/vns_constants.h>
41 namespace opt = boost::program_options;
42 using namespace boost::asio::ip;
44 using process::ConnectionInfo;
47 using process::ProcessState;
48 using process::ConnectionType;
50 using process::g_process_info_constants;
58 static void WaitForIdle(
long wait_seconds = 1200,
bool running_only =
false);
59 static void WaitForIdle(
long wait_seconds,
bool running_only) {
60 static const long kTimeoutUsecs = 1000;
61 static long envWaitTime;
64 if (getenv(
"WAIT_FOR_IDLE")) {
65 envWaitTime = atoi(getenv(
"WAIT_FOR_IDLE"));
67 envWaitTime = wait_seconds;
71 if (envWaitTime > wait_seconds) wait_seconds = envWaitTime;
74 for (
long i = 0; i < ((wait_seconds * 1000000)/kTimeoutUsecs); i++) {
75 if (scheduler->
IsEmpty(running_only)) {
78 usleep(kTimeoutUsecs);
84 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
85 SandeshLevel::SYS_NOTICE,
"EndOfRib point was reached, "
86 "IF-MAP objects have been created");
88 for (uint32_t i=0; i<ntypes; i++) {
91 std::stringstream msg_str;
92 msg_str <<
"The IF-MAP database table has been updated: "
94 <<
", counting " << table->
Size() <<
" elements";
97 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
98 SandeshLevel::SYS_NOTICE, msg_str.str().c_str());
102 std::stringstream msg_str;
103 msg_str <<
"VnniConfig has been updated after"
104 <<
" the bulk sync, the number of elements: "
107 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
108 SandeshLevel::SYS_NOTICE,
109 msg_str.str().c_str());
113 std::stringstream msg_str;
114 msg_str <<
"IpamConfig has been updated after"
115 <<
" the bulk sync, the number of elements: "
118 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
119 SandeshLevel::SYS_NOTICE,
120 msg_str.str().c_str());
124 std::stringstream msg_str;
125 msg_str <<
"VirtualDnsConfig has been updated after"
126 <<
" the bulk sync, the number of elements: "
129 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
130 SandeshLevel::SYS_NOTICE,
131 msg_str.str().c_str());
135 std::stringstream msg_str;
136 msg_str <<
"VirtualDnsRecordConfig has been updated after"
137 <<
" the bulk sync, the number of elements: "
140 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
141 SandeshLevel::SYS_NOTICE,
142 msg_str.str().c_str());
146 std::stringstream msg_str;
147 msg_str <<
"GlobalQosConfig has been updated after"
150 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
151 SandeshLevel::SYS_NOTICE,
152 msg_str.str().c_str());
171 const std::vector<ConnectionInfo> &cinfos,
173 std::vector<ConnectionTypeName> expected_connections) {
175 if (state == ProcessState::NON_FUNCTIONAL)
178 state = ProcessState::NON_FUNCTIONAL;
179 message =
"IFMap Server End-Of-RIB not computed";
184 ifstream file(filename.c_str());
185 string content((istreambuf_iterator<char>(file)),
186 istreambuf_iterator<char>());
192 vnc_cfg_JsonParserInit(json_parser);
193 vnc_cfg_Server_ModuleInit(server->
database(), server->
graph());
201 }
catch (boost::program_options::error &e) {
202 cout <<
"Error " << e.what() << endl;
204 cout <<
"Options Parser: Caught fatal unknown exception" << endl;
212 LOG(ERROR,
"SIGHUP handler ERROR: " << error);
218 int main(
int argc,
char *argv[]) {
232 srand(
unsigned(time(NULL)));
233 std::vector<Signal::SignalHandler> sighup_handlers = boost::assign::list_of
235 Signal::SignalCallbackMap smap = boost::assign::map_list_of
236 (SIGHUP, sighup_handlers);
241 string module_name = g_vns_constants.ModuleNames.find(module)->second;
243 std::string log_property_file =
options.log_property_file();
244 if (log_property_file.size()) {
250 options.syslog_facility(), module_name,
255 string build_info_str;
259 if (
options.collectors_configured()) {
265 string hostname =
options.hostname();
268 ConnectionStateManager::GetInstance();
270 g_vns_constants.Module2NodeType.find(module)->second;
272 if (
options.collectors_configured()) {
276 g_vns_constants.NodeTypeNames.find(node_type)->second,
277 g_vns_constants.INSTANCE_ID_DEFAULT,
280 options.randomized_collector_server_list(),
286 g_vns_constants.ModuleNames.find(module)->second,
288 g_vns_constants.NodeTypeNames.find(node_type)->second,
289 g_vns_constants.INSTANCE_ID_DEFAULT,
297 LOG(ERROR,
"SANDESH: Initialization FAILED ... exiting");
313 IFMapServer ifmap_server(&config_db, &config_graph,
318 boost::scoped_ptr<ConfigClientManager> config_client_manager_ptr(
320 ConfigStaticObjectFactory::Create<ConfigJsonParserBase>(),
333 dns_manager.
Initialize(&config_db, &config_graph,
339 options.named_max_cache_size(),
340 options.named_max_retransmissions(),
341 options.named_retransmission_interval());
367 "Dns Info log timer");
370 ifmap_server.set_config_manager(config_client_manager);
377 std::vector<ConnectionTypeName> expected_connections;
378 expected_connections = boost::assign::list_of
380 ConnectionType::DATABASE)->second,
"Cassandra"))
382 ConnectionType::DATABASE)->second,
"RabbitMQ"))
384 ConnectionType::COLLECTOR)->second,
""))
385 .convert_to_container\
386 <vector<ConnectionTypeName> >();
388 if (!
options.collectors_configured()) {
389 LOG(INFO,
"DNS: Collectors are not configured!");
390 expected_connections.pop_back();
393 ConnectionStateManager::GetInstance()->Init(
395 module_name, g_vns_constants.INSTANCE_ID_DEFAULT,
397 expected_connections),
"ObjectDns");
400 options.set_config_client_manager(config_client_manager);
402 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
403 SandeshLevel::SYS_NOTICE,
"Bulk sync has been started");
void StartRabbitMQReader()
void set_terminate(bool terminate)
bool GetEndOfRibComputed() const
ConfigJsonParserBase * config_json_parser()
static int GetNumWorkers()
ConfigAmqpClient * config_amqp_client() const
void ifmap_server_set(IFMapServer *ifmap_server)
static const uint16_t DnsXmpp()
const std::string & name() const
virtual size_t Size() const
static bool Init(bool xmpp_auth_enabled, const std::string &xmpp_server_cert, const std::string &xmpp_server_key, const std::string &xmpp_ca_cert)
static const char * config_types[]
static uint32_t config_types_size
void StartEndofConfigTimer()
void Initialize(DB *config_db, DBGraph *config_graph, const std::string &named_config_dir, const std::string &named_config_file, const std::string &named_log_file, const std::string &rndc_config_file, const std::string &rndc_secret, const std::string &named_max_cache_size, const uint16_t named_max_retransmissions, const uint16_t named_retransmission_interval)
void set_config_manager(ConfigClientManager *config_manager)
static void SendDnsUve(uint64_t start_time)
static void SetCollector(std::string name)
static void SetSelfIp(std::string ip)
static EventManager * GetEventManager()
static void SetDnsManager(DnsManager *mgr)
static void SetProgramName(const char *name)
static void SetDnsPort(uint32_t port)
static void SetHostName(const std::string name)
static bool GetVersion(std::string &build_info_str)
static void SetHttpPort(uint32_t port)
static XmppServer * GetXmppServer()
static IFMapTable * FindTable(DB *db, const std::string &element_type)
static void LogVersionInfo(const std::string str, Category::type categ)
static void set_module_context(const std::string &module_name, SandeshContext *context)
static bool InitGenerator(const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, unsigned short http_port, const std::vector< std::string > &collectors, SandeshContext *client_context=NULL, DerivedStats ds=DerivedStats(), const SandeshConfig &config=SandeshConfig())
std::map< std::string, std::map< std::string, std::string > > DerivedStats
static void SetLoggingParams(bool enable_local_log, std::string category, std::string level, bool enable_trace_print=false, bool enable_flow_log=false, bool enable_session_syslog=false)
static SandeshLevel::type StringToLevel(std::string level)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
static int GetDefaultThreadCount()
static void Initialize(uint32_t thread_count=0, EventManager *evm=NULL)
static TaskScheduler * GetInstance()
bool IsEmpty(bool running_only=false)
Returns true if there are no tasks running and/or enqueued If running_only is true,...
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
static void WaitForIdle(long wait_seconds=1200, bool running_only=false)
static bool OptionsParse(Options &options, int argc, char *argv[])
static void IFMap_Initialize(IFMapServer *server, ConfigJsonParser *json_parser)
static void PrintBulkSyncStats(DB *database)
Timer * dns_info_log_timer
TaskTrigger * dns_info_trigger
static void DnsServerGetProcessStateCb(const ConfigClientManager *config_client_manager, const std::vector< ConnectionInfo > &cinfos, ProcessState::type &state, std::string &message, std::vector< ConnectionTypeName > expected_connections)
static string FileRead(const string &filename)
void ReConfigSignalHandler(const boost::system::error_code &error, int sig)
void IFMapLinkTable_Init(DB *db, DBGraph *graph)
void SetLoggingDisabled(bool flag)
#define LOG(_Level, _Msg)
void GetProcessStateCb(const vector< ConnectionInfo > &cinfos, ProcessState::type &state, string &message, const vector< ConnectionTypeName > &expected_connections)
std::pair< std::string, std::string > ConnectionTypeName
log4cplus::LogLevel SandeshLevelTolog4Level(SandeshLevel::type slevel)
static DataMap ipam_config_
static DataMap virt_dns_config_
static DataMap virt_dns_rec_config_
static DataMap vnni_config_
static uint64_t UTCTimestampUsec()