10 #include <boost/program_options.hpp>
11 #include "nodeinfo_types.h"
26 #include <vnc_cfg_types.h>
36 #include <sandesh/common/vns_types.h>
37 #include <sandesh/common/vns_constants.h>
42 namespace opt = boost::program_options;
43 using namespace boost::asio::ip;
45 using process::ConnectionInfo;
48 using process::ProcessState;
49 using process::ConnectionType;
51 using process::g_process_info_constants;
59 static void WaitForIdle(
long wait_seconds = 1200,
bool running_only =
false);
60 static void WaitForIdle(
long wait_seconds,
bool running_only) {
61 static const long kTimeoutUsecs = 1000;
62 static long envWaitTime;
65 if (getenv(
"WAIT_FOR_IDLE")) {
66 envWaitTime = atoi(getenv(
"WAIT_FOR_IDLE"));
68 envWaitTime = wait_seconds;
72 if (envWaitTime > wait_seconds) wait_seconds = envWaitTime;
75 for (
long i = 0; i < ((wait_seconds * 1000000)/kTimeoutUsecs); i++) {
76 if (scheduler->
IsEmpty(running_only)) {
79 usleep(kTimeoutUsecs);
85 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
86 SandeshLevel::SYS_NOTICE,
"EndOfRib point was reached, "
87 "IF-MAP objects have been created");
89 for (uint32_t i=0; i<ntypes; i++) {
92 std::stringstream msg_str;
93 msg_str <<
"The IF-MAP database table has been updated: "
95 <<
", counting " << table->
Size() <<
" elements";
98 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
99 SandeshLevel::SYS_NOTICE, msg_str.str().c_str());
103 std::stringstream msg_str;
104 msg_str <<
"VnniConfig has been updated after"
105 <<
" the bulk sync, the number of elements: "
108 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
109 SandeshLevel::SYS_NOTICE,
110 msg_str.str().c_str());
114 std::stringstream msg_str;
115 msg_str <<
"IpamConfig has been updated after"
116 <<
" the bulk sync, the number of elements: "
119 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
120 SandeshLevel::SYS_NOTICE,
121 msg_str.str().c_str());
125 std::stringstream msg_str;
126 msg_str <<
"VirtualDnsConfig has been updated after"
127 <<
" the bulk sync, the number of elements: "
130 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
131 SandeshLevel::SYS_NOTICE,
132 msg_str.str().c_str());
136 std::stringstream msg_str;
137 msg_str <<
"VirtualDnsRecordConfig has been updated after"
138 <<
" the bulk sync, the number of elements: "
141 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
142 SandeshLevel::SYS_NOTICE,
143 msg_str.str().c_str());
147 std::stringstream msg_str;
148 msg_str <<
"GlobalQosConfig has been updated after"
151 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
152 SandeshLevel::SYS_NOTICE,
153 msg_str.str().c_str());
172 const std::vector<ConnectionInfo> &cinfos,
174 std::vector<ConnectionTypeName> expected_connections) {
176 if (state == ProcessState::NON_FUNCTIONAL)
179 state = ProcessState::NON_FUNCTIONAL;
180 message =
"IFMap Server End-Of-RIB not computed";
185 ifstream file(filename.c_str());
186 string content((istreambuf_iterator<char>(file)),
187 istreambuf_iterator<char>());
193 vnc_cfg_JsonParserInit(json_parser);
194 vnc_cfg_Server_ModuleInit(server->
database(), server->
graph());
202 }
catch (boost::program_options::error &e) {
203 cout <<
"Error " << e.what() << endl;
205 cout <<
"Options Parser: Caught fatal unknown exception" << endl;
213 LOG(ERROR,
"SIGHUP handler ERROR: " << error);
219 int main(
int argc,
char *argv[]) {
234 srand(
unsigned(time(NULL)));
235 std::vector<Signal::SignalHandler> sighup_handlers = boost::assign::list_of
237 Signal::SignalCallbackMap smap = boost::assign::map_list_of
238 (SIGHUP, sighup_handlers);
243 string module_name = g_vns_constants.ModuleNames.find(module)->second;
245 std::string log_property_file =
options.log_property_file();
246 if (log_property_file.size()) {
247 logging.
Init(log_property_file);
252 options.syslog_facility(), module_name,
257 string build_info_str;
261 if (
options.collectors_configured()) {
267 string hostname =
options.hostname();
270 ConnectionStateManager::GetInstance();
272 g_vns_constants.Module2NodeType.find(module)->second;
274 if (
options.collectors_configured()) {
278 g_vns_constants.NodeTypeNames.find(node_type)->second,
279 g_vns_constants.INSTANCE_ID_DEFAULT,
282 options.randomized_collector_server_list(),
288 g_vns_constants.ModuleNames.find(module)->second,
290 g_vns_constants.NodeTypeNames.find(node_type)->second,
291 g_vns_constants.INSTANCE_ID_DEFAULT,
299 LOG(ERROR,
"SANDESH: Initialization FAILED ... exiting");
315 IFMapServer ifmap_server(&config_db, &config_graph,
320 boost::scoped_ptr<ConfigClientManager> config_client_manager_ptr(
322 ConfigStaticObjectFactory::Create<ConfigJsonParserBase>(),
335 dns_manager.
Initialize(&config_db, &config_graph,
341 options.named_max_cache_size(),
342 options.named_max_retransmissions(),
343 options.named_retransmission_interval());
369 "Dns Info log timer");
372 ifmap_server.set_config_manager(config_client_manager);
379 std::vector<ConnectionTypeName> expected_connections;
380 expected_connections = boost::assign::list_of
382 ConnectionType::DATABASE)->second,
"Cassandra"))
384 ConnectionType::DATABASE)->second,
"RabbitMQ"))
386 ConnectionType::COLLECTOR)->second,
""))
387 .convert_to_container\
388 <vector<ConnectionTypeName> >();
390 if (!
options.collectors_configured()) {
391 LOG(INFO,
"DNS: Collectors are not configured!");
392 expected_connections.pop_back();
395 ConnectionStateManager::GetInstance()->Init(
397 module_name, g_vns_constants.INSTANCE_ID_DEFAULT,
399 expected_connections),
"ObjectDns");
402 options.set_config_client_manager(config_client_manager);
404 g_vns_constants.CategoryNames.find(Category::DNSAGENT)->second,
405 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)
A class providing basic control over logging capabilities in OpenSDN control plane.
void Init()
Performs basic initialization of the logging system ( log4cplus).
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()