forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teammgrd.cpp
101 lines (80 loc) · 2.28 KB
/
teammgrd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <fstream>
#include "teammgr.h"
#include "netdispatcher.h"
#include "netlink.h"
#include "select.h"
#include "warm_restart.h"
#include <signal.h>
using namespace std;
using namespace swss;
#define SELECT_TIMEOUT 1000
int gBatchSize = 0;
bool gSwssRecord = false;
bool gLogRotate = false;
ofstream gRecordOfs;
string gRecordFile;
bool received_sigterm = false;
void sig_handler(int signo)
{
received_sigterm = true;
return;
}
int main(int argc, char **argv)
{
Logger::linkToDbNative("teammgrd");
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("--- Starting teammrgd ---");
/* Register the signal handler for SIGTERM */
signal(SIGTERM, sig_handler);
try
{
DBConnector conf_db("CONFIG_DB", 0);
DBConnector app_db("APPL_DB", 0);
DBConnector state_db("STATE_DB", 0);
WarmStart::initialize("teammgrd", "teamd");
WarmStart::checkWarmStart("teammgrd", "teamd");
TableConnector conf_lag_table(&conf_db, CFG_LAG_TABLE_NAME);
TableConnector conf_lag_member_table(&conf_db, CFG_LAG_MEMBER_TABLE_NAME);
TableConnector state_port_table(&state_db, STATE_PORT_TABLE_NAME);
vector<TableConnector> tables = {
conf_lag_table,
conf_lag_member_table,
state_port_table
};
TeamMgr teammgr(&conf_db, &app_db, &state_db, tables);
vector<Orch *> cfgOrchList = {&teammgr};
Select s;
for (Orch *o: cfgOrchList)
{
s.addSelectables(o->getSelectables());
}
while (true)
{
if(received_sigterm)
{
teammgr.cleanTeamProcesses(SIGTERM);
received_sigterm = false;
}
Selectable *sel;
int ret;
ret = s.select(&sel, SELECT_TIMEOUT);
if (ret == Select::ERROR)
{
SWSS_LOG_NOTICE("Error: %s!", strerror(errno));
continue;
}
if (ret == Select::TIMEOUT)
{
teammgr.doTask();
continue;
}
auto *c = (Executor *)sel;
c->execute();
}
}
catch (const exception &e)
{
SWSS_LOG_ERROR("Runtime error: %s", e.what());
}
return -1;
}