From da5f3e7e378d6074cc85bebd1974bd560373a86e Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 19 Feb 2016 14:19:24 -0500 Subject: [PATCH] rgw-admin: add read_current_period_id() helper function Signed-off-by: Casey Bodley --- src/rgw/rgw_admin.cc | 46 ++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 40581ddc73eac..3ff498de70abb 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1556,6 +1556,20 @@ static int do_period_pull(const string& remote, const string& url, const string& return 0; } +static int read_current_period_id(RGWRados* store, const std::string& realm_id, + const std::string& realm_name, + std::string* period_id) +{ + RGWRealm realm(realm_id, realm_name); + int ret = realm.init(g_ceph_context, store); + if (ret < 0) { + std::cerr << "failed to read realm: " << cpp_strerror(-ret) << std::endl; + return ret; + } + *period_id = realm.get_current_period(); + return 0; +} + int main(int argc, char **argv) { vector args; @@ -2137,19 +2151,12 @@ int main(int argc, char **argv) break; case OPT_PERIOD_GET_CURRENT: { - RGWRealm realm(realm_id, realm_name); - int ret = realm.init(g_ceph_context, store); - if (ret < 0 ) { - cerr << "Error initializing realm " << cpp_strerror(-ret) << std::endl; - return ret; - } - string current_id = realm.get_current_period(); + int ret = read_current_period_id(store, realm_id, realm_name, &period_id); if (ret < 0) { - cerr << "Error reading current period:" << cpp_strerror(-ret) << std::endl; return ret; } formatter->open_object_section("period_get_current"); - encode_json("current_period", current_id, formatter); + encode_json("current_period", period_id, formatter); formatter->close_section(); formatter->flush(cout); } @@ -2282,21 +2289,18 @@ int main(int argc, char **argv) break; case OPT_REALM_LIST_PERIODS: { - RGWRealm realm(realm_id, realm_name); - int ret = realm.init(g_ceph_context, store); + int ret = read_current_period_id(store, realm_id, realm_name, &period_id); if (ret < 0) { - cerr << "realm.init failed: " << cpp_strerror(-ret) << std::endl; return -ret; } - string current_period = realm.get_current_period(); list periods; - ret = store->list_periods(current_period, periods); + ret = store->list_periods(period_id, periods); if (ret < 0) { cerr << "list periods failed: " << cpp_strerror(-ret) << std::endl; return -ret; } formatter->open_object_section("realm_periods_list"); - encode_json("current_period", current_period, formatter); + encode_json("current_period", period_id, formatter); encode_json("periods", periods, formatter); formatter->close_section(); formatter->flush(cout); @@ -4383,14 +4387,10 @@ next: int i = (specified_shard_id ? shard_id : 0); if (period_id.empty()) { - // read current_period from the realm - RGWRealm realm(realm_id, realm_name); - ret = realm.init(g_ceph_context, store); + int ret = read_current_period_id(store, realm_id, realm_name, &period_id); if (ret < 0) { - std::cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; return -ret; } - period_id = realm.get_current_period(); std::cerr << "No --period given, using current period=" << period_id << std::endl; } @@ -4434,14 +4434,10 @@ next: int i = (specified_shard_id ? shard_id : 0); if (period_id.empty()) { - // read current_period from the realm - RGWRealm realm(realm_id, realm_name); - int ret = realm.init(g_ceph_context, store); + int ret = read_current_period_id(store, realm_id, realm_name, &period_id); if (ret < 0) { - std::cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; return ret; } - period_id = realm.get_current_period(); std::cerr << "No --period given, using current period=" << period_id << std::endl; } -- 2.39.5