提交 ca4bf3a1 authored 作者: blu's avatar blu

refactor of delta config

上级 72e9e59d
...@@ -290,20 +290,17 @@ json *findModuleConfig(string peerId, json &data) ...@@ -290,20 +290,17 @@ json *findModuleConfig(string peerId, json &data)
} }
/// return json key: gid; value: 0 - stop, 1 - start, 3 - restart /// return json key: gid; value: 0 - stop, 1 - start, 3 - restart
json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, string sn) json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, string sn) {
{ /// key: gid; value: 0 - stop, 1 - start, 3 - restart
json ret; json ret;
ret["code"] = 0; ret["code"] = 0;
ret["msg"] = "ok"; ret["msg"] = "ok";
ret["data"] = json(); ret["data"] = json();
bool hasError = false; bool hasError = false;
if(diff.size() == 0) { spdlog::info("matching {}, size:{}, type:{}", diff.dump(), diff.size(), diff.type_name());
return ret; try{
}
spdlog::info("getModulesOperFromConfDiff for sn {}. diff: {}, newConfig: {}", sn, diff.dump(), newConfig.dump());
try {
for(auto &d: diff) { for(auto &d: diff) {
spdlog::info("getModulesOperFromConfDiff path :{}", d.dump()); spdlog::info("d :{}, {}", d.dump(), d.size());
if(d.count("path") != 0) { if(d.count("path") != 0) {
string path_ = d["path"]; string path_ = d["path"];
bool matched = false; bool matched = false;
...@@ -313,72 +310,107 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -313,72 +310,107 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
set<string> oprations{"add", "replace", "remove"}; set<string> oprations{"add", "replace", "remove"};
set<string> pullerTag{"addr", "user", "password", "proto", "port" /*, "sn"*/}; set<string> pullerTag{"addr", "user", "password", "proto", "port" /*, "sn"*/};
string ipcRegStr = "/(\\w+)/ipcs/(\\d+)/(\\w+)"; // string ipcRegStr = "/(\\w+)/ipcs/(\\d+)/(\\w+)";
// std::smatch results;
// std::regex ipcRegex(ipcRegStr);
// if (std::regex_match(path_, results, ipcRegex)) {
// if (results.size() == 4) {
// matched = true;
// string mgrSn = results[1].str();
// int ipcIdx = stoi(results[2].str());
// string tag = results[3].str();
// if(pullerTag.find(tag) != pullerTag.end()) {
// // TODO: op = remove
// if(d["op"] == "add" || d["op"] == "replace") {
// // start
// auto ipc = newConfig[mgrSn]["ipcs"][ipcIdx];
// auto ipcOld = oldConfig[mgrSn]["ipcs"][ipcIdx];
// if(ipc.count("modules") == 0 || ipc["modules"].size() == 0 || ipc["moudles"].count("evpuller") ==0 || ipc["modules"]["evpuller"].size() == 0 ) {
// string msg = fmt::format("invalid config for ipc[{}]['modules']['evpuller']: {}", ipcIdx, newConfig.dump());
// spdlog::error(msg);
// ret["msg"] = msg;
// hasError = true;
// break;
// }else{
// auto &evpullers = ipc["module"]["evpuller"];
// int idx = 0;
// for(auto &puller:evpullers) {
// // strutil
// if(puller.count("sn") == 0) {
// string msg = fmt::format("invalid config for ipc[{}]['modules']['evpuller'][{}] no sn field: {}", ipcIdx, idx, newConfig.dump());
// ret["msg"] = msg;
// spdlog::error(msg);
// hasError = true;
// break;
// }
// if(puller["sn"].get<string>() != sn) {
// spdlog::debug("skip {} for expecting sn: {}", puller.dump(), sn);
// continue;
// }
// if(puller.count("iid") == 0 || puller.count("addr") == 0) {
// string msg = fmt::format("invliad config as of having no iid/addr/enabled field in ipc[{}]['modules']['evpuller'][{}]: {}", ipcIdx, idx, newConfig.dump());
// spdlog::error(msg);
// ret["msg"] = msg;
// hasError = true;
// break;
// }else{
// string gid = sn + ":evpuller:" + to_string(puller["iid"].get<int>());
// if(puller.count("enabled") == 0 || puller["enabled"].get<int>() == 0) {
// ret["data"][gid] = 0; // stop
// }else{
// ret["data"][gid] = 2;
// }
// }
// idx++;
// }
// }
// }
// }
// }
// }
// // else{
// // spdlog::info("no match for ipc", path_);
// // }
// one ipc
if(!matched && !hasError) {
// /PSBV7GKN/ipcs/0"
// {"addr":"172.31.0.129","modules":{"evml":[{"area":200,"enabled":1,"entropy":0.3,"iid":1,"post":30,"pre":3,"sn":"PSBV7GKN","thresh":30,"type":"motion"}],"evpuller":[{"addr":"127.0.0.1","enabled":1,"iid":1,"port-pub":5556,"sn":"PSBV7GKN"}],"evpusher":[{"enabled":0,"iid":1,"password":"","sn":"PSBV7GKN","token":"","urlDest":"rtsp://40.73.41.176/PSBV7GKN","user":""}],"evslicer":[{"enabled":1,"iid":1,"path":"slices","sn":"PSBV7GKN","video-server-addr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}
string clusterRegStr = "/(\\w+)/ipcs/(\\d+).*";
std::regex clusterRegex(clusterRegStr);
std::smatch results; std::smatch results;
std::regex ipcRegex(ipcRegStr); if (std::regex_match(path_, results, clusterRegex)) {
if (std::regex_match(path_, results, ipcRegex)) { if (results.size() == 3) {
if (results.size() == 4) {
matched = true; matched = true;
string mgrSn = results[1].str(); string mgrSn = results[1].str();
int ipcIdx = stoi(results[2].str()); int ipcIdx = stoi(results[2].str());
string tag = results[3].str(); json mgr;
if(pullerTag.find(tag) != pullerTag.end()) { if(d["op"] == "remove"){
// TODO: op = remove mgr[mgrSn] = oldConfig[mgrSn];
if(d["op"] == "add" || d["op"] == "replace") { }else{
// start mgr[mgrSn] = newConfig[mgrSn];
auto ipc = newConfig[mgrSn]["ipcs"][ipcIdx];
auto ipcOld = oldConfig[mgrSn]["ipcs"][ipcIdx];
if(ipc.count("modules") == 0 || ipc["modules"].size() == 0 || ipc["moudles"].count("evpuller") ==0 || ipc["modules"]["evpuller"].size() == 0 ) {
string msg = fmt::format("invalid config for ipc[{}]['modules']['evpuller']: {}", ipcIdx, newConfig.dump());
spdlog::error(msg);
ret["msg"] = msg;
hasError = true;
break;
}
else {
auto &evpullers = ipc["module"]["evpuller"];
int idx = 0;
for(auto &puller:evpullers) {
// strutil
if(puller.count("sn") == 0) {
string msg = fmt::format("invalid config for ipc[{}]['modules']['evpuller'][{}] no sn field: {}", ipcIdx, idx, newConfig.dump());
ret["msg"] = msg;
spdlog::error(msg);
hasError = true;
break;
}
if(puller["sn"].get<string>() != sn) {
spdlog::debug("skip {} for expecting sn: {}", puller.dump(), sn);
continue;
} }
if(puller.count("iid") == 0 || puller.count("addr") == 0) { json jret = cfgutils::getModuleGidsFromCfg(sn, mgr, "getModulesOperFromConfDiff", ipcIdx);
string msg = fmt::format("invliad config as of having no iid/addr/enabled field in ipc[{}]['modules']['evpuller'][{}]: {}", ipcIdx, idx, newConfig.dump()); spdlog::info("jret: {}", jret.dump());
spdlog::error(msg); if(jret["code"] != 0) {
ret["msg"] = msg; ret["msg"] = jret["msg"];
hasError = true; hasError = true;
break; break;
} }else{
else { for(auto &k: jret["data"]) {
string gid = sn + ":evpuller:" + to_string(puller["iid"].get<int>()); if(d["op"] == "remove"){
if(puller.count("enabled") == 0 || puller["enabled"].get<int>() == 0) { ret["data"][string(k)] = 0;
ret["data"][gid] = 0; // stop }else{
} ret["data"][string(k)] = 2;
else {
ret["data"][gid] = 2;
}
}
idx++;
} }
} }
} }
} }
} }
} }
// else{
// spdlog::info("no match for ipc", path_);
// }
// match module config // match module config
if(!matched && !hasError) { if(!matched && !hasError) {
...@@ -403,16 +435,14 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -403,16 +435,14 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
ret["msg"] = msg; ret["msg"] = msg;
hasError = true; hasError = true;
break; break;
} }else{
else {
if(modName == "evml") { if(modName == "evml") {
if(newMod.count("type") == 0) { if(newMod.count("type") == 0) {
string msg = fmt::format("invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field", ipcIdx, modName, modIdx); string msg = fmt::format("invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field", ipcIdx, modName, modIdx);
spdlog::error(msg); spdlog::error(msg);
hasError = true; hasError = true;
break; break;
} }else{
else {
modName = modName + newMod["type"].get<string>(); modName = modName + newMod["type"].get<string>();
} }
} }
...@@ -428,12 +458,10 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -428,12 +458,10 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
string oldGid = sn + ":" + modName + ":" + to_string(oldMod["iid"].get<int>()); string oldGid = sn + ":" + modName + ":" + to_string(oldMod["iid"].get<int>());
ret["data"][oldGid] = 0; ret["data"][oldGid] = 0;
continue; continue;
} }else if(newMod["sn"].get<string>() != sn && (oldMod.count("sn") == 0 ||(oldMod.count("sn") != 0 && oldMod["sn"].get<string>() != sn))){
else if(newMod["sn"].get<string>() != sn && (oldMod.count("sn") == 0 ||(oldMod.count("sn") != 0 && oldMod["sn"].get<string>() != sn))) {
// ignore // ignore
continue; continue;
} }else{
else {
// oldSn == newSn == sn, below // oldSn == newSn == sn, below
} }
...@@ -447,17 +475,14 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -447,17 +475,14 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
if(propName == "enabled") { if(propName == "enabled") {
if(newMod.count("enabled") == 0||newMod["enabled"].get<int>() == 0) { if(newMod.count("enabled") == 0||newMod["enabled"].get<int>() == 0) {
ret["data"][newGid] = 0; ret["data"][newGid] = 0;
} }else{
else {
ret["data"][newGid] = 1; ret["data"][newGid] = 1;
} }
} }else{ // other prop modification
else { // other prop modification
// it was disabled. just ignore // it was disabled. just ignore
if(ret["data"].count(newGid) != 0 && ret["data"][newGid].get<int>() == 0) { if(ret["data"].count(newGid) != 0 && ret["data"][newGid].get<int>() == 0) {
// nop // nop
} }else{
else {
// restart // restart
ret["data"][newGid] = 2; ret["data"][newGid] = 2;
} }
...@@ -488,32 +513,28 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -488,32 +513,28 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
json modObj; json modObj;
if(d["op"] == "remove") { if(d["op"] == "remove") {
modObj = oldConfig[mgrSn]["ipcs"][ipcIdx]["modules"][modName][modIdx]; modObj = oldConfig[mgrSn]["ipcs"][ipcIdx]["modules"][modName][modIdx];
} }else{
else {
modObj = newConfig[mgrSn]["ipcs"][ipcIdx]["modules"][modName][modIdx]; modObj = newConfig[mgrSn]["ipcs"][ipcIdx]["modules"][modName][modIdx];
} }
if(modObj.count("sn") == 0) { if(modObj.count("sn") == 0) {
if(d["op"] != "remove") { if(d["op"] != "remove"){
string msg = fmt::format("invalid modue config having no sn /{}/ipcs/{}/modules/{}/{}", mgrSn, ipcIdx, modName, modIdx); string msg = fmt::format("invalid modue config having no sn /{}/ipcs/{}/modules/{}/{}", mgrSn, ipcIdx, modName, modIdx);
spdlog::error(msg); spdlog::error(msg);
hasError = true; hasError = true;
ret["msg"] = msg; ret["msg"] = msg;
break; break;
} }else{
else {
// nop // nop
} }
} }else{
else { if(modObj["sn"].get<string>() == sn){
if(modObj["sn"].get<string>() == sn) {
if(modName == "evml") { if(modName == "evml") {
if(modObj.count("type") == 0) { if(modObj.count("type") == 0) {
string msg = fmt::format("invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field", ipcIdx, modName, modIdx); string msg = fmt::format("invalid evml module config ipcs[{}]['modules'][{}][{}] having no type field", ipcIdx, modName, modIdx);
spdlog::error(msg); spdlog::error(msg);
hasError = true; hasError = true;
break; break;
} }else{
else {
modName = modName + modObj["type"].get<string>(); modName = modName + modObj["type"].get<string>();
} }
} }
...@@ -528,12 +549,10 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -528,12 +549,10 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
string modGid = sn + ":" + modName + ":" + to_string(modObj["iid"].get<int>()); string modGid = sn + ":" + modName + ":" + to_string(modObj["iid"].get<int>());
if(d["op"] == "remove") { if(d["op"] == "remove") {
ret["data"][modGid] = 0; ret["data"][modGid] = 0;
} }else{
else {
ret["data"][modGid] = 1; ret["data"][modGid] = 1;
} }
} }else{
else {
// nop // nop
} }
} }
...@@ -553,10 +572,9 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -553,10 +572,9 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
matched = true; matched = true;
string mgrSn = results[1].str(); string mgrSn = results[1].str();
json mgr; json mgr;
if(d["op"] == "remove") { if(d["op"] == "remove"){
mgr[mgrSn] = oldConfig[mgrSn]; mgr[mgrSn] = oldConfig[mgrSn];
} }else{
else {
mgr[mgrSn] = newConfig[mgrSn]; mgr[mgrSn] = newConfig[mgrSn];
} }
...@@ -566,54 +584,11 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -566,54 +584,11 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
ret["msg"] = jret["msg"]; ret["msg"] = jret["msg"];
hasError = true; hasError = true;
break; break;
} }else{
else {
for(auto &k: jret["data"]) {
if(d["op"] == "remove") {
ret["data"][string(k)] = 0;
}
else {
ret["data"][string(k)] = 2;
}
}
}
}
}
}
// one ipc
if(!matched && !hasError) {
// /PSBV7GKN/ipcs/0"
// {"addr":"172.31.0.129","modules":{"evml":[{"area":200,"enabled":1,"entropy":0.3,"iid":1,"post":30,"pre":3,"sn":"PSBV7GKN","thresh":30,"type":"motion"}],"evpuller":[{"addr":"127.0.0.1","enabled":1,"iid":1,"port-pub":5556,"sn":"PSBV7GKN"}],"evpusher":[{"enabled":0,"iid":1,"password":"","sn":"PSBV7GKN","token":"","urlDest":"rtsp://40.73.41.176/PSBV7GKN","user":""}],"evslicer":[{"enabled":1,"iid":1,"path":"slices","sn":"PSBV7GKN","video-server-addr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}
string clusterRegStr = "/(\\w+)/ipcs/(\\d+)";
std::regex clusterRegex(clusterRegStr);
std::smatch results;
if (std::regex_match(path_, results, clusterRegex)) {
if (results.size() == 3) {
matched = true;
string mgrSn = results[1].str();
int ipcIdx = stoi(results[2].str());
json mgr;
if(d["op"] == "remove") {
mgr[mgrSn] = oldConfig[mgrSn];
}
else {
mgr[mgrSn] = newConfig[mgrSn];
}
json jret = cfgutils::getModuleGidsFromCfg(sn, mgr, "getModulesOperFromConfDiff", ipcIdx);
spdlog::info("jret: {}", jret.dump());
if(jret["code"] != 0) {
ret["msg"] = jret["msg"];
hasError = true;
break;
}
else {
for(auto &k: jret["data"]) { for(auto &k: jret["data"]) {
if(d["op"] == "remove") { if(d["op"] == "remove"){
ret["data"][string(k)] = 0; ret["data"][string(k)] = 0;
} }else{
else {
ret["data"][string(k)] = 2; ret["data"][string(k)] = 2;
} }
} }
...@@ -623,11 +598,10 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -623,11 +598,10 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
} }
} }
} }
if(hasError) { if(hasError){
ret["code"] = 1; ret["code"] = 1;
} }
} }catch(exception &e) {
catch(exception &e) {
spdlog::error("getModulesOperFromConfDiff exception: {}", e.what()); spdlog::error("getModulesOperFromConfDiff exception: {}", e.what());
ret["code"] = -1; ret["code"] = -1;
ret["msg"] = e.what(); ret["msg"] = e.what();
......
...@@ -33,69 +33,107 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -33,69 +33,107 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
set<string> oprations{"add", "replace", "remove"}; set<string> oprations{"add", "replace", "remove"};
set<string> pullerTag{"addr", "user", "password", "proto", "port" /*, "sn"*/}; set<string> pullerTag{"addr", "user", "password", "proto", "port" /*, "sn"*/};
string ipcRegStr = "/(\\w+)/ipcs/(\\d+)/(\\w+)"; // string ipcRegStr = "/(\\w+)/ipcs/(\\d+)/(\\w+)";
// std::smatch results;
// std::regex ipcRegex(ipcRegStr);
// if (std::regex_match(path_, results, ipcRegex)) {
// if (results.size() == 4) {
// matched = true;
// string mgrSn = results[1].str();
// int ipcIdx = stoi(results[2].str());
// string tag = results[3].str();
// if(pullerTag.find(tag) != pullerTag.end()) {
// // TODO: op = remove
// if(d["op"] == "add" || d["op"] == "replace") {
// // start
// auto ipc = newConfig[mgrSn]["ipcs"][ipcIdx];
// auto ipcOld = oldConfig[mgrSn]["ipcs"][ipcIdx];
// if(ipc.count("modules") == 0 || ipc["modules"].size() == 0 || ipc["moudles"].count("evpuller") ==0 || ipc["modules"]["evpuller"].size() == 0 ) {
// string msg = fmt::format("invalid config for ipc[{}]['modules']['evpuller']: {}", ipcIdx, newConfig.dump());
// spdlog::error(msg);
// ret["msg"] = msg;
// hasError = true;
// break;
// }else{
// auto &evpullers = ipc["module"]["evpuller"];
// int idx = 0;
// for(auto &puller:evpullers) {
// // strutil
// if(puller.count("sn") == 0) {
// string msg = fmt::format("invalid config for ipc[{}]['modules']['evpuller'][{}] no sn field: {}", ipcIdx, idx, newConfig.dump());
// ret["msg"] = msg;
// spdlog::error(msg);
// hasError = true;
// break;
// }
// if(puller["sn"].get<string>() != sn) {
// spdlog::debug("skip {} for expecting sn: {}", puller.dump(), sn);
// continue;
// }
// if(puller.count("iid") == 0 || puller.count("addr") == 0) {
// string msg = fmt::format("invliad config as of having no iid/addr/enabled field in ipc[{}]['modules']['evpuller'][{}]: {}", ipcIdx, idx, newConfig.dump());
// spdlog::error(msg);
// ret["msg"] = msg;
// hasError = true;
// break;
// }else{
// string gid = sn + ":evpuller:" + to_string(puller["iid"].get<int>());
// if(puller.count("enabled") == 0 || puller["enabled"].get<int>() == 0) {
// ret["data"][gid] = 0; // stop
// }else{
// ret["data"][gid] = 2;
// }
// }
// idx++;
// }
// }
// }
// }
// }
// }
// // else{
// // spdlog::info("no match for ipc", path_);
// // }
// one ipc
if(!matched && !hasError) {
// /PSBV7GKN/ipcs/0"
// {"addr":"172.31.0.129","modules":{"evml":[{"area":200,"enabled":1,"entropy":0.3,"iid":1,"post":30,"pre":3,"sn":"PSBV7GKN","thresh":30,"type":"motion"}],"evpuller":[{"addr":"127.0.0.1","enabled":1,"iid":1,"port-pub":5556,"sn":"PSBV7GKN"}],"evpusher":[{"enabled":0,"iid":1,"password":"","sn":"PSBV7GKN","token":"","urlDest":"rtsp://40.73.41.176/PSBV7GKN","user":""}],"evslicer":[{"enabled":1,"iid":1,"path":"slices","sn":"PSBV7GKN","video-server-addr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}
string clusterRegStr = "/(\\w+)/ipcs/(\\d+).*";
std::regex clusterRegex(clusterRegStr);
std::smatch results; std::smatch results;
std::regex ipcRegex(ipcRegStr); if (std::regex_match(path_, results, clusterRegex)) {
if (std::regex_match(path_, results, ipcRegex)) { if (results.size() == 3) {
if (results.size() == 4) {
matched = true; matched = true;
string mgrSn = results[1].str(); string mgrSn = results[1].str();
int ipcIdx = stoi(results[2].str()); int ipcIdx = stoi(results[2].str());
string tag = results[3].str(); json mgr;
if(pullerTag.find(tag) != pullerTag.end()) { if(d["op"] == "remove"){
// TODO: op = remove mgr[mgrSn] = oldConfig[mgrSn];
if(d["op"] == "add" || d["op"] == "replace") {
// start
auto ipc = newConfig[mgrSn]["ipcs"][ipcIdx];
auto ipcOld = oldConfig[mgrSn]["ipcs"][ipcIdx];
if(ipc.count("modules") == 0 || ipc["modules"].size() == 0 || ipc["moudles"].count("evpuller") ==0 || ipc["modules"]["evpuller"].size() == 0 ) {
string msg = fmt::format("invalid config for ipc[{}]['modules']['evpuller']: {}", ipcIdx, newConfig.dump());
spdlog::error(msg);
ret["msg"] = msg;
hasError = true;
break;
}else{ }else{
auto &evpullers = ipc["module"]["evpuller"]; mgr[mgrSn] = newConfig[mgrSn];
int idx = 0;
for(auto &puller:evpullers) {
// strutil
if(puller.count("sn") == 0) {
string msg = fmt::format("invalid config for ipc[{}]['modules']['evpuller'][{}] no sn field: {}", ipcIdx, idx, newConfig.dump());
ret["msg"] = msg;
spdlog::error(msg);
hasError = true;
break;
}
if(puller["sn"].get<string>() != sn) {
spdlog::debug("skip {} for expecting sn: {}", puller.dump(), sn);
continue;
} }
if(puller.count("iid") == 0 || puller.count("addr") == 0) { json jret = cfgutils::getModuleGidsFromCfg(sn, mgr, "getModulesOperFromConfDiff", ipcIdx);
string msg = fmt::format("invliad config as of having no iid/addr/enabled field in ipc[{}]['modules']['evpuller'][{}]: {}", ipcIdx, idx, newConfig.dump()); spdlog::info("jret: {}", jret.dump());
spdlog::error(msg); if(jret["code"] != 0) {
ret["msg"] = msg; ret["msg"] = jret["msg"];
hasError = true; hasError = true;
break; break;
}else{ }else{
string gid = sn + ":evpuller:" + to_string(puller["iid"].get<int>()); for(auto &k: jret["data"]) {
if(puller.count("enabled") == 0 || puller["enabled"].get<int>() == 0) { if(d["op"] == "remove"){
ret["data"][gid] = 0; // stop ret["data"][string(k)] = 0;
}else{ }else{
ret["data"][gid] = 2; ret["data"][string(k)] = 2;
}
}
idx++;
} }
} }
} }
} }
} }
} }
// else{
// spdlog::info("no match for ipc", path_);
// }
// match module config // match module config
if(!matched && !hasError) { if(!matched && !hasError) {
...@@ -281,44 +319,6 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st ...@@ -281,44 +319,6 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
} }
} }
} }
// one ipc
if(!matched && !hasError) {
// /PSBV7GKN/ipcs/0"
// {"addr":"172.31.0.129","modules":{"evml":[{"area":200,"enabled":1,"entropy":0.3,"iid":1,"post":30,"pre":3,"sn":"PSBV7GKN","thresh":30,"type":"motion"}],"evpuller":[{"addr":"127.0.0.1","enabled":1,"iid":1,"port-pub":5556,"sn":"PSBV7GKN"}],"evpusher":[{"enabled":0,"iid":1,"password":"","sn":"PSBV7GKN","token":"","urlDest":"rtsp://40.73.41.176/PSBV7GKN","user":""}],"evslicer":[{"enabled":1,"iid":1,"path":"slices","sn":"PSBV7GKN","video-server-addr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}
string clusterRegStr = "/(\\w+)/ipcs/(\\d+)";
std::regex clusterRegex(clusterRegStr);
std::smatch results;
if (std::regex_match(path_, results, clusterRegex)) {
if (results.size() == 3) {
matched = true;
string mgrSn = results[1].str();
int ipcIdx = stoi(results[2].str());
json mgr;
if(d["op"] == "remove"){
mgr[mgrSn] = oldConfig[mgrSn];
}else{
mgr[mgrSn] = newConfig[mgrSn];
}
json jret = cfgutils::getModuleGidsFromCfg(sn, mgr, "getModulesOperFromConfDiff", ipcIdx);
spdlog::info("jret: {}", jret.dump());
if(jret["code"] != 0) {
ret["msg"] = jret["msg"];
hasError = true;
break;
}else{
for(auto &k: jret["data"]) {
if(d["op"] == "remove"){
ret["data"][string(k)] = 0;
}else{
ret["data"][string(k)] = 2;
}
}
}
}
}
}
} }
} }
if(hasError){ if(hasError){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论