From a69e69aaa3a2a63729c3421909bbf413d2689171 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 16 Oct 2015 16:41:00 -0400 Subject: [PATCH] rgw: move period Ops to rgw_rest_realm.cc this removes the handling of /admin/config?type=period Signed-off-by: Casey Bodley --- src/rgw/rgw_rest_config.cc | 74 ---------------------------------- src/rgw/rgw_rest_config.h | 33 +-------------- src/rgw/rgw_rest_realm.cc | 82 +++++++++++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 111 deletions(-) diff --git a/src/rgw/rgw_rest_config.cc b/src/rgw/rgw_rest_config.cc index 8b3abe1ba91cc..0c25e0c6ca219 100644 --- a/src/rgw/rgw_rest_config.cc +++ b/src/rgw/rgw_rest_config.cc @@ -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; - -} diff --git a/src/rgw/rgw_rest_config.h b/src/rgw/rgw_rest_config.h index 19d0379d718f3..8b22d240b214b 100644 --- a/src/rgw/rgw_rest_config.h +++ b/src/rgw/rgw_rest_config.h @@ -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; diff --git a/src/rgw/rgw_rest_realm.cc b/src/rgw/rgw_rest_realm.cc index 50b5ce2dd6bd5..1749417301c9b 100644 --- a/src/rgw/rgw_rest_realm.cc +++ b/src/rgw/rgw_rest_realm.cc @@ -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() -- 2.39.5