forked from vitalif/vitastor
Add a parameter to pass the initial config to client
parent
c573bc6bb3
commit
2187d06eac
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class cluster_client_t
|
|||
std::set<cluster_op_t*> 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:
|
||||
|
|
|
@ -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()];
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
25
osd.cpp
25
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue