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;
244 if (log_property_file.size()) {
255 string build_info_str;
268 ConnectionStateManager::GetInstance();
270 g_vns_constants.Module2NodeType.find(module)->second;
276 g_vns_constants.NodeTypeNames.find(node_type)->second,
277 g_vns_constants.INSTANCE_ID_DEFAULT,
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,
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> >();
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");
402 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
403 SandeshLevel::SYS_NOTICE,
"Bulk sync has been started");
ConfigJsonParserBase * config_json_parser()
log4cplus::LogLevel SandeshLevelTolog4Level(SandeshLevel::type slevel)
static DataMap virt_dns_rec_config_
static const char * config_types[]
void set_config_manager(ConfigClientManager *config_manager)
static void SetDnsPort(uint32_t port)
void StartRabbitMQReader()
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
std::string log_level() const
int log_files_count() const
static int GetDefaultThreadCount()
static void Initialize(uint32_t thread_count=0, EventManager *evm=NULL)
static SandeshLevel::type StringToLevel(std::string level)
const ConfigClientOptions & configdb_options() const
void ParseReConfig(bool force_reinit)
static void DnsServerGetProcessStateCb(const ConfigClientManager *config_client_manager, const std::vector< ConnectionInfo > &cinfos, ProcessState::type &state, std::string &message, std::vector< ConnectionTypeName > expected_connections)
uint16_t http_server_port() const
const uint16_t named_max_retransmissions()
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)
long log_file_size() const
std::string config_file() const
void ifmap_server_set(IFMapServer *ifmap_server)
static void SetProgramName(const char *name)
static void SetSelfIp(std::string ip)
const std::string & rndc_secret() const
ConfigAmqpClient * config_amqp_client() const
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)
static void LogVersionInfo(const std::string str, Category::type categ)
void StartEndofConfigTimer()
static void SetHostName(const std::string name)
std::map< std::string, std::map< std::string, std::string > > DerivedStats
static DataMap vnni_config_
uint16_t dns_server_port() const
static string FileRead(const string &filename)
static void SetDnsManager(DnsManager *mgr)
const std::string & named_config_file() const
std::string xmpp_server_cert() const
bool GetEndOfRibComputed() const
static void SetHttpPort(uint32_t port)
bool collectors_configured() const
std::vector< std::string > collector_server_list() const
std::string host_ip() const
static DataMap virt_dns_config_
virtual size_t Size() const
std::string log_property_file() const
void set_config_client_manager(ConfigClientManager *mgr)
std::vector< std::string > randomized_collector_server_list() const
TaskTrigger * dns_info_trigger
static void SetCollector(std::string name)
Timer * dns_info_log_timer
static DataMap ipam_config_
static TaskScheduler * GetInstance()
const std::string & named_config_dir() const
const uint16_t named_retransmission_interval()
bool xmpp_auth_enabled() const
void GetProcessStateCb(const vector< ConnectionInfo > &cinfos, ProcessState::type &state, string &message, const vector< ConnectionTypeName > &expected_connections)
bool IsEmpty(bool running_only=false)
Returns true if there are no tasks running and/or enqueued If running_only is true, enqueued tasks are ignored i.e. return true if there are no running tasks. Ignore TaskGroup or TaskEntry if it is disabled.
const std::string & name() const
const SandeshConfig & sandesh_config() const
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)
void IFMapLinkTable_Init(DB *db, DBGraph *graph)
std::pair< std::string, std::string > ConnectionTypeName
std::string syslog_facility() const
static void set_module_context(const std::string &module_name, SandeshContext *context)
std::string log_file() const
static void SendDnsUve(uint64_t start_time)
std::string xmpp_server_key() const
std::string log_category() const
const std::string & named_max_cache_size() const
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::string hostname() const
static void PrintBulkSyncStats(DB *database)
static uint64_t UTCTimestampUsec()
static IFMapTable * FindTable(DB *db, const std::string &element_type)
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
static uint32_t config_types_size
void set_terminate(bool terminate)
#define LOG(_Level, _Msg)
void SetLoggingDisabled(bool flag)
static XmppServer * GetXmppServer()
static EventManager * GetEventManager()
bool Parse(EventManager &evm, int argc, char **argv)
static int GetNumWorkers()
static bool GetVersion(std::string &build_info_str)
const std::string & rndc_config_file() const
static bool OptionsParse(Options &options, int argc, char *argv[])
void ReConfigSignalHandler(const boost::system::error_code &error, int sig, bool force_reinit)
static void WaitForIdle(long wait_seconds=1200, bool running_only=false)
static const uint16_t DnsXmpp()
std::string xmpp_ca_cert() const
static void IFMap_Initialize(IFMapServer *server, ConfigJsonParser *json_parser)
const std::string & named_log_file() 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)