From 24bc83e84b4e53121ff4752e011aeb24901d2732 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 24 Aug 2016 10:56:43 -0700 Subject: [PATCH] rgw: add cr to send DELETE to remove endpoint Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_cr_rest.h | 66 ++++++++++++++++++++++++++++++++++++++++- src/rgw/rgw_rest_conn.h | 19 ++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_cr_rest.h b/src/rgw/rgw_cr_rest.h index 346c3383fcbb2..d30c4816ac0f8 100644 --- a/src/rgw/rgw_cr_rest.h +++ b/src/rgw/rgw_cr_rest.h @@ -108,7 +108,7 @@ public: int ret = op->aio_send(bl); if (ret < 0) { - lsubdout(cct, rgw, 0) << "ERROR: failed to send post request" << dendl; + lsubdout(cct, rgw, 0) << "ERROR: failed to send request" << dendl; op->put(); return ret; } @@ -169,4 +169,68 @@ public: _params, _input, _result) {} }; +class RGWDeleteRESTResourceCR : public RGWSimpleCoroutine { + RGWRESTConn *conn; + RGWHTTPManager *http_manager; + string path; + param_vec_t params; + + boost::intrusive_ptr http_op; + +public: + RGWDeleteRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, + RGWHTTPManager *_http_manager, + const string& _path, + rgw_http_param_pair *_params) + : RGWSimpleCoroutine(_cct), conn(_conn), http_manager(_http_manager), + path(_path), params(make_param_list(_params)) + {} + + ~RGWDeleteRESTResourceCR() { + request_cleanup(); + } + + int send_request() { + auto op = boost::intrusive_ptr( + new RGWRESTDeleteResource(conn, path, params, nullptr, http_manager)); + + op->set_user_info((void *)stack); + + bufferlist bl; + + int ret = op->aio_send(bl); + if (ret < 0) { + lsubdout(cct, rgw, 0) << "ERROR: failed to send DELETE request" << dendl; + op->put(); + return ret; + } + std::swap(http_op, op); // store reference in http_op on success + return 0; + } + + int request_complete() { + int ret; + bufferlist bl; + ret = http_op->wait_bl(&bl); + auto op = std::move(http_op); // release ref on return + if (ret < 0) { + error_stream << "http operation failed: " << op->to_str() + << " status=" << op->get_http_status() << std::endl; + lsubdout(cct, rgw, 5) << "failed to wait for op, ret=" << ret + << ": " << op->to_str() << dendl; + op->put(); + return ret; + } + op->put(); + return 0; + } + + void request_cleanup() { + if (http_op) { + http_op->put(); + http_op = NULL; + } + } +}; + #endif diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index 01426034215d0..5ca8b682c866f 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -387,5 +387,24 @@ public: }; +class RGWRESTDeleteResource : public RGWRESTSendResource { +public: + RGWRESTDeleteResource(RGWRESTConn *_conn, + const string& _resource, + const rgw_http_param_pair *pp, + param_vec_t *extra_headers, + RGWHTTPManager *_mgr) : RGWRESTSendResource(_conn, "DELETE", _resource, + pp, extra_headers, _mgr) {} + + RGWRESTDeleteResource(RGWRESTConn *_conn, + const string& _resource, + param_vec_t& params, + param_vec_t *extra_headers, + RGWHTTPManager *_mgr) : RGWRESTSendResource(_conn, "DELETE", _resource, + params, extra_headers, _mgr) {} + +}; + + #endif -- 2.39.5