From d585436d7c4d1bc7e064d3142ce9349b9fa54400 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Mon, 12 Oct 2015 15:07:39 -0400 Subject: [PATCH] rgw: move RGWPostRESTResourceCR to rgw_cr_rest.h for use by RGWRealmPusher Signed-off-by: Casey Bodley --- src/rgw/rgw_cr_rest.h | 56 ++++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_rados.cc | 57 +------------------------------------------ 2 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/rgw/rgw_cr_rest.h b/src/rgw/rgw_cr_rest.h index 86347592dd0b1..c9971f6809675 100644 --- a/src/rgw/rgw_cr_rest.h +++ b/src/rgw/rgw_cr_rest.h @@ -2,6 +2,7 @@ #define CEPH_RGW_CR_REST_H #include "rgw_coroutine.h" +#include "rgw_rest_conn.h" #include @@ -55,5 +56,60 @@ public: } }; +template +class RGWPostRESTResourceCR : public RGWSimpleCoroutine { + RGWRESTConn *conn; + RGWHTTPManager *http_manager; + string path; + rgw_http_param_pair *params; + T *result; + S input; + + RGWRESTPostResource *http_op; + +public: + RGWPostRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, RGWHTTPManager *_http_manager, + const string& _path, rgw_http_param_pair *_params, S& _input, + T *_result) : RGWSimpleCoroutine(_cct), conn(_conn), http_manager(_http_manager), + path(_path), params(_params), result(_result), input(_input), http_op(NULL) {} + + int send_request() { + http_op = new RGWRESTPostResource(conn, path, params, NULL, http_manager); + + http_op->set_user_info((void *)stack); + + JSONFormatter jf; + encode_json("data", input, &jf); + std::stringstream ss; + jf.flush(ss); + bufferlist bl; + bl.append(ss.str()); + + int ret = http_op->aio_send(bl); + if (ret < 0) { + lsubdout(cct, rgw, 0) << "ERROR: failed to send post request" << dendl; + http_op->put(); + return ret; + } + return 0; + } + + int request_complete() { + int ret; + if (result) { + ret = http_op->wait(result); + } else { + bufferlist bl; + ret = http_op->wait_bl(&bl); + } + http_op->put(); + if (ret < 0) { + error_stream << "http operation failed: " << http_op->to_str() << " status=" << http_op->get_http_status() << std::endl; + lsubdout(cct, rgw, 0) << "ERROR: failed to wait for op, ret=" << ret << ": " << http_op->to_str() << dendl; + return ret; + } + return 0; + } +}; #endif diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 067561b3e1939..08dd21b87d064 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -22,6 +22,7 @@ #include "rgw_metadata.h" #include "rgw_bucket.h" #include "rgw_rest_conn.h" +#include "rgw_cr_rest.h" #include "cls/rgw/cls_rgw_ops.h" #include "cls/rgw/cls_rgw_types.h" @@ -2367,62 +2368,6 @@ void RGWObjectCtx::set_prefetch_data(rgw_obj& obj) { } } -template -class RGWPostRESTResourceCR : public RGWSimpleCoroutine { - RGWRESTConn *conn; - RGWHTTPManager *http_manager; - string path; - rgw_http_param_pair *params; - T *result; - S input; - - RGWRESTPostResource *http_op; - -public: - RGWPostRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, RGWHTTPManager *_http_manager, - const string& _path, rgw_http_param_pair *_params, S& _input, - T *_result) : RGWSimpleCoroutine(_cct), conn(_conn), http_manager(_http_manager), - path(_path), params(_params), result(_result), input(_input), http_op(NULL) {} - - int send_request() { - http_op = new RGWRESTPostResource(conn, path, params, NULL, http_manager); - - http_op->set_user_info((void *)stack); - - JSONFormatter jf; - encode_json("data", input, &jf); - std::stringstream ss; - jf.flush(ss); - bufferlist bl; - bl.append(ss.str()); - - int ret = http_op->aio_send(bl); - if (ret < 0) { - ldout(cct, 0) << "ERROR: failed to send post request" << dendl; - http_op->put(); - return ret; - } - return 0; - } - - int request_complete() { - int ret; - if (result) { - ret = http_op->wait(result); - } else { - bufferlist bl; - ret = http_op->wait_bl(&bl); - } - http_op->put(); - if (ret < 0) { - error_stream << "http operation failed: " << http_op->to_str() << " status=" << http_op->get_http_status() << std::endl; - ldout(cct, 0) << "ERROR: failed to wait for op, ret=" << ret << ": " << http_op->to_str() << dendl; - return ret; - } - return 0; - } -}; - class RGWMetaNotifierManager : public RGWCoroutinesManager { RGWRados *store; RGWHTTPManager http_manager; -- 2.39.5