]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add RGWRegionMap for backward compatability
authorOrit Wasserman <owasserm@redhat.com>
Mon, 26 Oct 2015 16:59:12 +0000 (17:59 +0100)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:23 +0000 (16:13 -0800)
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
src/rgw/rgw_json_enc.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_rest_config.cc
src/rgw/rgw_rest_config.h

index f743c2af3025756841bb7ea98d7a8579a0889f56..f13828b5c7572ee7af2725d2c2f06248e36d8e2a 100644 (file)
@@ -962,6 +962,22 @@ void RGWPeriodConfig::decode_json(JSONObj *obj)
   JSONDecoder::decode_json("user_quota", user_quota, obj);
 }
 
+void RGWRegionMap::dump(Formatter *f) const
+{
+  encode_json("regions", regions, f);
+  encode_json("master_region", master_region, f);
+  encode_json("bucket_quota", bucket_quota, f);
+  encode_json("user_quota", user_quota, f);
+}
+
+void RGWRegionMap::decode_json(JSONObj *obj)
+{
+  JSONDecoder::decode_json("regions", regions, obj);
+  JSONDecoder::decode_json("master_region", master_region, obj);
+  JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
+  JSONDecoder::decode_json("user_quota", user_quota, obj);
+}
+
 void RGWZoneGroupMap::dump(Formatter *f) const
 {
   encode_json("zonegroups", zonegroups, f);
index 14070df94883b2a87dc557627efe9e8f449163a3..5d30877b9e49b417d8cd52ff917b2aded525bed1 100644 (file)
@@ -1361,7 +1361,6 @@ int RGWPeriodMap::update(const RGWZoneGroup& zonegroup)
   return 0;
 }
 
-
 int RGWZoneGroupMap::read(CephContext *cct, RGWRados *store) {
 
   RGWPeriod period;
@@ -1379,7 +1378,27 @@ int RGWZoneGroupMap::read(CephContext *cct, RGWRados *store) {
 
   return 0;
 }
-  
+
+void RGWRegionMap::encode(bufferlist& bl) const {
+  ENCODE_START( 3, 1, bl);
+  ::encode(regions, bl);
+  ::encode(master_region, bl);
+  ::encode(bucket_quota, bl);
+  ::encode(user_quota, bl);
+  ENCODE_FINISH(bl);
+}
+
+void RGWRegionMap::decode(bufferlist::iterator& bl) {
+  DECODE_START(3, bl);
+  ::decode(regions, bl);
+  ::decode(master_region, bl);
+  if (struct_v >= 2)
+    ::decode(bucket_quota, bl);
+  if (struct_v >= 3)
+    ::decode(user_quota, bl);
+  DECODE_FINISH(bl);
+}
+
 void RGWZoneGroupMap::encode(bufferlist& bl) const {
   ENCODE_START( 3, 1, bl);
   ::encode(zonegroups, bl);
@@ -2950,6 +2969,7 @@ int RGWRados::convert_regionmap()
  */
 int RGWRados::replace_region_with_zonegroup()
 {
   /* copy default region */
   /* convert default region to default zonegroup */
   string default_oid = cct->_conf->rgw_default_region_info_oid;
@@ -2977,7 +2997,6 @@ int RGWRados::replace_region_with_zonegroup()
     lderr(cct) << "failed to list regions: ret "<< ret << " " << cpp_strerror(-ret) << dendl;
     return ret;
   }
-
   list<string>::iterator iter;
   /* create zonegroups */
   for (iter = regions.begin(); iter != regions.end(); ++iter)
index f2c58e0a2875ae938fe71f8340413cb7908c890b..adf9a1031cc35946fca2987a63f4591986cb648d 100644 (file)
@@ -1199,6 +1199,23 @@ struct RGWPeriodConfig
 WRITE_CLASS_ENCODER(RGWPeriodConfig)
 
 /* for backward comaptability */
+struct RGWRegionMap {
+
+  map<string, RGWZoneGroup> regions;
+
+  string master_region;
+
+  RGWQuotaInfo bucket_quota;
+  RGWQuotaInfo user_quota;
+
+  void encode(bufferlist& bl) const;
+  void decode(bufferlist::iterator& bl);
+
+  void dump(Formatter *f) const;
+  void decode_json(JSONObj *obj);
+};
+WRITE_CLASS_ENCODER(RGWRegionMap)
+
 struct RGWZoneGroupMap {
 
   map<string, RGWZoneGroup> zonegroups;
index 0c25e0c6ca219e8a79752b61254d9840659e8899..321125624f854a24df169775330eedf1750fe3b3 100644 (file)
@@ -24,7 +24,7 @@
 #define dout_subsys ceph_subsys_rgw
 
 void RGWOp_ZoneGroupMap_Get::execute() {
-  http_ret = zone_group_map.read(g_ceph_context, store);
+  http_ret = zonegroup_map.read(g_ceph_context, store);
   if (http_ret < 0) {
     dout(5) << "failed to read zone_group map" << dendl;
   }
@@ -37,7 +37,27 @@ void RGWOp_ZoneGroupMap_Get::send_response() {
 
   if (http_ret < 0)
     return;
-  
-  encode_json("region-map", zone_group_map, s->formatter);
-  flusher.flush(); 
+
+  if (old_format) {
+    RGWRegionMap region_map;
+    region_map.regions = zonegroup_map.zonegroups;
+    region_map.master_region = zonegroup_map.master_zonegroup;
+    region_map.bucket_quota = zonegroup_map.bucket_quota;
+    region_map.user_quota = zonegroup_map.user_quota;    
+    encode_json("region-map", region_map, s->formatter);
+  } else {
+    encode_json("zonegroup-map", zonegroup_map, s->formatter);
+  }
+  flusher.flush();
+}
+
+RGWOp* RGWHandler_Config::op_get() {
+  bool exists;
+  string type = s->info.args.get("type", &exists);
+
+  if (type.compare("zonegroup-map") == 0) {
+    return new RGWOp_ZoneGroupMap_Get(false);
+  } else {
+    return new RGWOp_ZoneGroupMap_Get(true);
+  }
 }
index 8b22d240b214b6fb745604ea78f214e38491324a..d4be7c0a6c899ccc8a828a94fdb3ee08ef4c0713 100644 (file)
 #define CEPH_RGW_REST_CONFIG_H
 
 class RGWOp_ZoneGroupMap_Get : public RGWRESTOp {
-  RGWZoneGroupMap zone_group_map;
+  RGWZoneGroupMap zonegroup_map;
+  bool old_format;
 public:
-  RGWOp_ZoneGroupMap_Get() {}
+  RGWOp_ZoneGroupMap_Get(bool _old_format) : old_format(_old_format) {}
   ~RGWOp_ZoneGroupMap_Get() {}
 
   int verify_permission() {
@@ -26,13 +27,17 @@ public:
   void execute();
   virtual void send_response();
   virtual const string name() {
-    return "get_region_map";
+    if (old_format) {
+      return "get_region_map";
+    } else {
+      return "get_zonegroup_map";
+    }
   }
 };
 
 class RGWHandler_Config : public RGWHandler_Auth_S3 {
 protected:
-  RGWOp *op_get() { return new RGWOp_ZoneGroupMap_Get; }
+  RGWOp *op_get();
 
   int read_permissions(RGWOp*) {
     return 0;