Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
c2075f4a
提交
c2075f4a
authored
10月 18, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bugfix: check 0 sized file
上级
fec55d5c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
278 行增加
和
42 行删除
+278
-42
version.json
opencv-motion-detect/deployment/version.json
+41
-36
evcloudsvc.cpp
opencv-motion-detect/evcloudsvc.cpp
+237
-6
没有找到文件。
opencv-motion-detect/deployment/version.json
浏览文件 @
c2075f4a
{
{
"b1.0.0"
:
{
"activeIdx"
:
-1
,
"evcloudsvc"
:
{
"bundles"
:
[
"url"
:
""
,
{
"version"
:
"0.1.1"
,
"releaseId"
:
"aabbcc"
,
"updateTime"
:
123
"updateTime"
:
123
,
},
"evcloudsvc"
:
{
"evdaemon"
:
{
"url"
:
""
,
"url"
:
""
,
"version"
:
"0.1.1"
,
"version"
:
"0.1.1"
,
"updateTime"
:
123
"updateTime"
:
123
},
},
"evdaemon"
:
{
"evmgr"
:
{
"url"
:
""
,
"url"
:
""
,
"version"
:
"0.1.1"
,
"version"
:
"0.1.1"
,
"updateTime"
:
123
"updateTime"
:
123
},
},
"evmgr"
:
{
"evpuller"
:
{
"url"
:
""
,
"url"
:
""
,
"version"
:
"0.1.1"
,
"version"
:
"0.1.1"
,
"updateTime"
:
123
"updateTime"
:
123
},
},
"evpuller"
:
{
"evpusher"
:
{
"url"
:
""
,
"url"
:
""
,
"version"
:
"0.1.1"
,
"version"
:
"0.1.1"
,
"updateTime"
:
123
"updateTime"
:
123
},
},
"evpusher"
:
{
"evslicer"
:
{
"url"
:
""
,
"url"
:
""
,
"version"
:
"0.1.1"
,
"version"
:
"0.1.1"
,
"updateTime"
:
123
"updateTime"
:
123
},
},
"evslicer"
:
{
"evmlmotion"
:
{
"url"
:
""
,
"url"
:
""
,
"version"
:
"0.1.1"
,
"version"
:
"0.1.1"
,
"updateTime"
:
123
"updateTime"
:
123
},
"evmlmotion"
:
{
"url"
:
""
,
"version"
:
"0.1.1"
,
"updateTime"
:
123
}
}
}
}
]
}
}
opencv-motion-detect/evcloudsvc.cpp
浏览文件 @
c2075f4a
...
@@ -27,6 +27,7 @@ using namespace zmqhelper;
...
@@ -27,6 +27,7 @@ using namespace zmqhelper;
//
//
#define KEY_CONFIG_MAP "configmap"
#define KEY_CONFIG_MAP "configmap"
#define KEY_RELEASE_BUNDLE "release_bundle"
class
EvCloudSvc
{
class
EvCloudSvc
{
private
:
private
:
Server
svr
;
Server
svr
;
...
@@ -36,6 +37,7 @@ private:
...
@@ -36,6 +37,7 @@ private:
string
devSn
=
"evcloudsvc"
;
string
devSn
=
"evcloudsvc"
;
json
configMap
;
json
configMap
;
json
releaseBundle
;
// peer data
// peer data
json
peerData
;
json
peerData
;
...
@@ -78,6 +80,16 @@ private:
...
@@ -78,6 +80,16 @@ private:
spdlog
::
info
(
"evcloudsvc loaded config for device: {}"
,
k
);
spdlog
::
info
(
"evcloudsvc loaded config for device: {}"
,
k
);
}
}
}
}
// release bundle
json
relBund
;
ret
=
LVDB
::
getValue
(
relBund
,
KEY_RELEASE_BUNDLE
);
if
(
ret
<
0
||
relBund
.
size
()
==
0
)
{
this
->
releaseBundle
[
"bundles"
]
=
json
();
this
->
releaseBundle
[
"activeIdx"
]
=
-
1
;
}
else
{
this
->
releaseBundle
=
relBund
;
}
}
}
int
sendConfig
(
json
&
config_
,
string
sn
)
int
sendConfig
(
json
&
config_
,
string
sn
)
...
@@ -628,12 +640,199 @@ private:
...
@@ -628,12 +640,199 @@ private:
json
getReleaseBundle
(
string
bid
)
json
getReleaseBundle
(
string
bid
)
{
{
json
ret
;
json
ret
;
int
stackId
=
-
1
;
if
(
bid
.
empty
())
{
ret
=
this
->
releaseBundle
;
}
else
{
try
{
stackId
=
stoi
(
bid
);
}
catch
(
exception
&
e
)
{
stackId
=
-
1
;
}
if
(
this
->
releaseBundle
.
size
()
!=
0
&&
this
->
releaseBundle
.
count
(
"bundles"
)
!=
0
)
{
auto
&
bunds
=
this
->
releaseBundle
[
"bundles"
];
int
idx
=
bunds
.
size
()
-
1
-
stackId
;
if
(
stackId
>=
0
&&
idx
>=
0
)
{
// idx style
ret
=
bunds
[
idx
];
}
else
{
// releaseId style
for
(
auto
&
r
:
bunds
)
{
if
(
r
[
"releaseId"
]
==
bid
)
{
ret
=
r
;
break
;
}
}
}
}
}
return
ret
;
}
string
enableRelease
(
string
bid
,
bool
enable
){
string
ret
;
int
stackId
=
-
1
;
bool
handled
=
false
;
bool
isNumber
=
true
;
if
(
bid
.
empty
())
{
if
(
enable
)
{
if
(
this
->
releaseBundle
.
size
()
>
0
)
{
this
->
releaseBundle
[
"activeIdx"
]
=
this
->
releaseBundle
.
size
()
-
1
;
handled
=
true
;
// TODO: send release to edge
}
}
else
{
if
(
this
->
releaseBundle
[
"bundles"
].
size
()
<=
1
)
{
ret
=
"no release to disable. (maybe only one or none release bundle configured)"
;
}
}
}
else
{
try
{
stackId
=
stoi
(
bid
);
}
catch
(
exception
&
e
)
{
isNumber
=
false
;
}
if
(
this
->
releaseBundle
.
size
()
!=
0
&&
this
->
releaseBundle
.
count
(
"bundles"
)
!=
0
)
{
auto
&
bunds
=
this
->
releaseBundle
[
"bundles"
];
if
(
isNumber
)
{
int
idx
=
bunds
.
size
()
-
1
-
stackId
;
if
(
idx
<
0
)
{
ret
=
string
(
"no left configure to "
)
+
(
enable
?
"enable"
:
"disable"
);
return
ret
;
}
if
(
this
->
releaseBundle
[
"activeIdx"
]
==
idx
)
{
if
(
enable
)
{
spdlog
::
info
(
"evcloudsvc release {} is already in active. nop."
,
idx
);
}
else
{
return
enableRelease
(
to_string
(
idx
-
1
),
true
);
// TODO: send release to edge
}
}
else
{
if
(
enable
)
{
this
->
releaseBundle
[
"activeIdx"
]
=
idx
;
handled
=
true
;
// TODO: send release to edge
}
else
{
ret
=
"this release is not in active. nop."
;
}
}
}
else
{
// releaseId style
int
idx
=
0
;
for
(
auto
&
r
:
bunds
)
{
if
(
r
[
"releaseId"
]
==
bid
)
{
return
enableRelease
(
to_string
(
idx
),
enable
);
}
idx
++
;
}
}
}
}
return
ret
;
}
string
delReleaseBundle
(
string
bid
)
{
string
ret
;
int
stackId
=
-
1
;
if
(
bid
.
empty
())
{
ret
=
"empty release bundle id"
;
}
else
{
try
{
stackId
=
stoi
(
bid
);
}
catch
(
exception
&
e
)
{
stackId
=
-
1
;
}
if
(
this
->
releaseBundle
.
size
()
!=
0
&&
this
->
releaseBundle
.
count
(
"bundles"
)
!=
0
)
{
auto
&
bunds
=
this
->
releaseBundle
[
"bundles"
];
bool
handled
=
false
;
int
idx
=
bunds
.
size
()
-
1
-
stackId
;
spdlog
::
info
(
"idx: {}"
,
idx
);
if
(
stackId
>=
0
&&
idx
>=
0
)
{
if
(
idx
==
this
->
releaseBundle
[
"activeIdx"
].
get
<
int
>
()){
ret
=
"can't delete active release bundle"
;
}
else
{
bunds
.
erase
(
idx
);
if
(
idx
<
this
->
releaseBundle
[
"activeIdx"
].
get
<
int
>
())
{
this
->
releaseBundle
[
"activeIdx"
]
=
this
->
releaseBundle
[
"activeIdx"
].
get
<
int
>
()
-
1
;
}
handled
=
true
;
}
}
else
if
(
stackId
>=
0
&&
bunds
.
size
()
-
1
-
stackId
<
0
)
{
ret
=
"release bundle not exist"
;
}
else
{
// releaseId style
int
idx
=
0
;
for
(
auto
r
:
bunds
)
{
if
(
r
[
"releaseId"
]
==
bid
)
{
bunds
.
erase
(
idx
);
handled
=
true
;
break
;
}
idx
++
;
}
if
(
handled
)
{
if
(
idx
<
this
->
releaseBundle
[
"activeIdx"
])
{
this
->
releaseBundle
[
"activeIdx"
]
=
this
->
releaseBundle
[
"activeIdx"
].
get
<
int
>
()
-
1
;
}
}
else
{
ret
=
"release bundle not exist"
;
}
}
if
(
handled
)
{
// save
int
r
=
LVDB
::
setValue
(
this
->
releaseBundle
,
KEY_RELEASE_BUNDLE
);
if
(
r
<
0
)
{
string
msg
=
fmt
::
format
(
"evcloudsvc failed to save release bundle"
);
spdlog
::
error
(
msg
);
ret
=
msg
;
}
}
}
}
return
ret
;
return
ret
;
}
}
json
addReleaseBundle
(
json
&
bundle
)
string
addReleaseBundle
(
json
&
bundle
)
{
{
json
ret
;
string
ret
;
if
(
bundle
.
count
(
"releaseId"
)
==
0
)
{
ret
=
"no releaseId field"
;
}
else
{
for
(
auto
&
b
:
this
->
releaseBundle
[
"bundles"
])
{
if
(
b
[
"releaseId"
]
==
bundle
[
"releaseId"
])
{
ret
=
"releaseId already exist: "
+
b
.
dump
();
spdlog
::
error
(
string
(
"evcloudsvc POST /release: "
)
+
ret
);
break
;
}
}
if
(
!
ret
.
empty
())
{
return
ret
;
}
this
->
releaseBundle
[
"bundles"
].
push_back
(
bundle
);
if
(
bundle
.
count
(
"active"
)
!=
0
&&
bundle
[
"active"
]
!=
0
)
{
// TODO: release to edge
this
->
releaseBundle
[
"activeIdx"
]
=
this
->
releaseBundle
[
"bundles"
].
size
()
-
1
;
// sendRealseToEdge(bundle);
}
// save
int
r
=
LVDB
::
setValue
(
this
->
releaseBundle
,
KEY_RELEASE_BUNDLE
);
if
(
r
<
0
)
{
string
msg
=
fmt
::
format
(
"evcloudsvc failed to save release bundle"
);
spdlog
::
error
(
msg
);
ret
=
msg
;
}
}
return
ret
;
return
ret
;
}
}
...
@@ -841,9 +1040,14 @@ public:
...
@@ -841,9 +1040,14 @@ public:
ret
[
"code"
]
=
0
;
ret
[
"code"
]
=
0
;
ret
[
"msg"
]
=
"ok"
;
ret
[
"msg"
]
=
"ok"
;
try
{
try
{
string
bundleId
=
req
.
get_param_value
(
"bId"
);
string
bundleId
=
req
.
get_param_value
(
"bid"
);
auto
body
=
json
::
parse
(
req
.
body
);
auto
bundle
=
this
->
getReleaseBundle
(
bundleId
);
ret
=
this
->
getReleaseBundle
(
bundleId
);
if
(
bundle
.
size
()
==
0
)
{
ret
[
"code"
]
=
1
;
ret
[
"msg"
]
=
"not found"
;
}
else
{
ret
[
"data"
]
=
bundle
;
}
}
}
catch
(
exception
&
e
)
{
catch
(
exception
&
e
)
{
ret
[
"code"
]
=
-
1
;
ret
[
"code"
]
=
-
1
;
...
@@ -862,7 +1066,11 @@ public:
...
@@ -862,7 +1066,11 @@ public:
ret
[
"msg"
]
=
"ok"
;
ret
[
"msg"
]
=
"ok"
;
try
{
try
{
auto
body
=
json
::
parse
(
req
.
body
);
auto
body
=
json
::
parse
(
req
.
body
);
ret
=
this
->
addReleaseBundle
(
body
);
auto
s
=
this
->
addReleaseBundle
(
body
);
if
(
!
s
.
empty
()){
ret
[
"code"
]
=
1
;
ret
[
"msg"
]
=
s
;
}
}
}
catch
(
exception
&
e
)
{
catch
(
exception
&
e
)
{
ret
[
"code"
]
=
-
1
;
ret
[
"code"
]
=
-
1
;
...
@@ -874,6 +1082,29 @@ public:
...
@@ -874,6 +1082,29 @@ public:
res
.
set_content
(
ret
.
dump
(),
"text/json"
);
res
.
set_content
(
ret
.
dump
(),
"text/json"
);
});
});
svr
.
Delete
(
"/release"
,
[
this
](
const
Request
&
req
,
Response
&
res
)
{
json
ret
;
string
msg
;
ret
[
"code"
]
=
0
;
ret
[
"msg"
]
=
"ok"
;
try
{
string
bundleId
=
req
.
get_param_value
(
"bid"
);
auto
s
=
this
->
delReleaseBundle
(
bundleId
);
if
(
!
s
.
empty
())
{
ret
[
"msg"
]
=
s
;
ret
[
"code"
]
=
1
;
}
}
catch
(
exception
&
e
)
{
ret
[
"code"
]
=
-
1
;
msg
=
fmt
::
format
(
"evcloudsvc Get /release Exception: {}"
,
e
.
what
());
spdlog
::
error
(
msg
);
ret
[
"msg"
]
=
msg
;
}
res
.
set_content
(
ret
.
dump
(),
"text/json"
);
});
svr
.
listen
(
"0.0.0.0"
,
stoi
(
httpPort
));
svr
.
listen
(
"0.0.0.0"
,
stoi
(
httpPort
));
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论