From 43b629c180e1b4350a9e9bd917d81a49acb57731 Mon Sep 17 00:00:00 2001
From: P Dheeraj Srujan Kumar
Date: Mon, 6 Dec 2021 19:49:01 +0000
Subject: [PATCH] Add unmerged changes for http retry support
The http retry support added upstream as a single patch was slpit into
3 patches, but only 2 of them was merged.
This commit pulls in the differentail changes required to complete the
entire http retry support. and also allow for other subsequent patches
to be appplied easily.
Change-Id: I43e68eeffb8d69c289dd306c1c7cafc87ad766a0
Signed-off-by: P Dheeraj Srujan Kumar
---
http/http_client.hpp | 32 ++++++++++++++++---
.../include/event_service_manager.hpp | 26 +++++++++------
redfish-core/lib/event_service.hpp | 1 +
3 files changed, 45 insertions(+), 14 deletions(-)
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 0c9e387..0701d9e 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -189,6 +189,17 @@ class HttpClient : public std::enable_shared_from_this
BMCWEB_LOG_DEBUG << "recvMessage() data: "
<< self->parser->get();
+ // Check if the response and header are received
+ if (!self->parser->is_done())
+ {
+ // The parser failed to receive the response
+ BMCWEB_LOG_ERROR
+ << "recvMessage() parser failed to receive response";
+ self->state = ConnState::recvFailed;
+ self->handleConnState();
+ return;
+ }
+
unsigned int respCode = self->parser->get().result_int();
BMCWEB_LOG_DEBUG << "recvMessage() Header Response Code: "
<< respCode;
@@ -381,15 +392,17 @@ class HttpClient : public std::enable_shared_from_this
public:
explicit HttpClient(boost::asio::io_context& ioc, const std::string& id,
const std::string& destIP, const std::string& destPort,
- const std::string& destUri,
- const boost::beast::http::fields& httpHeader) :
+ const std::string& destUri) :
conn(ioc),
- timer(ioc),
- req(boost::beast::http::verb::post, destUri, 11, "", httpHeader),
- subId(id), host(destIP), port(destPort)
+ timer(ioc), req(boost::beast::http::verb::post, destUri, 11), subId(id),
+ host(destIP), port(destPort)
{
+ // Set the request header
req.set(boost::beast::http::field::host, host);
+ req.set(boost::beast::http::field::content_type, "application/json");
req.keep_alive(true);
+
+ requestDataQueue.set_capacity(maxRequestQueueSize);
}
void sendData(const std::string& data)
@@ -412,6 +425,15 @@ class HttpClient : public std::enable_shared_from_this
return;
}
+ void setHeaders(const boost::beast::http::fields& httpHeaders)
+ {
+ // Set custom headers
+ for (const auto& header : httpHeaders)
+ {
+ req.set(header.name(), header.value());
+ }
+ }
+
void setRetryConfig(const uint32_t retryAttempts,
const uint32_t retryTimeoutInterval)
{
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index e0f290c..7a2f096 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -384,7 +384,10 @@ class Subscription : public persistent_data::UserSubscription
eventSeqNum(1),
host(inHost), port(inPort), path(inPath), uriProto(inUriProto)
{
- // Subscription constructor
+ // create the HttpClient connection
+ conn = std::make_shared(
+ crow::connections::systemBus->get_io_context(), id, host, port,
+ path);
}
Subscription(const std::shared_ptr& adaptor) :
@@ -397,17 +400,12 @@ class Subscription : public persistent_data::UserSubscription
void sendEvent(const std::string& msg)
{
- if (conn == nullptr)
+ if (conn != nullptr)
{
- // create the HttpClient connection
- conn = std::make_shared(
- crow::connections::systemBus->get_io_context(), id, host, port,
- path, httpHeaders);
+ conn->sendData(msg);
+ eventSeqNum++;
}
- conn->sendData(msg);
- eventSeqNum++;
-
if (sseConn != nullptr)
{
sseConn->sendData(eventSeqNum, msg);
@@ -551,6 +549,14 @@ class Subscription : public persistent_data::UserSubscription
}
}
+ void updatehttpHeaders()
+ {
+ if (conn != nullptr)
+ {
+ conn->setHeaders(httpHeaders);
+ }
+ }
+
uint64_t getEventSeqNum()
{
return eventSeqNum;
@@ -664,6 +670,7 @@ class EventServiceManager
// Update retry configuration.
subValue->updateRetryConfig(retryAttempts, retryTimeoutInterval);
subValue->updateRetryPolicy();
+ subValue->updatehttpHeaders();
}
return;
}
@@ -919,6 +926,7 @@ class EventServiceManager
// Update retry configuration.
subValue->updateRetryConfig(retryAttempts, retryTimeoutInterval);
subValue->updateRetryPolicy();
+ subValue->updatehttpHeaders();
return id;
}
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index d273aea..7739ad0 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -611,6 +611,7 @@ inline void requestRoutesEventDestination(App& app)
}
}
subValue->httpHeaders = fields;
+ subValue->updatehttpHeaders();
}
if (retryPolicy)
--
2.17.1