summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/eventservice/0001-Add-unmerged-changes-for-http-retry-support.patch
blob: 7229f9aa794a3e69f9649d9d79301887a108e339 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
From 43b629c180e1b4350a9e9bd917d81a49acb57731 Mon Sep 17 00:00:00 2001
From: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
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 <p.dheeraj.srujan.kumar@intel.com>
---
 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<HttpClient>
                 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<HttpClient>
   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<HttpClient>
         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::HttpClient>(
+            crow::connections::systemBus->get_io_context(), id, host, port,
+            path);
     }
 
     Subscription(const std::shared_ptr<boost::beast::tcp_stream>& 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::HttpClient>(
-                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