提交 0ea4290c authored 作者: blu's avatar blu

big refacting of communitation architect

上级 d284cba5
...@@ -400,7 +400,8 @@ private: ...@@ -400,7 +400,8 @@ private:
ret["code"] = 1; ret["code"] = 1;
string msg = "no such sn: " + sn; string msg = "no such sn: " + sn;
ret["msg"] = msg; ret["msg"] = msg;
spdlog::warn("evcloudsvc no config for sn: {}", sn); spdlog::warn("evcloudsvc no config for sn: {}", sn);
// TODO: append to retry queue
} }
}catch(exception &e) { }catch(exception &e) {
string msg = "evcloudsvc exception in file" + string(__FILE__) + ":" + to_string(__LINE__) + " for: " + e.what(); string msg = "evcloudsvc exception in file" + string(__FILE__) + ":" + to_string(__LINE__) + " for: " + e.what();
......
...@@ -67,7 +67,7 @@ class EvDaemon{ ...@@ -67,7 +67,7 @@ class EvDaemon{
/// tracking sub-systems: evmgr, evpuller, evpusher, evml*, evslicer etc. /// tracking sub-systems: evmgr, evpuller, evpusher, evml*, evslicer etc.
json mapSubSystems; json mapSubSystems;
int reloadCfg(string subModGid) { int reloadCfg(string subModGid = "") {
int bootType = 0; int bootType = 0;
if(subModGid == "ALL") { if(subModGid == "ALL") {
bootType = 1; bootType = 1;
...@@ -77,6 +77,8 @@ class EvDaemon{ ...@@ -77,6 +77,8 @@ class EvDaemon{
bootType = 3; bootType = 3;
} }
spdlog::info("evadmon {} reloading config: {}", devSn, this->config.dump());
int ret = LVDB::getSn(this->info); int ret = LVDB::getSn(this->info);
if(ret < 0) { if(ret < 0) {
spdlog::error("evdaemon {} failed to get info", this->devSn); spdlog::error("evdaemon {} failed to get info", this->devSn);
...@@ -116,7 +118,6 @@ class EvDaemon{ ...@@ -116,7 +118,6 @@ class EvDaemon{
} }
// startup other submodules // startup other submodules
spdlog::info("dump: {}", v.dump());
json &ipcs = v["ipcs"]; json &ipcs = v["ipcs"];
for(auto &ipc : ipcs) { for(auto &ipc : ipcs) {
json &modules = ipc["modules"]; json &modules = ipc["modules"];
...@@ -135,7 +136,6 @@ class EvDaemon{ ...@@ -135,7 +136,6 @@ class EvDaemon{
} }
this->peerData["config"][peerId] = v; this->peerData["config"][peerId] = v;
if(this->peerData["status"].count(peerId) == 0||this->peerData["status"][peerId] == 0) { if(this->peerData["status"].count(peerId) == 0||this->peerData["status"][peerId] == 0) {
this->peerData["status"][peerId] = 0; this->peerData["status"][peerId] = 0;
if(bootType == 1 || (bootType == 3 && subModGid == peerId)){ if(bootType == 1 || (bootType == 3 && subModGid == peerId)){
...@@ -179,7 +179,6 @@ class EvDaemon{ ...@@ -179,7 +179,6 @@ class EvDaemon{
if(this->peerData["pids"].count(k) != 0) { if(this->peerData["pids"].count(k) != 0) {
this->peerData["pids"].erase(k); this->peerData["pids"].erase(k);
} }
} }
} }
...@@ -187,14 +186,18 @@ class EvDaemon{ ...@@ -187,14 +186,18 @@ class EvDaemon{
// check status and startup // check status and startup
int ret = 0; int ret = 0;
vector<string> tmp; vector<string> tmp;
string info;
int cnt = 0;
for(auto &[k,v]: this->peerData["config"].items()) { for(auto &[k,v]: this->peerData["config"].items()) {
spdlog::info("evdaemon {} submodule {}, config {}", devSn, k, v.dump());
if(this->peerData["status"].count(k) == 0 || this->peerData["status"][k] == 0) { if(this->peerData["status"].count(k) == 0 || this->peerData["status"][k] == 0) {
tmp.push_back(k); tmp.push_back(k);
info += (cnt == 0? "" : string(", ")) + k;
} }
cnt++;
} }
spdlog::info("evdaemon {} will start following subsystems: {}", devSn, info);
// //
for(string &e : tmp) { for(string &e : tmp) {
pid_t pid = 0; pid_t pid = 0;
ret = zmqhelper::forkSubsystem(devSn, e, portRouter, pid); ret = zmqhelper::forkSubsystem(devSn, e, portRouter, pid);
...@@ -210,39 +213,6 @@ class EvDaemon{ ...@@ -210,39 +213,6 @@ class EvDaemon{
return ret; return ret;
} }
void setupSubsystems() {
thMon = thread([this](){
int ret = 0;
while(true) {
if(this->bReload) {
//cleanupSubSystems();
ret = reloadCfg("");
if(ret != 0) {
//TODO
spdlog::error("evdaemon {} failed to parse new configuration, check prevous log for details", devSn);
}else{
bReload = false;
}
if(this->bColdStart) {
// TODO:
this->bColdStart = false;
// for peers to connect
this_thread::sleep_for(chrono::seconds(5));
}
if(this->bBootstrap) {
startSubSystems();
}
}
this_thread::sleep_for(chrono::seconds(5));
}
});
thMon.detach();
}
int handleEdgeMsg(vector<vector<uint8_t> > &body) int handleEdgeMsg(vector<vector<uint8_t> > &body)
{ {
int ret = 0; int ret = 0;
...@@ -416,22 +386,24 @@ class EvDaemon{ ...@@ -416,22 +386,24 @@ class EvDaemon{
spdlog::error("evdaemon {} received invalid empty config", devSn); spdlog::error("evdaemon {} received invalid empty config", devSn);
}else{ }else{
this->deltaCfg = json::diff(this->config, data); this->deltaCfg = json::diff(this->config, data);
if(this->deltaCfg.size() != 0) { spdlog::info("evdaemon {} received cloud config diff: {}\nnew: {}", devSn, this->deltaCfg.dump(4), data.dump());
if(this->deltaCfg.size() != 0 || this->bColdStart) {
this->config = data; this->config = data;
this->bReload = true; ret = reloadCfg();
spdlog::info("evdaemon {} received cloud config diff:\n{}\nnew\n{}", devSn, this->deltaCfg.dump(4), data.dump()); if(ret != 0) {
spdlog::error("evdameon {} failed to parse new config: {}", devSn, data.dump());
return ret;
}
ret = LVDB::setLocalConfig(data, "", EV_FILE_LVDB_DAEMON); ret = LVDB::setLocalConfig(data, "", EV_FILE_LVDB_DAEMON);
if(ret < 0) { if(ret != 0) {
spdlog::error("evdameon {} failed to save new config to local db: {}", devSn, data.dump()); spdlog::error("evdameon {} failed to save new config to local db: {}", devSn, data.dump());
return ret;
} }
// TODO: detailed diff on submodules this->bColdStart = false;
}else{ }else{
if(this->bColdStart) {
startSubSystems();
}else{
spdlog::info("evdaemon {} received same configuration and ignored: {}", devSn, data.dump());
}
} }
startSubSystems();
} }
} }
}else{ }else{
...@@ -449,9 +421,7 @@ class EvDaemon{ ...@@ -449,9 +421,7 @@ class EvDaemon{
protected: protected:
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){
LVDB::getSn(this->info); LVDB::getSn(this->info);
...@@ -554,9 +524,10 @@ class EvDaemon{ ...@@ -554,9 +524,10 @@ class EvDaemon{
json cfg; json cfg;
ret = LVDB::getLocalConfig(cfg, "", EV_FILE_LVDB_DAEMON); ret = LVDB::getLocalConfig(cfg, "", EV_FILE_LVDB_DAEMON);
if(ret < 0) { if(ret < 0) {
spdlog::info("evdameon {} no local config", devSn, cfg.dump()); spdlog::info("evdaemon {} no local config", devSn);
}else{ }else{
this->config = cfg; this->config = cfg;
spdlog::info("evdaemon {} local config: {}", devSn, cfg.dump());
} }
// zmq router port // zmq router port
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论