Skip to content

Commit 666df23

Browse files
johnham-googledivyagayathri-hcl
authored andcommitted
Create NSF notification manager api
1 parent 7407a2e commit 666df23

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

common/warm_restart.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace swss {
88

9+
const std::string WarmStart::kNsfManagerNotificationChannel =
10+
"NSF_MANAGER_COMMON_NOTIFICATION_CHANNEL";
11+
912
const WarmStart::WarmStartStateNameMap WarmStart::warmStartStateNameMap =
1013
{
1114
{INITIALIZED, "initialized"},
@@ -23,6 +26,28 @@ const WarmStart::DataCheckStateNameMap WarmStart::dataCheckStateNameMap =
2326
{CHECK_FAILED, "failed"}
2427
};
2528

29+
const WarmStart::WarmBootNotificationNameMap* WarmStart::warmBootNotificationNameMap()
30+
{
31+
static const auto* const warmBootNotificationNameMap =
32+
new WarmBootNotificationNameMap({
33+
{WarmBootNotification::kFreeze, "freeze"},
34+
{WarmBootNotification::kUnfreeze, "unfreeze"},
35+
{WarmBootNotification::kCheckpoint, "checkpoint"},
36+
});
37+
return warmBootNotificationNameMap;
38+
}
39+
40+
const WarmStart::WarmBootNotificationReverseMap* WarmStart::warmBootNotificationReverseMap()
41+
{
42+
static const auto* const warmBootNotificationReverseMap =
43+
new WarmBootNotificationReverseMap({
44+
{"freeze", WarmBootNotification::kFreeze},
45+
{"unfreeze", WarmBootNotification::kUnfreeze},
46+
{"checkpoint", WarmBootNotification::kCheckpoint},
47+
});
48+
return warmBootNotificationReverseMap;
49+
}
50+
2651
WarmStart &WarmStart::getInstance(void)
2752
{
2853
static WarmStart m_warmStart;
@@ -288,4 +313,4 @@ WarmStart::DataCheckState WarmStart::getDataCheckState(const std::string &app_na
288313
return state;
289314
}
290315

291-
}
316+
} // namespace swss

common/warm_restart.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace swss {
1313
class WarmStart
1414
{
1515
public:
16+
static const std::string kNsfManagerNotificationChannel;
17+
1618
enum WarmStartState
1719
{
1820
INITIALIZED,
@@ -36,12 +38,24 @@ class WarmStart
3638
STAGE_RESTORE,
3739
};
3840

41+
enum class WarmBootNotification {
42+
kFreeze,
43+
kUnfreeze,
44+
kCheckpoint,
45+
};
46+
3947
typedef std::map<WarmStartState, std::string> WarmStartStateNameMap;
4048
static const WarmStartStateNameMap warmStartStateNameMap;
4149

4250
typedef std::map<DataCheckState, std::string> DataCheckStateNameMap;
4351
static const DataCheckStateNameMap dataCheckStateNameMap;
4452

53+
typedef std::map<WarmBootNotification, std::string> WarmBootNotificationNameMap;
54+
static const WarmBootNotificationNameMap* warmBootNotificationNameMap();
55+
56+
typedef std::map<std::string, WarmBootNotification> WarmBootNotificationReverseMap;
57+
static const WarmBootNotificationReverseMap* warmBootNotificationReverseMap();
58+
4559
static WarmStart &getInstance(void);
4660

4761
static void initialize(const std::string &app_name,
@@ -71,7 +85,7 @@ class WarmStart
7185
DataCheckState state);
7286

7387
static DataCheckState getDataCheckState(const std::string &app_name,
74-
DataCheckStage stage);
88+
DataCheckStage stage);
7589
private:
7690
std::shared_ptr<swss::DBConnector> m_stateDb;
7791
std::shared_ptr<swss::DBConnector> m_cfgDb;

tests/warm_restart_ut.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <iostream>
22
#include "gtest/gtest.h"
33
#include "common/dbconnector.h"
4-
#include "common/table.h"
54
#include "common/schema.h"
5+
#include "common/table.h"
66
#include "common/warm_restart.h"
77

88
using namespace std;
@@ -235,3 +235,20 @@ TEST(WarmRestart, set_get_DataCheckState)
235235
state = WarmStart::getDataCheckState(testAppName, WarmStart::STAGE_RESTORE);
236236
EXPECT_EQ(state, WarmStart::CHECK_FAILED);
237237
}
238+
239+
TEST(WarmRestart, testNotificationMaps)
240+
{
241+
WarmStart::WarmBootNotification warmBootNotifications[] =
242+
{
243+
WarmStart::WarmBootNotification::kFreeze,
244+
WarmStart::WarmBootNotification::kUnfreeze,
245+
WarmStart::WarmBootNotification::kCheckpoint,
246+
};
247+
248+
for (const auto &currNotification : warmBootNotifications) {
249+
std::string type = WarmStart::warmBootNotificationNameMap()->at(currNotification);
250+
WarmStart::WarmBootNotification notification;
251+
notification = WarmStart::warmBootNotificationReverseMap()->at(type);
252+
EXPECT_EQ(notification, currNotification);
253+
}
254+
}

0 commit comments

Comments
 (0)