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;
-
-}
}
};
-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;
#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()