rdb资源cate分类统计接口 (#380)
* rdb 资源cate分类统计接口 * 代码调节 Co-authored-by: alickliming <alickliming@didi.global.com>
This commit is contained in:
parent
79501b46fe
commit
633f224be6
|
@ -116,6 +116,7 @@ func Config(r *gin.Engine) {
|
||||||
userLogin.POST("/node/:id/roles", rolesUnderNodePost)
|
userLogin.POST("/node/:id/roles", rolesUnderNodePost)
|
||||||
userLogin.DELETE("/node/:id/roles", rolesUnderNodeDel)
|
userLogin.DELETE("/node/:id/roles", rolesUnderNodeDel)
|
||||||
userLogin.GET("/node/:id/resources", resourceUnderNodeGet)
|
userLogin.GET("/node/:id/resources", resourceUnderNodeGet)
|
||||||
|
userLogin.GET("/node/:id/resources/cate-count", renderNodeResourcesCountByCate)
|
||||||
userLogin.POST("/node/:id/resources/bind", resourceBindNode)
|
userLogin.POST("/node/:id/resources/bind", resourceBindNode)
|
||||||
userLogin.POST("/node/:id/resources/unbind", resourceUnbindNode)
|
userLogin.POST("/node/:id/resources/unbind", resourceUnbindNode)
|
||||||
userLogin.PUT("/node/:id/resources/note", resourceUnderNodeNotePut)
|
userLogin.PUT("/node/:id/resources/note", resourceUnderNodeNotePut)
|
||||||
|
|
|
@ -351,3 +351,54 @@ func v1ResourcesUnregisterPost(c *gin.Context) {
|
||||||
dangerous(models.ResourceUnregister(uuids))
|
dangerous(models.ResourceUnregister(uuids))
|
||||||
renderMessage(c, nil)
|
renderMessage(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type nodeResourcesCountResp struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Count int `json:"count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func renderNodeResourcesCountByCate(c *gin.Context) {
|
||||||
|
needSourceList := []string{"physical", "virtual", "redis", "mongo", "mysql"}
|
||||||
|
|
||||||
|
nodeId := urlParamInt64(c, "id")
|
||||||
|
node := Node(nodeId)
|
||||||
|
leadIds, err := node.LeafIds()
|
||||||
|
dangerous(err)
|
||||||
|
|
||||||
|
limit := 10000
|
||||||
|
query := ""
|
||||||
|
batch := ""
|
||||||
|
field := "ident"
|
||||||
|
|
||||||
|
ress, err := models.ResourceUnderNodeGets(leadIds, query, batch, field, limit, 0)
|
||||||
|
dangerous(err)
|
||||||
|
|
||||||
|
aggDat := make(map[string]int, len(ress))
|
||||||
|
for _, res := range ress {
|
||||||
|
cate := res.Cate
|
||||||
|
if cate != "" {
|
||||||
|
if _, ok := aggDat[cate]; !ok {
|
||||||
|
aggDat[cate] = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
aggDat[cate]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, need := range needSourceList {
|
||||||
|
if _, ok := aggDat[need]; !ok {
|
||||||
|
aggDat[need] = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []*nodeResourcesCountResp
|
||||||
|
for n, c := range aggDat {
|
||||||
|
ns := new(nodeResourcesCountResp)
|
||||||
|
ns.Name = n
|
||||||
|
ns.Count = c
|
||||||
|
|
||||||
|
list = append(list, ns)
|
||||||
|
}
|
||||||
|
|
||||||
|
renderData(c, list, nil)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue