]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Export user stats in get-user-info Adminops API 2446/head
authorRay Lv <xiangyulv@gmail.com>
Wed, 10 Sep 2014 07:33:22 +0000 (15:33 +0800)
committerRay Lv <xiangyulv@gmail.com>
Wed, 17 Sep 2014 13:05:59 +0000 (21:05 +0800)
Fixes: #9359
Signed-off-by: Ray Lv <raylv@yahoo-inc.com>
src/rgw/rgw_common.h
src/rgw/rgw_json_enc.cc
src/rgw/rgw_rest_user.cc
src/rgw/rgw_user.cc
src/rgw/rgw_user.h

index 1170650b56aaef476decca088980b6b7c4bbfed2..69d04ac27ba137ad77bbac214b08ab68d314b1ed 100644 (file)
@@ -827,6 +827,8 @@ struct RGWStorageStats
   uint64_t num_objects;
 
   RGWStorageStats() : category(RGW_OBJ_CATEGORY_NONE), num_kb(0), num_kb_rounded(0), num_objects(0) {}
+
+  void dump(Formatter *f) const;
 };
 
 struct req_state;
index 44db537c5ed727b9ded5d2e5fe432359c10533e7..b70b613f49a996b4e0effcbc9992b613e89eda23 100644 (file)
@@ -528,6 +528,13 @@ void RGWBucketEntryPoint::decode_json(JSONObj *obj) {
   }
 }
 
+void RGWStorageStats::dump(Formatter *f) const
+{
+  encode_json("num_kb", num_kb, f);
+  encode_json("num_kb_rounded", num_kb_rounded, f);
+  encode_json("num_objects", num_objects, f);
+}
+
 void RGWBucketInfo::dump(Formatter *f) const
 {
   encode_json("bucket", bucket, f);
index c95ea46986439fc3a65cc57a4baa847f869ae628..ea35d6f4dcf39195d4f4ede6a8c393faa49f64c7 100644 (file)
@@ -30,10 +30,13 @@ void RGWOp_User_Info::execute()
   RGWUserAdminOpState op_state;
 
   std::string uid;
+  bool fetch_stats;
 
   RESTArgs::get_string(s, "uid", uid, &uid);
+  RESTArgs::get_bool(s, "stats", false, &fetch_stats);
 
   op_state.set_user_id(uid);
+  op_state.set_fetch_stats(fetch_stats);
 
   http_ret = RGWUserAdminOp_User::info(store, op_state, flusher);
 }
index 18ce41ecd574d82483648a2f9d0a07dec391bfc0..4f373585c56c2113d2fc536300e8956b4c806547 100644 (file)
@@ -621,7 +621,8 @@ static void dump_swift_keys_info(Formatter *f, RGWUserInfo &info)
   f->close_section();
 }
 
-static void dump_user_info(Formatter *f, RGWUserInfo &info)
+static void dump_user_info(Formatter *f, RGWUserInfo &info,
+                           RGWStorageStats *stats = NULL)
 {
   f->open_object_section("user_info");
 
@@ -635,6 +636,9 @@ static void dump_user_info(Formatter *f, RGWUserInfo &info)
   dump_access_keys_info(f, info);
   dump_swift_keys_info(f, info);
   info.caps.dump(f);
+  if (stats) {
+    encode_json("stats", *stats, f);
+  }
 
   f->close_section();
 }
@@ -2128,9 +2132,20 @@ int RGWUserAdminOp_User::info(RGWRados *store, RGWUserAdminOpState& op_state,
   if (ret < 0)
     return ret;
 
+  RGWStorageStats stats;
+  RGWStorageStats *arg_stats = NULL;
+  if (op_state.fetch_stats) {
+    int ret = store->get_user_stats(info.user_id, stats);
+    if (ret < 0) {
+      return ret;
+    }
+
+    arg_stats = &stats;
+  }
+
   flusher.start(0);
 
-  dump_user_info(formatter, info);
+  dump_user_info(formatter, info, arg_stats);
   flusher.flush();
 
   return 0;
index f13c241abbb55f901435370707e8cc342d34b41c..317cd06cd31127b1c2eb0363ab204b697ee0e3e6 100644 (file)
@@ -134,6 +134,7 @@ struct RGWUserAdminOpState {
   __u8 suspended;
   __u8 system;
   __u8 exclusive;
+  __u8 fetch_stats;
   std::string caps;
   RGWObjVersionTracker objv;
   uint32_t op_mask;
@@ -273,6 +274,9 @@ struct RGWUserAdminOpState {
   void set_exclusive(__u8 is_exclusive) {
     exclusive = is_exclusive;
   }
+  void set_fetch_stats(__u8 is_fetch_stats) {
+    fetch_stats = is_fetch_stats;
+  }
   void set_user_info(RGWUserInfo& user_info) {
     user_id = user_info.user_id;
     info = user_info;
@@ -411,6 +415,7 @@ struct RGWUserAdminOpState {
     suspended = 0;
     system = 0;
     exclusive = 0;
+    fetch_stats = 0;
     op_mask = 0;
 
     existing_user = false;