]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_cr_rest.h
1 #ifndef CEPH_RGW_CR_REST_H
2 #define CEPH_RGW_CR_REST_H
4 #include <boost/intrusive_ptr.hpp>
5 #include "include/assert.h" // boost header clobbers our assert.h
7 #include "rgw_coroutine.h"
8 #include "rgw_rest_conn.h"
11 class RGWReadRESTResourceCR
: public RGWSimpleCoroutine
{
13 RGWHTTPManager
*http_manager
;
18 boost::intrusive_ptr
<RGWRESTReadResource
> http_op
;
21 RGWReadRESTResourceCR(CephContext
*_cct
, RGWRESTConn
*_conn
,
22 RGWHTTPManager
*_http_manager
, const string
& _path
,
23 rgw_http_param_pair
*params
, T
*_result
)
24 : RGWSimpleCoroutine(_cct
), conn(_conn
), http_manager(_http_manager
),
25 path(_path
), params(make_param_list(params
)), result(_result
)
28 ~RGWReadRESTResourceCR() override
{
32 int send_request() override
{
33 auto op
= boost::intrusive_ptr
<RGWRESTReadResource
>(
34 new RGWRESTReadResource(conn
, path
, params
, NULL
, http_manager
));
36 op
->set_user_info((void *)stack
);
38 int ret
= op
->aio_read();
40 log_error() << "failed to send http operation: " << op
->to_str()
41 << " ret=" << ret
<< std::endl
;
45 std::swap(http_op
, op
); // store reference in http_op on success
49 int request_complete() override
{
50 int ret
= http_op
->wait(result
);
51 auto op
= std::move(http_op
); // release ref on return
53 error_stream
<< "http operation failed: " << op
->to_str()
54 << " status=" << op
->get_http_status() << std::endl
;
62 void request_cleanup() override
{
70 template <class S
, class T
>
71 class RGWSendRESTResourceCR
: public RGWSimpleCoroutine
{
73 RGWHTTPManager
*http_manager
;
80 boost::intrusive_ptr
<RGWRESTSendResource
> http_op
;
83 RGWSendRESTResourceCR(CephContext
*_cct
, RGWRESTConn
*_conn
,
84 RGWHTTPManager
*_http_manager
,
85 const string
& _method
, const string
& _path
,
86 rgw_http_param_pair
*_params
, S
& _input
, T
*_result
)
87 : RGWSimpleCoroutine(_cct
), conn(_conn
), http_manager(_http_manager
),
88 method(_method
), path(_path
), params(make_param_list(_params
)), result(_result
),
92 ~RGWSendRESTResourceCR() override
{
96 int send_request() override
{
97 auto op
= boost::intrusive_ptr
<RGWRESTSendResource
>(
98 new RGWRESTSendResource(conn
, method
, path
, params
, NULL
, http_manager
));
100 op
->set_user_info((void *)stack
);
103 encode_json("data", input
, &jf
);
104 std::stringstream ss
;
109 int ret
= op
->aio_send(bl
);
111 lsubdout(cct
, rgw
, 0) << "ERROR: failed to send request" << dendl
;
115 std::swap(http_op
, op
); // store reference in http_op on success
119 int request_complete() override
{
122 ret
= http_op
->wait(result
);
125 ret
= http_op
->wait_bl(&bl
);
127 auto op
= std::move(http_op
); // release ref on return
129 error_stream
<< "http operation failed: " << op
->to_str()
130 << " status=" << op
->get_http_status() << std::endl
;
131 lsubdout(cct
, rgw
, 5) << "failed to wait for op, ret=" << ret
132 << ": " << op
->to_str() << dendl
;
140 void request_cleanup() override
{
148 template <class S
, class T
>
149 class RGWPostRESTResourceCR
: public RGWSendRESTResourceCR
<S
, T
> {
151 RGWPostRESTResourceCR(CephContext
*_cct
, RGWRESTConn
*_conn
,
152 RGWHTTPManager
*_http_manager
,
154 rgw_http_param_pair
*_params
, S
& _input
, T
*_result
)
155 : RGWSendRESTResourceCR
<S
, T
>(_cct
, _conn
, _http_manager
,
157 _params
, _input
, _result
) {}
160 template <class S
, class T
>
161 class RGWPutRESTResourceCR
: public RGWSendRESTResourceCR
<S
, T
> {
163 RGWPutRESTResourceCR(CephContext
*_cct
, RGWRESTConn
*_conn
,
164 RGWHTTPManager
*_http_manager
,
166 rgw_http_param_pair
*_params
, S
& _input
, T
*_result
)
167 : RGWSendRESTResourceCR
<S
, T
>(_cct
, _conn
, _http_manager
,
169 _params
, _input
, _result
) {}
172 class RGWDeleteRESTResourceCR
: public RGWSimpleCoroutine
{
174 RGWHTTPManager
*http_manager
;
178 boost::intrusive_ptr
<RGWRESTDeleteResource
> http_op
;
181 RGWDeleteRESTResourceCR(CephContext
*_cct
, RGWRESTConn
*_conn
,
182 RGWHTTPManager
*_http_manager
,
184 rgw_http_param_pair
*_params
)
185 : RGWSimpleCoroutine(_cct
), conn(_conn
), http_manager(_http_manager
),
186 path(_path
), params(make_param_list(_params
))
189 ~RGWDeleteRESTResourceCR() override
{
193 int send_request() override
{
194 auto op
= boost::intrusive_ptr
<RGWRESTDeleteResource
>(
195 new RGWRESTDeleteResource(conn
, path
, params
, nullptr, http_manager
));
197 op
->set_user_info((void *)stack
);
201 int ret
= op
->aio_send(bl
);
203 lsubdout(cct
, rgw
, 0) << "ERROR: failed to send DELETE request" << dendl
;
207 std::swap(http_op
, op
); // store reference in http_op on success
211 int request_complete() override
{
214 ret
= http_op
->wait_bl(&bl
);
215 auto op
= std::move(http_op
); // release ref on return
217 error_stream
<< "http operation failed: " << op
->to_str()
218 << " status=" << op
->get_http_status() << std::endl
;
219 lsubdout(cct
, rgw
, 5) << "failed to wait for op, ret=" << ret
220 << ": " << op
->to_str() << dendl
;
228 void request_cleanup() override
{