Merge pull request 'schedule situation' (#133) from zhangweiii/pcm-coordinator:master into master
Former-commit-id: d8fe5a1885ed560eb8ac9ad23e35f4bab451afa1
This commit is contained in:
commit
cf52f868ce
|
@ -80,4 +80,29 @@ type (
|
||||||
name string `json:"name"`
|
name string `json:"name"`
|
||||||
version string `json:"version"`
|
version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
scheduleSituationResp{
|
||||||
|
nodes []NodeRegion `json:"nodes"`
|
||||||
|
links []Link `json:"links"`
|
||||||
|
categories []Category `json:"categories"`
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeRegion{
|
||||||
|
id int64 `json:"id"`
|
||||||
|
name string `json:"name"`
|
||||||
|
category string `json:"category"`
|
||||||
|
value int `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
Link{
|
||||||
|
source string `json:"source"`
|
||||||
|
target string `json:"target"`
|
||||||
|
}
|
||||||
|
|
||||||
|
Category{
|
||||||
|
name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
)
|
)
|
|
@ -1021,11 +1021,14 @@ service pcm {
|
||||||
|
|
||||||
@doc "Synchronize Cluster alert Information"
|
@doc "Synchronize Cluster alert Information"
|
||||||
@handler syncClusterAlertHandler
|
@handler syncClusterAlertHandler
|
||||||
post /core/syncClusterAlert (SyncClusterAlertReq)
|
post /monitoring/syncClusterAlert (SyncClusterAlertReq)
|
||||||
|
|
||||||
@handler taskNumHandler
|
@handler taskNumHandler
|
||||||
get /monitoring/task/num (taskNumReq) returns (taskNumResp)
|
get /monitoring/task/num (taskNumReq) returns (taskNumResp)
|
||||||
|
|
||||||
@handler adapterInfoHandler
|
@handler adapterInfoHandler
|
||||||
get /monitoring/adapter/info (adapterInfoReq) returns (adapterInfoResp)
|
get /monitoring/adapter/info (adapterInfoReq) returns (adapterInfoResp)
|
||||||
|
|
||||||
|
@handler scheduleSituationHandler
|
||||||
|
get /monitoring/schedule/situation returns (scheduleSituationResp)
|
||||||
}
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package monitoring
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/monitoring"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ScheduleSituationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
l := monitoring.NewScheduleSituationLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ScheduleSituation()
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1284,7 +1284,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/core/syncClusterAlert",
|
Path: "/monitoring/syncClusterAlert",
|
||||||
Handler: monitoring.SyncClusterAlertHandler(serverCtx),
|
Handler: monitoring.SyncClusterAlertHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1297,6 +1297,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/monitoring/adapter/info",
|
Path: "/monitoring/adapter/info",
|
||||||
Handler: monitoring.AdapterInfoHandler(serverCtx),
|
Handler: monitoring.AdapterInfoHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/monitoring/schedule/situation",
|
||||||
|
Handler: monitoring.ScheduleSituationHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
rest.WithPrefix("/pcm/v1"),
|
rest.WithPrefix("/pcm/v1"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
package monitoring
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ScheduleSituationLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewScheduleSituationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleSituationLogic {
|
||||||
|
return &ScheduleSituationLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ScheduleSituationLogic) ScheduleSituation() (resp *types.ScheduleSituationResp, err error) {
|
||||||
|
resp = &types.ScheduleSituationResp{}
|
||||||
|
// node region
|
||||||
|
tx := l.svcCtx.DbEngin.Raw("SELECT c.id, c.name, tdi.id AS category, count(DISTINCT ta.id)+count(DISTINCT tc.id)+COUNT(DISTINCT th.id)+COUNT(tv.id) as value FROM t_cluster c LEFT JOIN t_dict_item tdi ON c.region_dict = tdi.id left JOIN task_ai ta ON ta.cluster_id = c.id left JOIN task_cloud tc ON tc.cluster_id = c.id left JOIN task_hpc th ON th.cluster_id = c.id left JOIN task_vm tv ON tv.cluster_id = c.id WHERE tc.deleted_at IS NULL GROUP BY c.id").Scan(&resp.Nodes)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// hpc
|
||||||
|
var hpcLinks []string
|
||||||
|
tx = l.svcCtx.DbEngin.Raw("SELECT GROUP_CONCAT(cluster_id SEPARATOR ',') as cluster_ids FROM task_hpc WHERE deleted_at IS NULL GROUP BY task_id HAVING COUNT(*) > 1;").Scan(&hpcLinks)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
LinksHandler(hpcLinks, resp)
|
||||||
|
// cloud
|
||||||
|
var cloudLinks []string
|
||||||
|
tx = l.svcCtx.DbEngin.Raw("SELECT GROUP_CONCAT(cluster_id SEPARATOR ',') as cluster_ids FROM task_cloud WHERE deleted_at IS NULL GROUP BY task_id HAVING COUNT(*) > 1;").Scan(&cloudLinks)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
LinksHandler(cloudLinks, resp)
|
||||||
|
// ai
|
||||||
|
var aiLinks []string
|
||||||
|
tx = l.svcCtx.DbEngin.Raw("SELECT GROUP_CONCAT(cluster_id SEPARATOR ',') as cluster_ids FROM task_ai WHERE deleted_at IS NULL GROUP BY task_id HAVING COUNT(*) > 1;").Scan(&aiLinks)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
LinksHandler(aiLinks, resp)
|
||||||
|
// vm
|
||||||
|
var vmLinks []string
|
||||||
|
tx = l.svcCtx.DbEngin.Raw("SELECT GROUP_CONCAT(cluster_id SEPARATOR ',') as cluster_ids FROM task_vm WHERE deleted_at IS NULL GROUP BY task_id HAVING COUNT(*) > 1;").Scan(&vmLinks)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
LinksHandler(vmLinks, resp)
|
||||||
|
|
||||||
|
// categories
|
||||||
|
tx = l.svcCtx.DbEngin.Raw("select tdi.item_text as name from t_dict_item tdi,t_dict td where td.dict_code = 'cluster_region_dict' and tdi.dict_id = td.id").Scan(&resp.Categories)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func LinksHandler(sources []string, resp *types.ScheduleSituationResp) {
|
||||||
|
for _, source := range sources {
|
||||||
|
links := strings.Split(source, ",")
|
||||||
|
|
||||||
|
for i := 1; i < len(links); i++ {
|
||||||
|
if links[i] != links[i-1] {
|
||||||
|
resp.Links = append(resp.Links, types.Link{Source: links[i], Target: links[i-1]})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5694,3 +5694,25 @@ type AdapterInfoResp struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ScheduleSituationResp struct {
|
||||||
|
Nodes []NodeRegion `json:"nodes"`
|
||||||
|
Links []Link `json:"links"`
|
||||||
|
Categories []Category `json:"categories"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type NodeRegion struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Category string `json:"category"`
|
||||||
|
Value int `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Link struct {
|
||||||
|
Source string `json:"source"`
|
||||||
|
Target string `json:"target"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Category struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue