提交 94ecc77e authored 作者: blu's avatar blu

cloud cmd api for platform client

上级 18570676
......@@ -21,7 +21,7 @@ update: 2019/09/10
using namespace leveldb;
using namespace httplib;
string _config_default_tmpl = "{\"time\":0,\"code\":0,\"data\":{\"<SN_MGR>\":{\"sn\":\"<SN_MGR>\",\"addr\":\"127.0.0.1\",\"mqtt-cloud\":\"<cloud_addr>\",\"api-cloud\":\"http://127.0.0.1:8089\",\"proto\":\"zmq\",\"port-cloud\":5556,\"port-router\":5550,\"status\":1,\"ipcs\":[{\"addr\":\"172.31.0.51\",\"proto\":\"rtsp\",\"user\":\"admin\",\"password\":\"FWBWTU\",\"status\":0,\"port\":554,\"modules\":{\"evpuller\":[{\"sn\":\"<SN_PULLER>\",\"addr\":\"127.0.0.1\",\"iid\":1,\"port-pub\":5556,\"status\":0}],\"evpusher\":[{\"sn\":\"<SN_PUSHER>\",\"iid\":1,\"urlDest\":\"rtsp://40.73.41.176:554/test1\",\"user\":\"\",\"password\":\"\",\"token\":\"\",\"enabled\":1,\"status\":0}],\"evslicer\":[{\"sn\":\"<SN_SLICER>\",\"iid\":1,\"path\":\"slices\",\"enabled\":1,\"status\":0}],\"evml\":[{\"type\":\"motion\",\"sn\":\"<SN_ML>\",\"iid\":1,\"pre\":3,\"area\":300,\"post\":30,\"thresh\":80,\"enabled\":1,\"status\":0}]}}]}}}";
string _config_default_tmpl = "{\"time\":0,\"code\":0,\"data\":{\"<SN_MGR>\":{\"sn\":\"<SN_MGR>\",\"addr\":\"127.0.0.1\",\"mqttCloud\":\"<cloud_addr>\",\"apiCloud\":\"http://127.0.0.1:8089\",\"proto\":\"zmq\",\"portCloud\":5556,\"portRouter\":5550,\"status\":1,\"ipcs\":[{\"addr\":\"172.31.0.51\",\"proto\":\"rtsp\",\"user\":\"admin\",\"password\":\"FWBWTU\",\"status\":0,\"port\":554,\"modules\":{\"evpuller\":[{\"sn\":\"<SN_PULLER>\",\"addr\":\"127.0.0.1\",\"iid\":1,\"portPub\":5556,\"status\":0}],\"evpusher\":[{\"sn\":\"<SN_PUSHER>\",\"iid\":1,\"urlDest\":\"rtsp://40.73.41.176:554/test1\",\"user\":\"\",\"password\":\"\",\"token\":\"\",\"enabled\":1,\"status\":0}],\"evslicer\":[{\"sn\":\"<SN_SLICER>\",\"iid\":1,\"path\":\"slices\",\"enabled\":1,\"status\":0}],\"evml\":[{\"type\":\"motion\",\"sn\":\"<SN_ML>\",\"iid\":1,\"pre\":3,\"area\":300,\"post\":30,\"thresh\":80,\"enabled\":1,\"status\":0}]}}]}}}";
const string _sn_tmpl[] = {"<SN_MGR>", "<SN_PULLER>", "<SN_PUSHER>", "<SN_SLICER>", "<SN_ML>"};
const string _addr_tmpl[] = {"<ADDR_CAMERA>"};
......@@ -381,7 +381,7 @@ togo_end:
// create default sn.
string sn = getStrRand(8);
info["sn"] = sn;
info["api-cloud"] = "http://127.0.0.1:8089";
info["apiCloud"] = "http://127.0.0.1:8089";
spdlog::warn("no local sn set. create a new one: {}", sn);
auto tsNow = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
info["lastboot"] = tsNow;
......
{
"data":{
"W2E0VFN1":{
"V2I0C7KC":{
"addr":"127.0.0.1",
"api-cloud":"http://127.0.0.1:8089",
"apiCloud":"http://127.0.0.1:8089",
"ipcs":[
{
"addr":"172.31.0.129",
......@@ -14,7 +14,7 @@
"iid":1,
"post":30,
"pre":3,
"sn":"W2E0VFN1",
"sn":"V2I0C7KC",
"thresh":30,
"entropy": 0.3,
"type":"motion"
......@@ -25,8 +25,8 @@
"addr":"127.0.0.1",
"iid":1,
"enabled": 1,
"port-pub":5556,
"sn":"W2E0VFN1"
"portPub":5556,
"sn":"V2I0C7KC"
}
],
"evpusher":[
......@@ -34,9 +34,9 @@
"enabled":0,
"iid":1,
"password":"",
"sn":"W2E0VFN1",
"sn":"V2I0C7KC",
"token":"",
"urlDest":"rtsp://40.73.41.176/W2E0VFN1",
"urlDest":"rtsp://40.73.41.176/V2I0C7KC",
"user":""
}
],
......@@ -45,8 +45,8 @@
"enabled":1,
"iid":1,
"path":"slices",
"sn":"W2E0VFN1",
"video-server-addr": "http://40.73.41.176:10009/upload/evtvideos/"
"sn":"V2I0C7KC",
"videoServerAddr": "http://40.73.41.176:10009/upload/evtvideos/"
}
]
},
......@@ -57,11 +57,11 @@
"sn": "iLabService"
}
],
"mqtt-cloud":"<cloud_addr>",
"port-cloud":5556,
"port-router":5550,
"mqttCloud":"<cloud_addr>",
"portCloud":5556,
"portRouter":5550,
"proto":"zmq",
"sn":"W2E0VFN1"
"sn":"V2I0C7KC"
}
},
"lastupdated":1567669674
......
......@@ -68,7 +68,7 @@ private:
goto error_exit;
}
addr = "tcp://*:" + to_string(config["port-router"]);
addr = "tcp://*:" + to_string(config["portRouter"]);
// setup zmq
// TODO: connect to cloud
......
......@@ -217,8 +217,8 @@ private:
json evslicer = ipc["modules"]["evslicer"][0];
slicerGid = evslicer["sn"].get<string>()+":evslicer:" + to_string(evslicer["iid"]);
urlPub = string("tcp://") + evpuller["addr"].get<string>() + ":" + to_string(evpuller["port-pub"]);
urlRouter = string("tcp://") + evmgr["addr"].get<string>() + ":" + to_string(evmgr["port-router"]);
urlPub = string("tcp://") + evpuller["addr"].get<string>() + ":" + to_string(evpuller["portPub"]);
urlRouter = string("tcp://") + evmgr["addr"].get<string>() + ":" + to_string(evmgr["portRouter"]);
spdlog::info("evmlmotion {} will connect to {} for sub, {} for router", selfId, urlPub, urlRouter);
// TODO: multiple protocols support
......
......@@ -220,8 +220,8 @@ private:
exit(1);
}
urlPub = string("tcp://*:") + to_string(evpuller["port-pub"]);
urlDealer = "tcp://" + evmgr["addr"].get<string>() + string(":") + to_string(evmgr["port-router"]);
urlPub = string("tcp://*:") + to_string(evpuller["portPub"]);
urlDealer = "tcp://" + evmgr["addr"].get<string>() + string(":") + to_string(evmgr["portRouter"]);
spdlog::info("evpuller {} bind on {} for pub, connect to {} for dealer", selfId, urlPub, urlDealer);
pPubCtx = zmq_ctx_new();
......
......@@ -91,8 +91,8 @@ private:
pullerGid = evpuller["sn"].get<string>() + ":evpuller:" + to_string(evpuller["iid"]);
mgrSn = evmgr["sn"];
urlPub = string("tcp://") + evpuller["addr"].get<string>() + ":" + to_string(evpuller["port-pub"]);
urlDealer = string("tcp://") + evmgr["addr"].get<string>() + ":" + to_string(evmgr["port-router"]);
urlPub = string("tcp://") + evpuller["addr"].get<string>() + ":" + to_string(evpuller["portPub"]);
urlDealer = string("tcp://") + evmgr["addr"].get<string>() + ":" + to_string(evmgr["portRouter"]);
spdlog::info("evpusher {} connect to {} for sub, {} for router", selfId, urlPub, urlDealer);
// TODO: multiple protocols support
urlOut = evpusher["urlDest"].get<string>();
......
......@@ -259,8 +259,8 @@ private:
ipcSn = ipc["sn"];
}
if(evslicer.count("video-server-addr") != 0 && !evslicer["video-server-addr"].get<string>().empty()) {
videoFileServerApi = evslicer["video-server-addr"].get<string>();
if(evslicer.count("videoServerAddr") != 0 && !evslicer["videoServerAddr"].get<string>().empty()) {
videoFileServerApi = evslicer["videoServerAddr"].get<string>();
if(videoFileServerApi.at(videoFileServerApi.size()-1) != '/') {
videoFileServerApi += string("/");
}
......@@ -301,8 +301,8 @@ private:
spdlog::info("evslicer mkdir -p {}", selfId, urlOut);
ret = system((string("mkdir -p ") + urlOut).c_str());
urlPub = string("tcp://") + evpuller["addr"].get<string>() + ":" + to_string(evpuller["port-pub"]);
urlRouter = string("tcp://") + evmgr["addr"].get<string>() + ":" + to_string(evmgr["port-router"]);
urlPub = string("tcp://") + evpuller["addr"].get<string>() + ":" + to_string(evpuller["portPub"]);
urlRouter = string("tcp://") + evmgr["addr"].get<string>() + ":" + to_string(evmgr["portRouter"]);
spdlog::info("evslicer {} will connect to {} for sub, {} for router", selfId, urlPub, urlRouter);
// setup sub
......@@ -613,11 +613,12 @@ protected:
string videoFileTs2Name(long ts, bool bLog = false)
{
std::time_t now = ts;
std::tm * ptm = std::localtime(&now);
std::tm t;
memcpy(&t, localtime(&ts), sizeof(t));
char buffer[20];
// Format: Mo, 15.06.2009 20:20:00
std::strftime(buffer, 20, "%Y%m%d_%H%M%S", ptm);
std::strftime(buffer, 20, "%Y%m%d_%H%M%S", &t);
if(bLog)
spdlog::info("ts: {}, fname: {}/{}.mp4", ts, this->urlOut, buffer);
return string(buffer);
......@@ -822,8 +823,6 @@ protected:
// find video files
vector<string> findSlicesByRange(long tss, long tse, int offsetS, int offsetE)
{
debugFilesRing(this->vTsActive);
vector<string> ret;
int found = 0;
int _itss = 0;
......@@ -997,9 +996,30 @@ public:
}
// TODO: scheduled task
spdlog::info("evslicer {} wait for {}s to matching event videos", this->selfId, this->seconds + 5);
// check tss, tse
int sIdx = 0, eIdx = 0;
if(this->bSegFull) {
sIdx = this->incSegHead(this->segHead);
eIdx = this->decSegHead(this->segHead);
}else{
sIdx = 1;
eIdx = this->decSegHead(this->segHead);
}
if(sIdx > eIdx || tss > this->vTsActive[eIdx] || tse < this->vTsActive[sIdx]) {
spdlog::error("event range ({}, {}) not in local range ({}, {}).", tss, tse, this->vTsActive[sIdx], this->vTsActive[eIdx]);
this->debugFilesRing(this->vTsActive);
continue;
}
if(sIdx == eIdx)
{
spdlog::info("evslicer {} wait for {}s to matching event videos", this->selfId, this->seconds + 5);
this_thread::sleep_for(chrono::seconds(this->seconds + 5));
}else{
spdlog::info("event range ({}, {}) is in local range ({}, {}).", tss, tse, this->vTsActive[sIdx], this->vTsActive[eIdx]);
}
auto v = findSlicesByRange(tss, tse, offsetS, offsetE);
if(v.size() == 0) {
spdlog::error("evslicer {} ignore upload videos in range ({}, {})", this->selfId, this->videoFileTs2Name(tss), this->videoFileTs2Name(tse));
......
......@@ -9,10 +9,10 @@ json registry(json &conf, string sn, string module)
json ret;
string api;
try {
api = conf.at("data").at(sn).at("api-cloud").get<string>() + "/register";
api = conf.at("data").at(sn).at("apiCloud").get<string>() + "/register";
Uri uri=Uri::Parse(api);
if(uri.Host.empty()||uri.Port.empty()||uri.Protocol.find("http") == string::npos||uri.Path.empty()) {
string msg = "registry error. invalid api-cloud in config: " + api;
string msg = "registry error. invalid apiCloud in config: " + api;
ret["code"] = 1;
ret["msg"] = msg;
spdlog::error(msg);
......@@ -45,11 +45,11 @@ json reqConfig(json &info)
json ret;
string api;
try {
api = info.at("api-cloud").get<string>();
api = info.at("apiCloud").get<string>();
Uri uri=Uri::Parse(api);
string sn = info.at("sn").get<string>();
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 apiCloud in info: " + api;
ret["code"] = EVCLOUD_REQ_E_PARAM;
ret["msg"] = msg;
spdlog::error(msg);
......@@ -334,7 +334,7 @@ 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"}
// {"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,"portPub":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","videoServerAddr":"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;
......@@ -375,7 +375,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
// match module config
if(!matched && !hasError) {
// /PSBV7GKN/ipcs/0/modules/evslicer/0/video-server-addr
// /PSBV7GKN/ipcs/0/modules/evslicer/0/videoServerAddr
// /NMXH73Y2/ipcs/0/modules/evpusher/0/urlDest
string moduleRegStr = "/(\\w+)/ipcs/(\\d+)/modules/(\\w+)/(\\d+)/([^/]+)";
std::regex moduleRegex(moduleRegStr);
......@@ -518,7 +518,7 @@ json getModulesOperFromConfDiff(json& oldConfig, json &newConfig, json &diff, st
// whole cluster
if(!matched && !hasError) {
// /PSBV7GKN
// "value":{"addr":"127.0.0.1","api-cloud":"http://127.0.0.1:8089","ipcs":[{"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"}],"mqtt-cloud":"<cloud_addr>","port-cloud":5556,"port-router":5550,"proto":"zmq","sn":"PSBV7GKN"}
// "value":{"addr":"127.0.0.1","apiCloud":"http://127.0.0.1:8089","ipcs":[{"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,"portPub":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","videoServerAddr":"http://40.73.41.176:10009/upload/evtvideos/"}]},"password":"iLabService","port":554,"proto":"rtsp","sn":"iLabService","user":"admin"}],"mqttCloud":"<cloud_addr>","portCloud":5556,"portRouter":5550,"proto":"zmq","sn":"PSBV7GKN"}
string clusterRegStr = "/(\\w+)";
std::regex clusterRegex(clusterRegStr);
std::smatch results;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论