From 7a760fe79089907f923d637755c13c6e656a27bc Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 9 Sep 2015 10:56:31 -0400 Subject: [PATCH] radosgw-admin: fixes for period push/pull for send_to_remote_gateway() to work, the push and pull commands had to be moved to the not-raw-storage section, because RGWRados::init_complete is needed to set up the gateway connections the period push command was changed to send the json-encoded period data, so an in_data argument was added to send_to_remote_gateway() the parameters for push and pull needed to remain separate from the request_uri, because request_uri is used as input for the auth digest, and the server side parses the parameters separately as well Implements feature #11944 Signed-off-by: Casey Bodley --- src/rgw/rgw_admin.cc | 145 ++++++++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 63 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 7e171b2bc317d..4d5ad0a19ca07 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -6,8 +6,6 @@ #include #include -using namespace std; - #include "auth/Crypto.h" #include "common/armor.h" @@ -36,6 +34,8 @@ using namespace std; #include "rgw_sync.h" #include "rgw_rest_conn.h" +using namespace std; + #define dout_subsys ceph_subsys_rgw #define SECRET_KEY_LEN 40 @@ -175,9 +175,10 @@ void _usage() cerr << " --remote= remote to pull period\n"; cerr << " --parent= parent period id\n"; cerr << " --period= period id\n"; + cerr << " --epoch= period epoch\n"; cerr << " --master-zonegroup= master zonegroup id\n"; cerr << " --master-zone= master zone id\n"; - cerr << " --realm= realm name\n"; + cerr << " --realm= realm name\n"; cerr << " --realm-id= realm id\n"; cerr << " --realm-new-name= realm new name\n"; cerr << " --zonegroup= zonegroup name\n"; @@ -1215,9 +1216,10 @@ int do_check_object_locator(const string& tenant_name, const string& bucket_name } #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response -int send_to_remote_gateway(const string& remote,req_info& info, JSONParser& p) +int send_to_remote_gateway(const string& remote, req_info& info, JSONParser& p, + bufferlist &in_data) { - bufferlist in_data, response; + bufferlist response; RGWRESTConn *conn; if (remote.empty()) { if (!store->rest_master_conn) { @@ -1261,12 +1263,11 @@ int main(int argc, char **argv) std::string date, subuser, access, format; std::string start_date, end_date; std::string key_type_str; - std::string period_id, url, parent_period; + std::string period_id, period_epoch, remote, url, parent_period; std::string master_zonegroup, master_zone; std::string realm_name, realm_id, realm_new_name; std::string zone_name, zone_id, zone_new_name; std::string zonegroup_name, zonegroup_id, zonegroup_new_name; - epoch_t period_epoch = 0; int key_type = KEY_TYPE_UNDEFINED; rgw_bucket bucket; uint32_t perm_mask = 0; @@ -1564,6 +1565,10 @@ int main(int argc, char **argv) master_zone = val; } else if (ceph_argparse_witharg(args, i, &val, "--period", (char*)NULL)) { period_id = val; + } else if (ceph_argparse_witharg(args, i, &val, "--epoch", (char*)NULL)) { + period_epoch = val; + } else if (ceph_argparse_witharg(args, i, &val, "--remote", (char*)NULL)) { + remote = val; } else if (ceph_argparse_witharg(args, i, &val, "--url", (char*)NULL)) { url = val; } else if (ceph_argparse_witharg(args, i, &val, "--realm", (char*)NULL)) { @@ -1678,7 +1683,6 @@ int main(int argc, char **argv) opt_cmd == OPT_ZONE_LIST || opt_cmd == OPT_ZONE_CREATE || opt_cmd == OPT_REALM_CREATE || opt_cmd == OPT_PERIOD_PREPARE || opt_cmd == OPT_PERIOD_ACTIVATE || opt_cmd == OPT_PERIOD_DELETE || opt_cmd == OPT_PERIOD_GET || - opt_cmd == OPT_PERIOD_PULL || opt_cmd == OPT_PERIOD_PUSH || opt_cmd == OPT_PERIOD_GET_CURRENT || opt_cmd == OPT_PERIOD_LIST || opt_cmd == OPT_REALM_DELETE || opt_cmd == OPT_REALM_GET || opt_cmd == OPT_REALM_LIST || opt_cmd == OPT_REALM_LIST_PERIODS || @@ -1803,60 +1807,6 @@ int main(int argc, char **argv) } } break; - case OPT_PERIOD_PUSH: - { - req_info info(g_ceph_context, NULL); - info.method = "POST"; - info.request_uri = "/admin/realm/period?"; - if (!period_id.empty()) { - info.request_uri += "period_id=" + period_id; - } - if (!period_epoch) { - if (!period_id.empty()) { - info.request_uri =+ "&"; - } - info.request_uri += "epoch=" + period_epoch; - } - - JSONParser p; - int ret = send_to_remote_gateway(url, info,p); - if (ret < 0) { - return ret; - } - } - break; - case OPT_PERIOD_PULL: - { - req_info info(g_ceph_context, NULL); - info.method = "GET"; - info.request_uri = "/admin/realm/period?"; - if (!period_id.empty()) { - info.request_uri += "period_id=" + period_id; - } - if (!period_epoch) { - if (!period_id.empty()) { - info.request_uri =+ "&"; - } - info.request_uri += "epoch=" + period_epoch; - } - JSONParser p; - int ret = send_to_remote_gateway(url, info,p); - if (ret < 0) { - return ret; - } - RGWPeriod period(g_ceph_context, store); - try { - decode_json_obj(period, &p); - } catch (JSONDecoder::err& e) { - cout << "failed to decode JSON input: " << e.message << std::endl; - return -EINVAL; - } - ret = period.store_info(true); - if (ret < 0) { - cerr << "Error storing period " << period.get_id() << ": " << cpp_strerror(ret) << std::endl; - } - } - break; case OPT_PERIOD_LIST: { list periods; @@ -2634,8 +2584,77 @@ int main(int argc, char **argv) cerr << "could not remove key: " << err_msg << std::endl; return -ret; } + case OPT_PERIOD_PUSH: + { + RGWEnv env; + req_info info(g_ceph_context, &env); + info.method = "POST"; + info.request_uri = "/admin/realm/period"; + + map ¶ms = info.args.get_params(); + if (!period_id.empty()) + params["period_id"] = period_id; + if (!period_epoch.empty()) + params["epoch"] = period_epoch; + + // load the period + RGWPeriod period(g_ceph_context, store, period_id); + int ret = period.init(); + if (ret < 0) { + cerr << "period init failed: " << cpp_strerror(-ret) << std::endl; + return ret; + } + // json format into a bufferlist + JSONFormatter jf(false); + encode_json("period", period, &jf); + bufferlist bl; + jf.flush(bl); + + JSONParser p; + ret = send_to_remote_gateway(url, info, p, bl); + if (ret < 0) { + cerr << "request failed: " << cpp_strerror(-ret) << std::endl; + return ret; + } + } + return 0; + case OPT_PERIOD_PULL: + { + RGWEnv env; + req_info info(g_ceph_context, &env); + info.method = "GET"; + info.request_uri = "/admin/realm/period"; + + map ¶ms = info.args.get_params(); + if (!period_id.empty()) + params["period_id"] = period_id; + if (!period_epoch.empty()) + params["epoch"] = period_epoch; + + bufferlist bl; + JSONParser p; + int ret = send_to_remote_gateway(url, info, p, bl); + if (ret < 0) { + cerr << "request failed: " << cpp_strerror(-ret) << std::endl; + return ret; + } + RGWPeriod period(g_ceph_context, store); + try { + decode_json_obj(period, &p); + } catch (JSONDecoder::err& e) { + cout << "failed to decode JSON input: " << e.message << std::endl; + return -EINVAL; + } + ret = period.store_info(false); + if (ret < 0) { + cerr << "Error storing period " << period.get_id() << ": " << cpp_strerror(ret) << std::endl; + } - break; + encode_json("period", period, formatter); + formatter->flush(cout); + cout << std::endl; + } + return 0; default: output_user_info = false; } -- 2.39.5