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.

resourcelogic.go 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package hpc
  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 ResourceLogic struct {
  9. logx.Logger
  10. ctx context.Context
  11. svcCtx *svc.ServiceContext
  12. }
  13. func NewResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResourceLogic {
  14. return &ResourceLogic{
  15. Logger: logx.WithContext(ctx),
  16. ctx: ctx,
  17. svcCtx: svcCtx,
  18. }
  19. }
  20. func (l *ResourceLogic) Resource(req *types.HpcResourceReq) (resp *types.HpcResourceResp, err error) {
  21. type hpcResourceOV struct {
  22. CpuAvail float64 `json:"cpu_avail"`
  23. CpuTotal float64 `json:"cpu_total"`
  24. MemAvail float64 `json:"mem_avail"`
  25. MemTotal float64 `json:"mem_total"`
  26. DiskAvail float64 `json:"disk_avail"`
  27. DiskTotal float64 `json:"disk_total"`
  28. GpuAvail float64 `json:"gpu_avail"`
  29. GpuTotal float64 `json:"gpu_total"`
  30. }
  31. var hrov hpcResourceOV
  32. l.svcCtx.DbEngin.Raw("SELECT sum(cpu_avail) as cpu_avail,sum(cpu_total) as cpu_total,sum(mem_avail) as mem_avail,sum(mem_total) as mem_total,sum(disk_avail) as disk_avail,sum(disk_total) as disk_total,sum(gpu_avail) as gpu_avail,sum(gpu_total) as gpu_total FROM t_cluster_resource where cluster_type = 2").Scan(&hrov)
  33. hpcResource := types.HPCResource{
  34. GPUCardsTotal: hrov.GpuTotal,
  35. CPUCoresTotal: hrov.CpuTotal,
  36. RAMTotal: hrov.MemTotal,
  37. GPUCardsUsed: hrov.GpuTotal - hrov.GpuAvail,
  38. CPUCoresUsed: hrov.CpuTotal - hrov.CpuAvail,
  39. RAMUsed: hrov.MemTotal - hrov.MemAvail,
  40. GPURate: (hrov.GpuTotal - hrov.GpuAvail) / hrov.GpuTotal,
  41. CPURate: (hrov.CpuTotal - hrov.CpuAvail) / hrov.CpuTotal,
  42. RAMRate: (hrov.MemTotal - hrov.MemAvail) / hrov.MemTotal,
  43. }
  44. resp = &types.HpcResourceResp{
  45. Code: 200,
  46. Msg: "success",
  47. Data: hpcResource,
  48. }
  49. return resp, nil
  50. }

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.