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.

getclustersumlogic.go 2.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package adapters
  2. import (
  3. "context"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. )
  8. type GetClusterSumLogic struct {
  9. logx.Logger
  10. ctx context.Context
  11. svcCtx *svc.ServiceContext
  12. }
  13. func NewGetClusterSumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClusterSumLogic {
  14. return &GetClusterSumLogic{
  15. Logger: logx.WithContext(ctx),
  16. ctx: ctx,
  17. svcCtx: svcCtx,
  18. }
  19. }
  20. func (l *GetClusterSumLogic) GetClusterSum(req *types.ClusterSumReq) (resp *types.ClusterSumReqResp, err error) {
  21. // todo: add your logic here and delete this line
  22. resp = &types.ClusterSumReqResp{}
  23. var AdapterSum int //
  24. var podSum int //
  25. var vmSum int //
  26. var TaskSum int //
  27. //
  28. sqlStr := "SELECT COUNT(*) FROM `t_adapter` t where t.type ='0' and deleted_at is null"
  29. tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&AdapterSum)
  30. if tx.Error != nil {
  31. logx.Error(err)
  32. return nil, tx.Error
  33. }
  34. //vm
  35. sqlStrVm := "SELECT COUNT(*) FROM `t_adapter` t left join t_cluster tc on t.id=tc.adapter_id where t.type = '0' and t.resource_type='02' and tc.deleted_at is null"
  36. txClusterVm := l.svcCtx.DbEngin.Raw(sqlStrVm).Scan(&vmSum)
  37. if txClusterVm.Error != nil {
  38. logx.Error(err)
  39. return nil, txClusterVm.Error
  40. }
  41. //pod
  42. sqlStrPod := "SELECT COUNT(*) FROM `t_adapter` t left join t_cluster tc on t.id=tc.adapter_id where t.type = '0' and t.resource_type='02' and tc.deleted_at is null"
  43. txClusterPod := l.svcCtx.DbEngin.Raw(sqlStrPod).Scan(&podSum)
  44. if txClusterPod.Error != nil {
  45. logx.Error(err)
  46. return nil, txClusterPod.Error
  47. }
  48. //
  49. sqlStrTask := "SELECT COUNT(*) FROM `task` where adapter_type_dict = '0'"
  50. txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&TaskSum)
  51. if txTask.Error != nil {
  52. logx.Error(err)
  53. return nil, txTask.Error
  54. }
  55. resp.TaskSum = TaskSum
  56. resp.VmSum = vmSum
  57. resp.PodSum = podSum
  58. resp.AdapterSum = AdapterSum
  59. return resp, nil
  60. }

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.