提交 89213da3 authored 作者: blu's avatar blu

big refacting of communitation architect

上级 856c3e81
...@@ -141,23 +141,21 @@ private: ...@@ -141,23 +141,21 @@ private:
} }
} }
// update evmgr config // update evmgr config
json evmgrData;
evmgrData["data"] = data;
this->configMap[k] = k; this->configMap[k] = k;
//save //save
iret = LVDB::setLocalConfig(evmgrData, k); iret = LVDB::setLocalConfig(v, k);
if(iret < 0) { if(iret < 0) {
string msg = "failed to save config " + k + " -> " + evmgrData.dump(4); string msg = "failed to save config " + k + " -> " + v.dump(4);
spdlog::error(msg); spdlog::error(msg);
ret["code"] = iret; ret["code"] = iret;
ret["msg"] = msg; ret["msg"] = msg;
} }
// update in memory peerData // update in memory peerData
if(this->peerData["config"].count(k) != 0) { if(this->peerData["config"].count(k) != 0) {
json diff = json::diff(this->peerData["config"][k], v); json diff = json::diff(this->peerData["config"][k], v);
spdlog::info("evcloudsvc peer {} config diff:\n{}", k, diff.dump(4)); spdlog::info("evcloudsvc peer {} config diff:\n{}\n\norigin:\n{}\n\n\nnew:\n{}", k, diff.dump(4), this->peerData["config"][k].dump(4), v.dump(4));
}else{ }else{
this->peerData["config"][k] = v; this->peerData["config"][k] = v;
} }
...@@ -355,70 +353,6 @@ public: ...@@ -355,70 +353,6 @@ public:
} }
} }
// svr.Post("/register", [this](const Request& req, Response& res){
// json ret;
// try{
// string sn = req.get_param_value("sn");
// string module = req.get_param_value("module");
// bool force = (req.get_param_value("force") == "true") ? true: false;
// if(sn.empty()||module.empty()){
// throw StrException("no para sn/module");
// }
// auto cfg = json::parse(req.body);
// string key, modname;
// if(module == "evmgr") {
// key = sn;
// // trigger exception
// (void)cfg.at("data").at(key);
// }else {
// if(modname == "evml") {
// string
// modname = "evml:" + module.substr(4, module.size());
// }else{
// modname = module;
// }
// modname = sn + ":" + modname;
// if(this->configMap.count(modname) == 0){
// spdlog::info("evcloudsvc no such edge module registred: {}, create new entry", key);
// ret = this->config(cfg);
// if(ret["code"] == 0) {
// }else{
// spdlog::error("failed to config: {}", ret.dump(4));
// }
// }else{
// key = configMap[modname];
// }
// }
// if(!key.empty()){
// // TODO: calc md5
// spdlog::info("evcloudsvc key: {}", key);
// int r;
// ret["code"] = 0;
// ret["msg"] = "diff";
// json data;
// r = LVDB::getLocalConfig(data, key);
// if(r < 0||force) {
// spdlog::error("failed to get localconfig or force to updaste. create new");
// ret = this->config(cfg);
// }else{
// json diff = json::diff(cfg, data);
// spdlog::info("evcloudsvc diff: {}", diff.dump(4));
// ret["data"] = diff;
// }
// }
// }catch(exception &e) {
// ret.clear();
// ret["code"] = -1;
// ret["msg"] = e.what();
// }
// res.set_content(ret.dump(), "text/json");
// });
svr.Get("/config", [this](const Request& req, Response& res) { svr.Get("/config", [this](const Request& req, Response& res) {
json ret; json ret;
ret["code"] = 0; ret["code"] = 0;
......
...@@ -38,7 +38,7 @@ class EvDaemon{ ...@@ -38,7 +38,7 @@ class EvDaemon{
thread::id thIdMain; thread::id thIdMain;
thread thRouter; thread thRouter;
thread thCloud; thread thCloud;
bool bReload = true; bool bReload = false;
bool bBootstrap = true; bool bBootstrap = true;
// peerData["status"]; // peerData["status"];
// peerData["pids"]; // peerData["pids"];
...@@ -196,7 +196,7 @@ class EvDaemon{ ...@@ -196,7 +196,7 @@ class EvDaemon{
thMon = thread([this](){ thMon = thread([this](){
while(true) { while(true) {
if(this->bReload) { if(this->bReload) {
cleanupSubSystems(); //cleanupSubSystems();
int ret; int ret;
if(bBootstrap){ if(bBootstrap){
ret = reloadCfg("ALL"); ret = reloadCfg("ALL");
...@@ -211,7 +211,7 @@ class EvDaemon{ ...@@ -211,7 +211,7 @@ class EvDaemon{
} }
} }
this_thread::sleep_for(chrono::seconds(30)); this_thread::sleep_for(chrono::seconds(5));
} }
}); });
...@@ -433,8 +433,15 @@ class EvDaemon{ ...@@ -433,8 +433,15 @@ class EvDaemon{
if(peerId == "evcloudsvc") { if(peerId == "evcloudsvc") {
// its configuration message // its configuration message
if(meta == EV_MSG_META_CONFIG) { if(meta == EV_MSG_META_CONFIG) {
if(data.size() == 0) {
spdlog::error("evdaemon {} received invalid empty config");
}else{
json diff = json::diff(config, data); json diff = json::diff(config, data);
// TODO: calc diff
spdlog::info("evdaemon {} received cloud config diff:\n{}\nfull\n{}", devSn, diff.dump(4), data.dump(4)); spdlog::info("evdaemon {} received cloud config diff:\n{}\nfull\n{}", devSn, diff.dump(4), data.dump(4));
bReload = true;
}
} }
}else{ }else{
// from peer // from peer
...@@ -452,7 +459,7 @@ class EvDaemon{ ...@@ -452,7 +459,7 @@ class EvDaemon{
public: public:
void run(){ void run(){
//setupSubSystems(); setupSubSystems();
// get config // get config
svr.Get("/info", [this](const Request& req, Response& res){ svr.Get("/info", [this](const Request& req, Response& res){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论