You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

schedulesituationlogic.go 3.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package monitoring
  2. import (
  3. "context"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  6. "strings"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. type ScheduleSituationLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewScheduleSituationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleSituationLogic {
  15. return &ScheduleSituationLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. }
  20. }
  21. func (l *ScheduleSituationLogic) ScheduleSituation() (resp *types.ScheduleSituationResp, err error) {
  22. // todo: add your logic here and delete this line
  23. resp = &types.ScheduleSituationResp{}
  24. // node region
  25. 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)
  26. if tx.Error != nil {
  27. return nil, tx.Error
  28. }
  29. // hpc
  30. var hpcLinks []string
  31. 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)
  32. if tx.Error != nil {
  33. return nil, tx.Error
  34. }
  35. LinksHandler(hpcLinks, resp)
  36. // cloud
  37. var cloudLinks []string
  38. 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)
  39. if tx.Error != nil {
  40. return nil, tx.Error
  41. }
  42. LinksHandler(cloudLinks, resp)
  43. // ai
  44. var aiLinks []string
  45. 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)
  46. if tx.Error != nil {
  47. return nil, tx.Error
  48. }
  49. LinksHandler(aiLinks, resp)
  50. // vm
  51. var vmLinks []string
  52. 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)
  53. if tx.Error != nil {
  54. return nil, tx.Error
  55. }
  56. LinksHandler(vmLinks, resp)
  57. // categories
  58. 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)
  59. if tx.Error != nil {
  60. return nil, tx.Error
  61. }
  62. return resp, nil
  63. }
  64. func LinksHandler(sources []string, resp *types.ScheduleSituationResp) {
  65. for _, source := range sources {
  66. links := strings.Split(source, ",")
  67. for i := 1; i < len(links); i++ {
  68. if links[i] != links[i-1] {
  69. resp.Links = append(resp.Links, types.Link{Source: links[i], Target: links[i-1]})
  70. }
  71. }
  72. }
  73. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.