提交 6ee36698 authored 作者: blu's avatar blu

big refacting of communitation architect

上级 be9df0e8
...@@ -81,16 +81,20 @@ class EvDaemon{ ...@@ -81,16 +81,20 @@ class EvDaemon{
// startup evmgr // startup evmgr
peerId = v["sn"].get<string>() + ":evmgr:0"; peerId = v["sn"].get<string>() + ":evmgr:0";
// offline // offline
this->peerData["status"][peerId] = 0;
this->peerData["config"][peerId] = v; this->peerData["config"][peerId] = v;
ret = zmqhelper::forkSubsystem(devSn, peerId, portRouter, pid); if(this->peerData["status"].count(peerId) == 0||this->peerData["status"][peerId] == 0) {
if(ret != 0) { this->peerData["status"][peerId] = 0;
spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId); ret = zmqhelper::forkSubsystem(devSn, peerId, portRouter, pid);
// TODO: clean up and reload config if(ret != 0) {
exit(1); spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId);
} // TODO: clean up and reload config
this->peerData["pids"][peerId] = pid; exit(1);
spdlog::info("evdaemon {} created subsystem {}", devSn, peerId); }
this->peerData["pids"][peerId] = pid;
spdlog::info("evdaemon {} created subsystem {}", devSn, peerId);
}else{
// TODO:
}
} }
// startup other submodules // startup other submodules
...@@ -110,16 +114,21 @@ class EvDaemon{ ...@@ -110,16 +114,21 @@ class EvDaemon{
// TODO: cleanup and reload // TODO: cleanup and reload
} }
this->peerData["status"][peerId] = 0;
this->peerData["config"][peerId] = v; this->peerData["config"][peerId] = v;
ret = zmqhelper::forkSubsystem(devSn, peerId, portRouter, pid);
if(ret != 0) { if(this->peerData["status"].count(peerId) == 0||this->peerData["status"][peerId] == 0) {
spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId); this->peerData["status"][peerId] = 0;
// TODO: cleanup and reload ret = zmqhelper::forkSubsystem(devSn, peerId, portRouter, pid);
exit(1); if(ret != 0) {
spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId);
// TODO: cleanup and reload
exit(1);
}
this->peerData["pids"][peerId] = pid;
spdlog::info("evdaemon {} created subsystem {}", devSn, peerId);
}else{
// TODO:
} }
this->peerData["pids"][peerId] = pid;
spdlog::info("evdaemon {} created subsystem {}", devSn, peerId);
} }
} }
} }
...@@ -139,8 +148,10 @@ class EvDaemon{ ...@@ -139,8 +148,10 @@ class EvDaemon{
int ret = reloadCfg(); int ret = reloadCfg();
if(ret != 0) { if(ret != 0) {
spdlog::error("evdaemon {} failed to setup subsystems, please check log for more info", this->devSn); spdlog::error("evdaemon {} failed to setup subsystems, please check log for more info", this->devSn);
this_thread::sleep_for(chrono::seconds(5));
} }
this_thread::sleep_for(chrono::seconds(5));
break; break;
} }
}); });
...@@ -163,12 +174,12 @@ class EvDaemon{ ...@@ -163,12 +174,12 @@ class EvDaemon{
return -1; return -1;
} }
if(peerData["status"].count(selfId) == 0) { // if(peerData["status"].count(selfId) == 0) {
spdlog::warn("evdaemon {} unkown module with id: {}, peerStats {}", devSn, selfId, peerData["status"].dump(4)); // spdlog::warn("evdaemon {} unkown module with id: {}, peerStats {}", devSn, selfId, peerData["status"].dump(4));
return -1; // return -1;
} // }
if(peerData["status"][selfId] == 0) { if(peerData["status"].count(selfId) == 0 || peerData["status"][selfId] == 0) {
peerData["status"][selfId] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count(); peerData["status"][selfId] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
spdlog::info("evdaemon {} peer connected: {}", devSn, selfId); spdlog::info("evdaemon {} peer connected: {}", devSn, selfId);
eventConn = true; eventConn = true;
...@@ -344,8 +355,12 @@ class EvDaemon{ ...@@ -344,8 +355,12 @@ class EvDaemon{
res.set_content(ret.dump(), "text/json"); res.set_content(ret.dump(), "text/json");
}); });
svr.Post("/reset", [](const Request& req, Response& res){ svr.Get("/reset", [](const Request& req, Response& res){
json ret;
ret["code"] = 0;
ret["msg"] = "resetting ...";
res.set_content(ret.dump(), "text/json");
kill(getpid(), SIGTERM);
}); });
svr.listen("0.0.0.0", 8088); svr.listen("0.0.0.0", 8088);
......
...@@ -259,6 +259,10 @@ protected: ...@@ -259,6 +259,10 @@ protected:
bStopSig = true; bStopSig = true;
break; break;
} }
if(1 == getppid()) {
spdlog::error("evmgr {} exit since evdaemon is dead", devSn);
exit(1);
}
auto body = z_recv_multiple(pRouter,false); auto body = z_recv_multiple(pRouter,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evmgr {} failed to receive multiple msg: {}", devSn, zmq_strerror(zmq_errno())); spdlog::error("evmgr {} failed to receive multiple msg: {}", devSn, zmq_strerror(zmq_errno()));
......
...@@ -51,6 +51,12 @@ json registry(json &conf, string sn, string module) { ...@@ -51,6 +51,12 @@ json registry(json &conf, string sn, string module) {
return ret; return ret;
} }
#define EVCLOUD_REQ_E_CONN -2
#define EVCLOUD_REQ_E_DATA -3
#define EVCLOUD_REQ_E_PARAM -4
#define EVCLOUD_REQ_E_ABORT -5
#define EVCLOUD_REQ_E_NONE 0
/// req config /// req config
json reqConfig(json &info){ json reqConfig(json &info){
json ret; json ret;
...@@ -61,7 +67,7 @@ json reqConfig(json &info){ ...@@ -61,7 +67,7 @@ json reqConfig(json &info){
string sn = info.at("sn").get<string>(); string sn = info.at("sn").get<string>();
if(uri.Host.empty()||uri.Port.empty()||uri.Protocol.find("http") == string::npos) { if(uri.Host.empty()||uri.Port.empty()||uri.Protocol.find("http") == string::npos) {
string msg = string(__FILE__) +":" + to_string(__LINE__) + ": request cloud configuration error. invalid api-cloud in info: " + api; string msg = string(__FILE__) +":" + to_string(__LINE__) + ": request cloud configuration error. invalid api-cloud in info: " + api;
ret["code"] = 1; ret["code"] = EVCLOUD_REQ_E_PARAM;
ret["msg"] = msg; ret["msg"] = msg;
spdlog::error(msg); spdlog::error(msg);
return ret; return ret;
...@@ -76,7 +82,7 @@ json reqConfig(json &info){ ...@@ -76,7 +82,7 @@ json reqConfig(json &info){
const char *msg = NULL; const char *msg = NULL;
if(res == nullptr) { if(res == nullptr) {
msg = (string("error to connect to server: ") + api + "/config").c_str(); msg = (string("error to connect to server: ") + api + "/config").c_str();
ret["code"] = -2; ret["code"] = EVCLOUD_REQ_E_CONN;
}else{ }else{
msg = httplib::detail::status_message(res->status); msg = httplib::detail::status_message(res->status);
ret["code"] = res->status; ret["code"] = res->status;
...@@ -88,7 +94,7 @@ json reqConfig(json &info){ ...@@ -88,7 +94,7 @@ json reqConfig(json &info){
ret = json::parse(res->body); ret = json::parse(res->body);
} }
}catch(exception &e) { }catch(exception &e) {
ret["code"] = -1; ret["code"] = EVCLOUD_REQ_E_DATA;
string msg = string(__FILE__) + ":" + to_string(__LINE__) + string(": registry exception - ") + e.what(); string msg = string(__FILE__) + ":" + to_string(__LINE__) + string(": registry exception - ") + e.what();
ret["msg"] = msg; ret["msg"] = msg;
spdlog::error(msg); spdlog::error(msg);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论