From: Yehuda Sadeh Date: Wed, 17 Aug 2016 09:00:04 +0000 (-0700) Subject: rgw: a new cr to send http PUT requests X-Git-Tag: v11.1.0~681^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e2477e58fc61203cce38660227fa3683aca42606;p=ceph.git rgw: a new cr to send http PUT requests Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_cr_rest.h b/src/rgw/rgw_cr_rest.h index bc8dca630ac2..346c3383fcbb 100644 --- a/src/rgw/rgw_cr_rest.h +++ b/src/rgw/rgw_cr_rest.h @@ -68,32 +68,34 @@ public: }; template -class RGWPostRESTResourceCR : public RGWSimpleCoroutine { +class RGWSendRESTResourceCR : public RGWSimpleCoroutine { RGWRESTConn *conn; RGWHTTPManager *http_manager; + string method; string path; param_vec_t params; T *result; S input; - boost::intrusive_ptr http_op; + boost::intrusive_ptr http_op; public: - RGWPostRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, - RGWHTTPManager *_http_manager, const string& _path, + RGWSendRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, + RGWHTTPManager *_http_manager, + const string& _method, const string& _path, rgw_http_param_pair *_params, S& _input, T *_result) : RGWSimpleCoroutine(_cct), conn(_conn), http_manager(_http_manager), - path(_path), params(make_param_list(_params)), result(_result), + method(_method), path(_path), params(make_param_list(_params)), result(_result), input(_input) {} - ~RGWPostRESTResourceCR() { + ~RGWSendRESTResourceCR() { request_cleanup(); } int send_request() { - auto op = boost::intrusive_ptr( - new RGWRESTPostResource(conn, path, params, NULL, http_manager)); + auto op = boost::intrusive_ptr( + new RGWRESTSendResource(conn, method, path, params, NULL, http_manager)); op->set_user_info((void *)stack); @@ -143,4 +145,28 @@ public: } }; +template +class RGWPostRESTResourceCR : public RGWSendRESTResourceCR { +public: + RGWPostRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, + RGWHTTPManager *_http_manager, + const string& _path, + rgw_http_param_pair *_params, S& _input, T *_result) + : RGWSendRESTResourceCR(_cct, _conn, _http_manager, + "POST", _path, + _params, _input, _result) {} +}; + +template +class RGWPutRESTResourceCR : public RGWSendRESTResourceCR { +public: + RGWPutRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, + RGWHTTPManager *_http_manager, + const string& _path, + rgw_http_param_pair *_params, S& _input, T *_result) + : RGWSendRESTResourceCR(_cct, _conn, _http_manager, + "PUT", _path, + _params, _input, _result) {} +}; + #endif diff --git a/src/rgw/rgw_rest_conn.cc b/src/rgw/rgw_rest_conn.cc index a95bc7323e42..d92a8ca0d767 100644 --- a/src/rgw/rgw_rest_conn.cc +++ b/src/rgw/rgw_rest_conn.cc @@ -282,30 +282,32 @@ int RGWRESTReadResource::aio_read() return 0; } -RGWRESTPostResource::RGWRESTPostResource(RGWRESTConn *_conn, +RGWRESTSendResource::RGWRESTSendResource(RGWRESTConn *_conn, + const string& _method, const string& _resource, const rgw_http_param_pair *pp, param_vec_t *extra_headers, RGWHTTPManager *_mgr) - : cct(_conn->get_ctx()), conn(_conn), resource(_resource), + : cct(_conn->get_ctx()), conn(_conn), method(_method), resource(_resource), params(make_param_list(pp)), cb(bl), mgr(_mgr), - req(cct, "POST", conn->get_url(), &cb, NULL, NULL) + req(cct, method.c_str(), conn->get_url(), &cb, NULL, NULL) { init_common(extra_headers); } -RGWRESTPostResource::RGWRESTPostResource(RGWRESTConn *_conn, +RGWRESTSendResource::RGWRESTSendResource(RGWRESTConn *_conn, + const string& _method, const string& _resource, param_vec_t& params, param_vec_t *extra_headers, RGWHTTPManager *_mgr) - : cct(_conn->get_ctx()), conn(_conn), resource(_resource), params(params), - cb(bl), mgr(_mgr), req(cct, "POST", conn->get_url(), &cb, NULL, NULL) + : cct(_conn->get_ctx()), conn(_conn), method(_method), resource(_resource), params(params), + cb(bl), mgr(_mgr), req(cct, method.c_str(), conn->get_url(), &cb, NULL, NULL) { init_common(extra_headers); } -void RGWRESTPostResource::init_common(param_vec_t *extra_headers) +void RGWRESTSendResource::init_common(param_vec_t *extra_headers) { params.push_back(param_pair_t(RGW_SYS_PARAM_PREFIX "zonegroup", conn->get_self_zonegroup())); @@ -316,7 +318,7 @@ void RGWRESTPostResource::init_common(param_vec_t *extra_headers) req.set_params(¶ms); } -int RGWRESTPostResource::send(bufferlist& outbl) +int RGWRESTSendResource::send(bufferlist& outbl) { req.set_outbl(outbl); int ret = req.get_resource(conn->get_key(), headers, resource, mgr); @@ -330,7 +332,7 @@ int RGWRESTPostResource::send(bufferlist& outbl) return req.complete(etag, NULL, NULL, attrs); } -int RGWRESTPostResource::aio_send(bufferlist& outbl) +int RGWRESTSendResource::aio_send(bufferlist& outbl) { req.set_outbl(outbl); int ret = req.get_resource(conn->get_key(), headers, resource, mgr); diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index a8d056caa46a..01426034215d 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -253,9 +253,10 @@ int RGWRESTReadResource::wait(T *dest) return 0; } -class RGWRESTPostResource : public RefCountedObject { +class RGWRESTSendResource : public RefCountedObject { CephContext *cct; RGWRESTConn *conn; + string method; string resource; param_vec_t params; map headers; @@ -268,13 +269,15 @@ class RGWRESTPostResource : public RefCountedObject { void init_common(param_vec_t *extra_headers); public: - RGWRESTPostResource(RGWRESTConn *_conn, + RGWRESTSendResource(RGWRESTConn *_conn, + const string& _method, const string& _resource, const rgw_http_param_pair *pp, param_vec_t *extra_headers, RGWHTTPManager *_mgr); - RGWRESTPostResource(RGWRESTConn *_conn, + RGWRESTSendResource(RGWRESTConn *_conn, + const string& _method, const string& _resource, param_vec_t& params, param_vec_t *extra_headers, @@ -320,7 +323,7 @@ public: }; template -int RGWRESTPostResource::decode_resource(T *dest) +int RGWRESTSendResource::decode_resource(T *dest) { int ret = req.get_status(); if (ret < 0) { @@ -334,7 +337,7 @@ int RGWRESTPostResource::decode_resource(T *dest) } template -int RGWRESTPostResource::wait(T *dest) +int RGWRESTSendResource::wait(T *dest) { int ret = req.wait(); if (ret < 0) { @@ -348,4 +351,41 @@ int RGWRESTPostResource::wait(T *dest) return 0; } +class RGWRESTPostResource : public RGWRESTSendResource { +public: + RGWRESTPostResource(RGWRESTConn *_conn, + const string& _resource, + const rgw_http_param_pair *pp, + param_vec_t *extra_headers, + RGWHTTPManager *_mgr) : RGWRESTSendResource(_conn, "POST", _resource, + pp, extra_headers, _mgr) {} + + RGWRESTPostResource(RGWRESTConn *_conn, + const string& _resource, + param_vec_t& params, + param_vec_t *extra_headers, + RGWHTTPManager *_mgr) : RGWRESTSendResource(_conn, "POST", _resource, + params, extra_headers, _mgr) {} + +}; + +class RGWRESTPutResource : public RGWRESTSendResource { +public: + RGWRESTPutResource(RGWRESTConn *_conn, + const string& _resource, + const rgw_http_param_pair *pp, + param_vec_t *extra_headers, + RGWHTTPManager *_mgr) : RGWRESTSendResource(_conn, "PUT", _resource, + pp, extra_headers, _mgr) {} + + RGWRESTPutResource(RGWRESTConn *_conn, + const string& _resource, + param_vec_t& params, + param_vec_t *extra_headers, + RGWHTTPManager *_mgr) : RGWRESTSendResource(_conn, "PUT", _resource, + params, extra_headers, _mgr) {} + +}; + + #endif