Skip to content

Commit f1841ed

Browse files
rkavitha-hclKAVITHA RAMALINGAM
authored and
KAVITHA RAMALINGAM
committed
Integrated Rebootbackend changes
1 parent 5ac7797 commit f1841ed

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include "redis_utils.h"
2+
3+
#include <sstream>
4+
#include <string>
5+
#include <unordered_map>
6+
#include <unordered_set>
7+
8+
#include "dbconnector.h"
9+
#include "notificationproducer.h"
10+
//#include "stateverification.h"
11+
#include "table.h"
12+
#include "timestamp.h"
13+
#include "warm_restart.h"
14+
15+
namespace rebootbackend {
16+
17+
using WarmStartState = ::swss::WarmStart::WarmStartState;
18+
19+
20+
void init_warm_reboot_states(const swss::DBConnector &db) {
21+
swss::Table table(&db, STATE_WARM_RESTART_TABLE_NAME);
22+
std::vector<std::string> keys;
23+
24+
table.getKeys(keys);
25+
for (auto &key : keys) {
26+
table.hdel(key, "state");
27+
table.hdel(key, "timestamp");
28+
}
29+
}
30+
31+
void set_warm_restart_enable(const swss::DBConnector &db, bool enabled) {
32+
swss::Table table(&db, STATE_WARM_RESTART_ENABLE_TABLE_NAME);
33+
table.hset("system", "enable", enabled ? "true" : "false");
34+
}
35+
36+
bool is_valid_key(const std::string &key, const std::string &separator) {
37+
if (separator.empty()) {
38+
return false;
39+
}
40+
41+
size_t pos = key.find(separator);
42+
// The separator must exist in the string, and cannot be the first or last
43+
// character.
44+
return !(pos == std::string::npos || pos == 0 || pos == key.size() - 1);
45+
}
46+
47+
bool get_docker_app_from_key(const std::string &key,
48+
const std::string &separator, std::string &docker,
49+
std::string &app) {
50+
SWSS_LOG_ENTER();
51+
52+
size_t pos = key.find(separator);
53+
54+
if (separator.empty()) {
55+
SWSS_LOG_ERROR("separator [%s] shouldn't be empty", separator.c_str());
56+
return false;
57+
}
58+
59+
if (pos == std::string::npos) {
60+
SWSS_LOG_ERROR("key [%s] should contain separator [%s]", key.c_str(),
61+
separator.c_str());
62+
return false;
63+
}
64+
65+
docker = key.substr(0, pos);
66+
app = key.substr(pos + separator.length(), std::string::npos);
67+
68+
if (docker.empty()) {
69+
SWSS_LOG_ERROR("docker name shouldn't be empty, key = %s", key.c_str());
70+
return false;
71+
}
72+
73+
if (app.empty()) {
74+
SWSS_LOG_ERROR("app name shouldn't be empty, key = %s", key.c_str());
75+
return false;
76+
}
77+
return true;
78+
}
79+
80+
} // namespace rebootbackend
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
#include <string>
3+
#include <unordered_map>
4+
#include <unordered_set>
5+
6+
#include "dbconnector.h"
7+
#include "notificationconsumer.h"
8+
#include "notificationproducer.h"
9+
#include "selectableevent.h"
10+
#include "status_code_util.h"
11+
#include "warm_restart.h"
12+
13+
namespace rebootbackend {
14+
15+
// Return string corresponding to state
16+
std::string get_warm_start_state_name(
17+
const swss::WarmStart::WarmStartState state);
18+
19+
void init_warm_reboot_states(const swss::DBConnector &db);
20+
21+
// Set the system warm start state to a new enabled/disabled state.
22+
// STATE_WARM_RESTART_TABLE_NAME
23+
// key = system, field = enable, value = "true"/"false"
24+
void set_warm_restart_enable(const swss::DBConnector &db, bool enabled);
25+
26+
// Returns true if key is in the formm "text<separator>text", and false
27+
// otherwise.
28+
bool is_valid_key(const std::string &key, const std::string &separator);
29+
30+
// Helper function: given key of form "docker|app"
31+
// extract docker and app. (separator = | in this case)
32+
// return false if docker or app are empty or separator
33+
// isn't present, else true.
34+
// key and separator are inputs
35+
// docker and app are outputs
36+
bool get_docker_app_from_key(const std::string &key,
37+
const std::string &separator, std::string &docker,
38+
std::string &app);
39+
40+
} // namespace rebootbackend

0 commit comments

Comments
 (0)