Skip to content

Commit

Permalink
rgw: es: introduce new classes for storing ES version info
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
theanalyst authored and yehudasa committed Jan 30, 2019
1 parent 7d97444 commit 48a91a4
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/rgw/rgw_sync_module_es.cc
Expand Up @@ -103,6 +103,57 @@ class ItemList {
#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};
string id;
Expand Down

0 comments on commit 48a91a4

Please sign in to comment.