From 5cc6ec21c15846f52471a7363f4bd69e19e790e7 Mon Sep 17 00:00:00 2001 From: Abhishek Lekshmanan Date: Mon, 7 May 2018 15:01:39 +0200 Subject: [PATCH] rgw: es: introduce new classes for storing ES version info Getting the basic information from elasticsearch, while we're only currently interested in elasic search version, other data such as the ES cluster name etc may be useful in the future as well. Signed-off-by: Abhishek Lekshmanan --- src/rgw/rgw_sync_module_es.cc | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/rgw/rgw_sync_module_es.cc b/src/rgw/rgw_sync_module_es.cc index f81dc62102a..db64662c77f 100644 --- a/src/rgw/rgw_sync_module_es.cc +++ b/src/rgw/rgw_sync_module_es.cc @@ -109,6 +109,55 @@ public: #define ES_NUM_SHARDS_DEFAULT 16 #define ES_NUM_REPLICAS_DEFAULT 1 +struct ESVersion { + int major_ver; + int minor_ver; + + ESVersion(int _major, int _minor): major_ver(_major), minor_ver(_minor) {} + ESVersion(): major_ver(0), minor_ver(0) {} + + void from_str(const char* s) { + sscanf(s, "%d.%d", &major_ver, &minor_ver); + } + + std::string to_str() const { + return std::to_string(major_ver) + "." + std::to_string(minor_ver); + } + + void decode_json(JSONObj *obj); +}; + +bool operator >= (const ESVersion& v1, const ESVersion& v2) +{ + if (v1.major_ver == v2.major_ver) + return v1.minor_ver >= v2.minor_ver; + + return v1.major_ver > v2.major_ver; +} + +struct ESInfo { + std::string name; + std::string cluster_name; + std::string cluster_uuid; + ESVersion version; + + void decode_json(JSONObj *obj); +}; + +void ESInfo::decode_json(JSONObj *obj) +{ + JSONDecoder::decode_json("name", name, obj); + JSONDecoder::decode_json("cluster_name", cluster_name, obj); + JSONDecoder::decode_json("cluster_uuid", cluster_uuid, obj); + JSONDecoder::decode_json("version", version, obj); +} + +void ESVersion::decode_json(JSONObj *obj) +{ + std::string s; + JSONDecoder::decode_json("number", s, obj); + this->from_str(s.c_str()); +} struct ElasticConfig { uint64_t sync_instance{0}; -- 2.39.5