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.

getcomputilitystatisticslogic.go 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. Copyright (c) [2023] [pcm]
  3. [pcm-coordinator] is licensed under Mulan PSL v2.
  4. You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. You may obtain a copy of Mulan PSL v2 at:
  6. http://license.coscl.org.cn/MulanPSL2
  7. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. See the Mulan PSL v2 for more details.
  11. */
  12. package core
  13. import (
  14. "context"
  15. "fmt"
  16. "strconv"
  17. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  18. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  19. "github.com/zeromicro/go-zero/core/logx"
  20. )
  21. type GetComputilityStatisticsLogic struct {
  22. logx.Logger
  23. ctx context.Context
  24. svcCtx *svc.ServiceContext
  25. }
  26. func NewGetComputilityStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetComputilityStatisticsLogic {
  27. return &GetComputilityStatisticsLogic{
  28. Logger: logx.WithContext(ctx),
  29. ctx: ctx,
  30. svcCtx: svcCtx,
  31. }
  32. }
  33. func (l *GetComputilityStatisticsLogic) GetComputilityStatistics() (resp *types.ComputilityStatisticsResp, err error) {
  34. // todo: add your logic here and delete this line
  35. resp = &types.ComputilityStatisticsResp{}
  36. var computilityStatistics types.ComputilityStatistics
  37. var domainSum int64 //所有域的总和
  38. var AiFlopsNum float64 //所有域的总和
  39. var K8sFlopsNum float64 //所有域的总和
  40. var aiClusterSum int64 //所有域的总和
  41. var hpcClusterSum int64 //所有域的总和
  42. var PCClusterSum int64 //所有域的总和
  43. var ClusterSum int64 //所有域的总和
  44. //算力中心总数(计算域):包括所有云算域,智算域,超算域以及鹏城返回的所有域的总和
  45. sqlStr := "select count(*) as domainSum from `pcm`.domain_resource t where t.connection_state = 3 OR t.domain_source=0"
  46. tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&domainSum)
  47. if tx.Error != nil {
  48. logx.Error(err)
  49. return nil, tx.Error
  50. }
  51. computilityStatistics.DomainSum = domainSum
  52. //统计集群
  53. clusterStr := "select count(*) from `joint_domain`.domain_cluster"
  54. tc := l.svcCtx.DbEngin.Raw(clusterStr).Scan(&ClusterSum)
  55. if tc.Error != nil {
  56. logx.Error(err)
  57. return nil, tc.Error
  58. }
  59. //智算算力总和
  60. aiFlopsStr := "select sum(t.flops) as flopsNum from `pcm`.domain_resource t"
  61. tf := l.svcCtx.DbEngin.Raw(aiFlopsStr).Scan(&AiFlopsNum)
  62. if tf.Error != nil {
  63. logx.Error(err)
  64. return nil, tf.Error
  65. }
  66. //云算算力总和 SELECT sum(t.flops) FROM `resources` t
  67. k8sFlopsStr := "SELECT sum(t.flops) as k8sFlopsNum FROM `joint_domain`.`resources` t"
  68. tk := l.svcCtx.DbEngin.Raw(k8sFlopsStr).Scan(&K8sFlopsNum)
  69. if tk.Error != nil {
  70. logx.Error(err)
  71. return nil, tk.Error
  72. }
  73. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", K8sFlopsNum/1000000+AiFlopsNum), 64)
  74. computilityStatistics.TotalComputility = value
  75. //智算集群数
  76. aiClusterStr := "select count(*) as aiClusterSum from `pcm`.ai_cluster"
  77. ts := l.svcCtx.DbEngin.Raw(aiClusterStr).Scan(&aiClusterSum)
  78. if ts.Error != nil {
  79. logx.Error(err)
  80. return nil, ts.Error
  81. }
  82. //云算集群数
  83. hpcClusterStr := "select count(*) as hpcClusterSum from `pcm`.hpc_cluster"
  84. th := l.svcCtx.DbEngin.Raw(hpcClusterStr).Scan(&hpcClusterSum)
  85. if th.Error != nil {
  86. logx.Error(err)
  87. return nil, th.Error
  88. }
  89. //鹏城集群数
  90. PCClusterStr := "select count(*) as PCClusterSum from `pcm`.domain_resource t where t.connection_state = 3 "
  91. tp := l.svcCtx.DbEngin.Raw(PCClusterStr).Scan(&PCClusterSum)
  92. if tp.Error != nil {
  93. logx.Error(err)
  94. return nil, tp.Error
  95. }
  96. computilityStatistics.ClusterNum = ClusterSum + PCClusterSum + hpcClusterSum + aiClusterSum
  97. resp.ComputilityStatistics = computilityStatistics
  98. resp.Code = 200
  99. resp.Msg = "Success"
  100. return resp, nil
  101. }

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.