diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-02-11 16:41:28 -0800 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-03-22 11:23:57 -0700 |
commit | 75c413c3e9e52006137faaf2f4ccf56e306e0c80 (patch) | |
tree | 307f594ed727f17f452204ece1dbaab083cef2ed | |
parent | 0f8199fc8ce19cb44c51368e07c0b143af92b6da (diff) | |
download | ceph-75c413c3e9e52006137faaf2f4ccf56e306e0c80.tar.gz |
rgw: define region/zone data structures
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/rgw/rgw_rados.cc | 68 | ||||
-rw-r--r-- | src/rgw/rgw_rados.h | 73 |
2 files changed, 141 insertions, 0 deletions
diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index cf05dbe6220..96f6b3b255c 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -148,6 +148,74 @@ int RGWZoneParams::store_info(CephContext *cct, RGWRados *store) return ret; } +void RGWZone::dump(Formatter *f) const +{ + f->dump_string("name", name); + f->open_array_section("endpoints"); + for (list<string>::const_iterator iter = endpoints.begin(); iter != endpoints.end(); ++iter) { + f->dump_string("endpoint", *iter); + } + f->close_section(); +} + +void RGWZone::decode_json(JSONObj *obj) +{ + JSONDecoder::decode_json("name", name, obj); + JSONDecoder::decode_json("endpoints", endpoints, obj); +} + +void RGWRegion::dump(Formatter *f) const +{ + f->dump_string("name", name); + f->open_array_section("endpoints"); + for (list<string>::const_iterator iter = endpoints.begin(); iter != endpoints.end(); ++iter) { + f->dump_string("endpoint", *iter); + } + f->close_section(); + f->dump_string("master_zone", master_zone); + f->open_array_section("zones"); + for (list<RGWZone>::const_iterator iter = zones.begin(); iter != zones.end(); ++iter) { + const RGWZone& zone = *iter; + f->open_object_section("zone"); + zone.dump(f); + f->close_section(); + } + f->close_section(); +} + +void RGWRegion::decode_json(JSONObj *obj) +{ + JSONDecoder::decode_json("name", name, obj); + JSONDecoder::decode_json("endpoints", endpoints, obj); + JSONDecoder::decode_json("master_zone", master_zone, obj); + JSONDecoder::decode_json("zones", zones, obj); +} + + +void RGWRegionMap::dump(Formatter *f) const +{ + f->open_array_section("regions"); + for (map<string, RGWRegion>::const_iterator iter = regions.begin(); iter != regions.end(); ++iter) { + const RGWRegion& region = iter->second; + f->open_object_section("region"); + region.dump(f); + f->close_section(); + } + f->close_section(); + f->dump_string("master_region", master_region); +} + +void RGWRegionMap::decode_json(JSONObj *obj) +{ + list<RGWRegion> regions_list; + JSONDecoder::decode_json("regions", regions_list, obj); + + for (list<RGWRegion>::iterator iter = regions_list.begin(); iter != regions_list.end(); ++iter) { + RGWRegion& region = *iter; + regions[region.name] = region; + } +} + void RGWObjManifest::append(RGWObjManifest& m) { map<uint64_t, RGWObjManifestPart>::iterator iter; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 30cd3a80dfc..82d648ad93a 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -288,6 +288,79 @@ struct RGWZoneParams { void decode_json(JSONObj *obj); }; WRITE_CLASS_ENCODER(RGWZoneParams); + +struct RGWZone { + string name; + list<string> endpoints; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(name, bl); + ::encode(endpoints, bl); + ENCODE_FINISH(bl); + } + + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(name, bl); + ::decode(endpoints, bl); + DECODE_FINISH(bl); + } + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); +}; +WRITE_CLASS_ENCODER(RGWZone); + +struct RGWRegion { + string name; + list<string> endpoints; + + string master_zone; + list<RGWZone> zones; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(endpoints, bl); + ::encode(master_zone, bl); + ::encode(zones, bl); + ENCODE_FINISH(bl); + } + + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(endpoints, bl); + ::decode(master_zone, bl); + ::decode(zones, bl); + DECODE_FINISH(bl); + } + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); +}; +WRITE_CLASS_ENCODER(RGWRegion); + +struct RGWRegionMap { + map<string, RGWRegion> regions; + + string master_region; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(regions, bl); + ENCODE_FINISH(bl); + } + + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(regions, bl); + DECODE_FINISH(bl); + } + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); +}; +WRITE_CLASS_ENCODER(RGWRegionMap); + + class RGWRados { |