]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: move period Ops to rgw_rest_realm.cc
authorCasey Bodley <cbodley@redhat.com>
Fri, 16 Oct 2015 20:41:00 +0000 (16:41 -0400)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:20 +0000 (16:13 -0800)
this removes the handling of /admin/config?type=period

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_rest_config.cc
src/rgw/rgw_rest_config.h
src/rgw/rgw_rest_realm.cc

index 8b3abe1ba91cc17e8fc45d9c1572e19f0a76098b..0c25e0c6ca219e8a79752b61254d9840659e8899 100644 (file)
@@ -41,77 +41,3 @@ void RGWOp_ZoneGroupMap_Get::send_response() {
   encode_json("region-map", zone_group_map, s->formatter);
   flusher.flush(); 
 }
-
-void RGWOp_Period_Get::execute() {
-  string period_id;
-  RESTArgs::get_string(s, "period_id", period_id, &period_id);
-  epoch_t epoch = 0;
-  RESTArgs::get_uint32(s, "epoch", 0, &epoch);
-
-  period = new RGWPeriod(period_id, epoch);
-  http_ret = period->init(g_ceph_context, store);
-  if (http_ret < 0) {
-    dout(5) << "failed to read period" << dendl;
-  }
-}
-
-void RGWOp_Period_Get::send_response() {
-  set_req_state_err(s, http_ret);
-  dump_errno(s);
-  end_header(s);
-
-  if (http_ret < 0)
-    return;
-
-  encode_json("period", *period, s->formatter);
-  flusher.flush();
-}
-
-void RGWOp_Period_Post::execute() {
-  string period_id;
-  RESTArgs::get_string(s, "period_id", period_id, &period_id);
-  epoch_t epoch = 0;
-  RESTArgs::get_uint32(s, "epoch", 0, &epoch);
-
-  RGWPeriod period(period_id, epoch);
-  http_ret = period.init(g_ceph_context, store);
-  if (http_ret < 0) {
-    dout(5) << "failed to read period" << dendl;
-    return;
-  }
-
-#define PERIOD_INPUT_MAX_LEN 4096
-  bool empty;
-  http_ret = rgw_rest_get_json_input(store->ctx(), s, period,
-                                     PERIOD_INPUT_MAX_LEN, &empty);
-  if (http_ret < 0) {
-    dout(5) << "failed to decode period" << dendl;
-    return;
-  }
-
-  period.store_info(false);
-}
-
-RGWOp* RGWHandler_Config::op_get() {
-  bool exists;
-  string type = s->info.args.get("type", &exists);
-
-  if (type.compare("period") == 0) {
-    return new RGWOp_Period_Get;
-  } else {
-    return new RGWOp_ZoneGroupMap_Get;
-  }
-}
-
-
-RGWOp* RGWHandler_Config::op_post() {
-  bool exists;
-  string type = s->info.args.get("type", &exists);
-
-  if (type.compare("period") == 0) {
-    return new RGWOp_Period_Post;
-  }
-
-  return NULL;
-
-}
index 19d0379d718f32bbac6c21de0562083235a9e0ef..8b22d240b214b6fb745604ea78f214e38491324a 100644 (file)
@@ -30,40 +30,9 @@ public:
   }
 };
 
-class RGWOp_Period_Get : public RGWRESTOp {
-  RGWPeriod *period;
-public:
-  RGWOp_Period_Get() : period(NULL) {}
-  ~RGWOp_Period_Get() { delete period; }
-
-  int verify_permission() {
-    return 0;
-  }
-  void execute();
-  virtual void send_response();
-  virtual const string name() {
-    return "get_period";
-  }
-};
-
-class RGWOp_Period_Post : public RGWRESTOp {
-public:
-  RGWOp_Period_Post() {}
-  ~RGWOp_Period_Post() {}
-
-  int verify_permission() {
-    return 0;
-  }
-  void execute();
-  virtual const string name() {
-    return "post_period";
-  }
-};
-
 class RGWHandler_Config : public RGWHandler_Auth_S3 {
 protected:
-  RGWOp *op_get();
-  RGWOp *op_post();
+  RGWOp *op_get() { return new RGWOp_ZoneGroupMap_Get; }
 
   int read_permissions(RGWOp*) {
     return 0;
index 50b5ce2dd6bd563f14ccf85d382f9123467ebab8..1749417301c9b052b780f0db92e53991015c7e14 100644 (file)
@@ -7,15 +7,87 @@
 
 #define dout_subsys ceph_subsys_rgw
 
+// base period op, shared between Get and Post
+class RGWOp_Period_Base : public RGWRESTOp {
+ protected:
+  RGWPeriod period;
+ public:
+  int verify_permission() override { return 0; }
+  void send_response() override;
+};
+
+// reply with the period object on success
+void RGWOp_Period_Base::send_response()
+{
+  set_req_state_err(s, http_ret);
+  dump_errno(s);
+  end_header(s);
+
+  if (http_ret < 0)
+    return;
+
+  encode_json("period", period, s->formatter);
+  flusher.flush();
+}
+
+// GET /admin/realm/period
+class RGWOp_Period_Get : public RGWOp_Period_Base {
+ public:
+  void execute() override;
+  const string name() override { return "get_period"; }
+};
+
+void RGWOp_Period_Get::execute()
+{
+  string period_id;
+  epoch_t epoch = 0;
+  RESTArgs::get_string(s, "period_id", period_id, &period_id);
+  RESTArgs::get_uint32(s, "epoch", 0, &epoch);
+
+  period.set_id(period_id);
+  period.set_epoch(epoch);
+
+  http_ret = period.init(store->ctx(), store);
+  if (http_ret < 0)
+    ldout(store->ctx(), 5) << "failed to read period" << dendl;
+}
+
+// POST /admin/realm/period
+class RGWOp_Period_Post : public RGWOp_Period_Base {
+ public:
+  void execute() override;
+  const string name() override { return "post_period"; }
+};
+
+void RGWOp_Period_Post::execute()
+{
+  // initialize the period without reading from rados
+  period.init(store->ctx(), store, false);
+
+  // decode the period from input
+#define PERIOD_INPUT_MAX_LEN 4096
+  bool empty;
+  http_ret = rgw_rest_get_json_input(store->ctx(), s, period,
+                                     PERIOD_INPUT_MAX_LEN, &empty);
+  if (http_ret < 0) {
+    dout(5) << "failed to decode period" << dendl;
+    return;
+  }
+
+  period.store_info(false);
+}
+
 class RGWHandler_Period : public RGWHandler_Auth_S3 {
-protected:
-  RGWOp *op_get() { return new RGWOp_Period_Get; }
-  RGWOp *op_post() { return new RGWOp_Period_Post; }
+ protected:
+  RGWOp *op_get() override { return new RGWOp_Period_Get; }
+  RGWOp *op_post() override { return new RGWOp_Period_Post; }
 };
 
 class RGWRESTMgr_Period : public RGWRESTMgr {
-public:
-  RGWHandler *get_handler(struct req_state *s) { return new RGWHandler_Period; }
+ public:
+  RGWHandler* get_handler(struct req_state*) override {
+    return new RGWHandler_Period;
+  }
 };
 
 RGWRESTMgr_Realm::RGWRESTMgr_Realm()