]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: a new cr to send http PUT requests
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 17 Aug 2016 09:00:04 +0000 (02:00 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 7 Oct 2016 17:31:20 +0000 (10:31 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_cr_rest.h
src/rgw/rgw_rest_conn.cc
src/rgw/rgw_rest_conn.h

index bc8dca630ac26bdc58f5c18d6c46559cc37db417..346c3383fcbb21c1a585d8e40c982050bc952c2b 100644 (file)
@@ -68,32 +68,34 @@ public:
 };
 
 template <class S, class T>
-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<RGWRESTPostResource> http_op;
+  boost::intrusive_ptr<RGWRESTSendResource> 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<RGWRESTPostResource>(
-        new RGWRESTPostResource(conn, path, params, NULL, http_manager));
+    auto op = boost::intrusive_ptr<RGWRESTSendResource>(
+        new RGWRESTSendResource(conn, method, path, params, NULL, http_manager));
 
     op->set_user_info((void *)stack);
 
@@ -143,4 +145,28 @@ public:
   }
 };
 
+template <class S, class T>
+class RGWPostRESTResourceCR : public RGWSendRESTResourceCR<S, T> {
+public:
+  RGWPostRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn,
+                        RGWHTTPManager *_http_manager,
+                        const string& _path,
+                        rgw_http_param_pair *_params, S& _input, T *_result)
+    : RGWSendRESTResourceCR<S, T>(_cct, _conn, _http_manager,
+                            "POST", _path,
+                            _params, _input, _result) {}
+};
+
+template <class S, class T>
+class RGWPutRESTResourceCR : public RGWSendRESTResourceCR<S, T> {
+public:
+  RGWPutRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn,
+                        RGWHTTPManager *_http_manager,
+                        const string& _path,
+                        rgw_http_param_pair *_params, S& _input, T *_result)
+    : RGWSendRESTResourceCR<S, T>(_cct, _conn, _http_manager,
+                            "PUT", _path,
+                            _params, _input, _result) {}
+};
+
 #endif
index a95bc7323e423d77d2125fece7cf761aee83f3db..d92a8ca0d76781d23e2e2feead742ced74f9483a 100644 (file)
@@ -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(&params);
 }
 
-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);
index a8d056caa46a99959f02d4cf5a89471775bdf28b..01426034215d0b3efe8e9788903935ce5092a803 100644 (file)
@@ -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<string, string> 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 <class T>
-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 <class T>
-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