From 2187d06eac103e4d93f10e2479313d0ed0ee8640 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 6 Jun 2020 16:32:35 +0300 Subject: [PATCH] Add a parameter to pass the initial config to client --- cluster_client.cpp | 6 ++++-- cluster_client.h | 2 +- etcd_state_client.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++ etcd_state_client.h | 1 + osd.cpp | 25 ++--------------------- osd_cluster.cpp | 10 +++++++-- 6 files changed, 63 insertions(+), 28 deletions(-) diff --git a/cluster_client.cpp b/cluster_client.cpp index 8024855d..3f4e70fb 100644 --- a/cluster_client.cpp +++ b/cluster_client.cpp @@ -1,6 +1,6 @@ #include "cluster_client.h" -cluster_client_t::cluster_client_t(ring_loop_t *ringloop, timerfd_manager_t *tfd) +cluster_client_t::cluster_client_t(ring_loop_t *ringloop, timerfd_manager_t *tfd, json11::Json & config) { this->ringloop = ringloop; this->tfd = tfd; @@ -18,11 +18,13 @@ cluster_client_t::cluster_client_t(ring_loop_t *ringloop, timerfd_manager_t *tfd }; st_cli.tfd = tfd; - st_cli.log_level = log_level; st_cli.on_load_config_hook = [this](json11::Json::object & cfg) { on_load_config_hook(cfg); }; st_cli.on_change_osd_state_hook = [this](uint64_t peer_osd) { on_change_osd_state_hook(peer_osd); }; st_cli.on_change_hook = [this](json11::Json::object & changes) { on_change_hook(changes); }; st_cli.on_load_pgs_hook = [this](bool success) { on_load_pgs_hook(success); }; + + log_level = config["log_level"].int64_value(); + st_cli.parse_config(config); st_cli.load_global_config(); } diff --git a/cluster_client.h b/cluster_client.h index a49c23e7..d423593c 100644 --- a/cluster_client.h +++ b/cluster_client.h @@ -60,7 +60,7 @@ class cluster_client_t std::set sent_ops, unsent_ops; public: - cluster_client_t(ring_loop_t *ringloop, timerfd_manager_t *tfd); + cluster_client_t(ring_loop_t *ringloop, timerfd_manager_t *tfd, json11::Json & config); void execute(cluster_op_t *op); protected: diff --git a/etcd_state_client.cpp b/etcd_state_client.cpp index 82f1cb91..c3788cf9 100644 --- a/etcd_state_client.cpp +++ b/etcd_state_client.cpp @@ -43,6 +43,53 @@ void etcd_state_client_t::etcd_call(std::string api, json11::Json payload, int t http_request_json(tfd, etcd_address, req, timeout, callback); } +void etcd_state_client_t::parse_config(json11::Json & config) +{ + this->etcd_addresses.clear(); + if (config["etcd_address"].is_string()) + { + std::string ea = config["etcd_address"].string_value(); + while (1) + { + int pos = ea.find(','); + std::string addr = pos >= 0 ? ea.substr(0, pos) : ea; + if (addr.length() > 0) + { + if (addr.find('/') < 0) + addr += "/v3"; + this->etcd_addresses.push_back(addr); + } + if (pos >= 0) + ea = ea.substr(pos+1); + else + break; + } + } + else if (config["etcd_address"].array_items().size()) + { + for (auto & ea: config["etcd_address"].array_items()) + { + std::string addr = ea.string_value(); + if (addr != "") + { + if (addr.find('/') < 0) + addr += "/v3"; + this->etcd_addresses.push_back(addr); + } + } + } + this->etcd_prefix = config["etcd_prefix"].string_value(); + if (this->etcd_prefix == "") + { + this->etcd_prefix = "/microceph"; + } + else if (this->etcd_prefix[0] != '/') + { + this->etcd_prefix = "/"+this->etcd_prefix; + } + this->log_level = config["log_level"].int64_value(); +} + void etcd_state_client_t::start_etcd_watcher() { std::string etcd_address = etcd_addresses[rand() % etcd_addresses.size()]; diff --git a/etcd_state_client.h b/etcd_state_client.h index 4d95e128..7140c805 100644 --- a/etcd_state_client.h +++ b/etcd_state_client.h @@ -57,4 +57,5 @@ struct etcd_state_client_t void load_global_config(); void load_pgs(); void parse_state(const std::string & key, const json11::Json & value); + void parse_config(json11::Json & config); }; diff --git a/osd.cpp b/osd.cpp index 093584a2..cf4e31be 100644 --- a/osd.cpp +++ b/osd.cpp @@ -73,29 +73,9 @@ osd_t::~osd_t() void osd_t::parse_config(blockstore_config_t & config) { - int pos; // Initial startup configuration - { - std::string ea = config["etcd_address"]; - while (1) - { - pos = ea.find(','); - std::string addr = pos >= 0 ? ea.substr(0, pos) : ea; - if (addr.length() > 0) - { - if (addr.find('/') < 0) - addr += "/v3"; - st_cli.etcd_addresses.push_back(addr); - } - if (pos >= 0) - ea = ea.substr(pos+1); - else - break; - } - } - st_cli.etcd_prefix = config["etcd_prefix"]; - if (st_cli.etcd_prefix == "") - st_cli.etcd_prefix = "/microceph"; + json11::Json json_config = json11::Json(config); + st_cli.parse_config(json_config); etcd_report_interval = strtoull(config["etcd_report_interval"].c_str(), NULL, 10); if (etcd_report_interval <= 0) etcd_report_interval = 30; @@ -148,7 +128,6 @@ void osd_t::parse_config(blockstore_config_t & config) if (!c_cli.peer_connect_timeout) c_cli.peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT; log_level = strtoull(config["log_level"].c_str(), NULL, 10); - st_cli.log_level = log_level; c_cli.log_level = log_level; } diff --git a/osd_cluster.cpp b/osd_cluster.cpp index 53a89de2..89682cf6 100644 --- a/osd_cluster.cpp +++ b/osd_cluster.cpp @@ -229,8 +229,14 @@ void osd_t::on_load_config_hook(json11::Json::object & global_config) { if (this->config.find(cfg_var.first) == this->config.end()) { - // FIXME Convert int to str - osd_config[cfg_var.first] = cfg_var.second.string_value(); + if (cfg_var.second.is_string()) + { + osd_config[cfg_var.first] = cfg_var.second.string_value(); + } + else + { + osd_config[cfg_var.first] = cfg_var.second.dump(); + } } } parse_config(osd_config);