summaryrefslogtreecommitdiff
path: root/include/persistent_data.hpp
diff options
context:
space:
mode:
authorJunLin Chen <Jun-Lin.Chen@quantatw.com>2021-02-24 12:13:29 +0300
committerEd Tanous <ed@tanous.net>2021-07-26 18:25:24 +0300
commit28afb49c480790e763b8491be0b5a8e35964dbc9 (patch)
treee24c10b205345073b3ac1e623ff4fac1b19adbef /include/persistent_data.hpp
parent02bdd9672c7619cc1e11fe3daed8e3ec092b207b (diff)
downloadbmcweb-28afb49c480790e763b8491be0b5a8e35964dbc9.tar.xz
EventService: Move subscription persistent data
This commit resolves https://github.com/openbmc/bmcweb/issues/168 Current store mechanism makes it very difficult to keep in sync with the existing files, and has caused several bugs because the path it uses different than the existing bmcweb_persistent_data.json, and it's missing several error checks. If there has old config in /var/lib/bmcweb/eventservice_config.json. Restart bmcweb will move old config to bmcweb_presistent_data.json and delete the old config. Tested: - Create new Subscription via POST https://${bmc}/redfish/v1/EventService/Subscriptions/ The subscription is successfully created and GET succussfully. Restart bmcweb or reboot. The subscription will restore. - Delete the Subscription via DELETE https://${bmc}/redfish/v1/EventService/Subscriptions/${subscription_id} The subscription is successfully delete. bmcweb_persistent_data.json will delete subscription content. - Modify EventService config via PATCH https://{{bmc}}/redfish/v1/EventService GET https://{{bmc}}/redfish/v1/EventService and the changes applied. bmcweb_persistent_data.json will apply modification after PATCH. Restart bmcweb or reboot The config maintains the changed. Signed-off-by: JunLin Chen <Jun-Lin.Chen@quantatw.com> Change-Id: Ic29385ea8231ba976bbf415af2803df2d30cb10a
Diffstat (limited to 'include/persistent_data.hpp')
-rw-r--r--include/persistent_data.hpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp
index 24f7afd460..4178d7d69f 100644
--- a/include/persistent_data.hpp
+++ b/include/persistent_data.hpp
@@ -5,6 +5,7 @@
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
+#include <event_service_store.hpp>
#include <http_request.hpp>
#include <http_response.hpp>
#include <nlohmann/json.hpp>
@@ -129,6 +130,35 @@ class ConfigFile
SessionStore::getInstance().updateSessionTimeout(
sessionTimeoutInseconds);
}
+ else if (item.key() == "eventservice_config")
+ {
+ EventServiceStore::getInstance()
+ .getEventServiceConfig()
+ .fromJson(item.value());
+ }
+ else if (item.key() == "subscriptions")
+ {
+ for (const auto& elem : item.value())
+ {
+ std::shared_ptr<UserSubscription> newSubscription =
+ UserSubscription::fromJson(elem);
+
+ if (newSubscription == nullptr)
+ {
+ BMCWEB_LOG_ERROR
+ << "Problem reading subscription "
+ "from persistent store";
+ continue;
+ }
+
+ BMCWEB_LOG_DEBUG << "Restored subscription: "
+ << newSubscription->id << " "
+ << newSubscription->customText;
+ EventServiceStore::getInstance()
+ .subscriptionsConfigMap.emplace(
+ newSubscription->id, newSubscription);
+ }
+ }
else
{
// Do nothing in the case of extra fields. We may have
@@ -170,6 +200,8 @@ class ConfigFile
std::filesystem::perms::group_read;
std::filesystem::permissions(filename, permission);
const auto& c = SessionStore::getInstance().getAuthMethodsConfig();
+ const auto& eventServiceConfig =
+ EventServiceStore::getInstance().getEventServiceConfig();
nlohmann::json data{
{"auth_config",
{{"XToken", c.xtoken},
@@ -179,6 +211,13 @@ class ConfigFile
{"TLS", c.tls}}
},
+ {"eventservice_config",
+ {{"ServiceEnabled", eventServiceConfig.enabled},
+ {"DeliveryRetryAttempts", eventServiceConfig.retryAttempts},
+ {"DeliveryRetryIntervalSeconds",
+ eventServiceConfig.retryTimeoutInterval}}
+
+ },
{"system_uuid", systemUuid},
{"revision", jsonRevision},
{"timeout", SessionStore::getInstance().getTimeoutInSeconds()}};
@@ -202,6 +241,34 @@ class ConfigFile
});
}
}
+ nlohmann::json& subscriptions = data["subscriptions"];
+ subscriptions = nlohmann::json::array();
+ for (const auto& it :
+ EventServiceStore::getInstance().subscriptionsConfigMap)
+ {
+ std::shared_ptr<UserSubscription> subValue = it.second;
+ if (subValue->subscriptionType == "SSE")
+ {
+ BMCWEB_LOG_DEBUG
+ << "The subscription type is SSE, so skipping.";
+ continue;
+ }
+ subscriptions.push_back({
+ {"Id", subValue->id},
+ {"Context", subValue->customText},
+ {"DeliveryRetryPolicy", subValue->retryPolicy},
+ {"Destination", subValue->destinationUrl},
+ {"EventFormatType", subValue->eventFormatType},
+ {"HttpHeaders", subValue->httpHeaders},
+ {"MessageIds", subValue->registryMsgIds},
+ {"Protocol", subValue->protocol},
+ {"RegistryPrefixes", subValue->registryPrefixes},
+ {"ResourceTypes", subValue->resourceTypes},
+ {"SubscriptionType", subValue->subscriptionType},
+ {"MetricReportDefinitions", subValue->metricReportDefinitions},
+
+ });
+ }
persistentFile << data;
}