]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw-admin: add read_current_period_id() helper function
authorCasey Bodley <cbodley@redhat.com>
Fri, 19 Feb 2016 19:19:24 +0000 (14:19 -0500)
committerCasey Bodley <cbodley@redhat.com>
Fri, 4 Mar 2016 22:04:08 +0000 (17:04 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_admin.cc

index 40581ddc73eac197d4ef13c2b02e5a6304a3be74..3ff498de70abbc6d6c039743967f49ffcaca98ee 100644 (file)
@@ -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<const char*> 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<string> 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;
     }