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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. resp = &types.ScheduleSituationResp{}
  23. // node region
  24. 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)
  25. if tx.Error != nil {
  26. return nil, tx.Error
  27. }
  28. // hpc
  29. var hpcLinks []string
  30. tx = l.svcCtx.DbEngin.Raw("SELECT distinct GROUP_CONCAT( distinct cluster_id SEPARATOR ',') as cluster_ids FROM task_hpc WHERE deleted_at IS NULL GROUP BY task_id HAVING COUNT(*) > 1;").Scan(&hpcLinks)
  31. if tx.Error != nil {
  32. return nil, tx.Error
  33. }
  34. LinksHandler(hpcLinks, resp)
  35. // cloud
  36. var cloudLinks []string
  37. tx = l.svcCtx.DbEngin.Raw("SELECT distinct GROUP_CONCAT(distinct cluster_id SEPARATOR ',') as cluster_ids FROM task_cloud WHERE deleted_at IS NULL GROUP BY task_id HAVING COUNT(*) > 1;").Scan(&cloudLinks)
  38. if tx.Error != nil {
  39. return nil, tx.Error
  40. }
  41. LinksHandler(cloudLinks, resp)
  42. // ai
  43. var aiLinks []string
  44. tx = l.svcCtx.DbEngin.Raw("SELECT distinct GROUP_CONCAT(distinct cluster_id SEPARATOR ',') as cluster_ids FROM task_ai WHERE deleted_at IS NULL GROUP BY task_id HAVING COUNT(*) > 1;").Scan(&aiLinks)
  45. if tx.Error != nil {
  46. return nil, tx.Error
  47. }
  48. LinksHandler(aiLinks, resp)
  49. // vm
  50. var vmLinks []string
  51. tx = l.svcCtx.DbEngin.Raw("SELECT distinct GROUP_CONCAT(distinct cluster_id SEPARATOR ',') as cluster_ids FROM task_vm WHERE deleted_at IS NULL GROUP BY task_id HAVING COUNT(*) > 1;").Scan(&vmLinks)
  52. if tx.Error != nil {
  53. return nil, tx.Error
  54. }
  55. LinksHandler(vmLinks, resp)
  56. // categories
  57. 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)
  58. if tx.Error != nil {
  59. return nil, tx.Error
  60. }
  61. return resp, nil
  62. }
  63. func LinksHandler(sources []string, resp *types.ScheduleSituationResp) {
  64. for _, source := range sources {
  65. links := strings.Split(source, ",")
  66. for i := 1; i < len(links); i++ {
  67. if links[i] != links[i-1] {
  68. resp.Links = append(resp.Links, types.Link{Source: links[i], Target: links[i-1]})
  69. }
  70. }
  71. }
  72. }

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.