]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: es: introduce new classes for storing ES version info
authorAbhishek Lekshmanan <abhishek@suse.com>
Mon, 7 May 2018 13:01:39 +0000 (15:01 +0200)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 25 Jan 2019 23:45:56 +0000 (15:45 -0800)
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 <abhishek@suse.com>
src/rgw/rgw_sync_module_es.cc

index f81dc62102af355c586609e58f82645ac15fa947..db64662c77fe344820bf9c7ad2f4c2bf4da2db05 100644 (file)
@@ -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};