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.

containermetricslogic.go 2.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 cloud
  13. import (
  14. "context"
  15. "errors"
  16. "github.com/zeromicro/go-zero/core/logx"
  17. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/cloud"
  18. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  19. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  20. container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
  21. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  22. "k8s.io/apimachinery/pkg/util/json"
  23. "net/http"
  24. "strconv"
  25. )
  26. type ContainerMetricsLogic struct {
  27. logx.Logger
  28. ctx context.Context
  29. svcCtx *svc.ServiceContext
  30. }
  31. func NewContainerMetricsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContainerMetricsLogic {
  32. return &ContainerMetricsLogic{
  33. Logger: logx.WithContext(ctx),
  34. ctx: ctx,
  35. svcCtx: svcCtx,
  36. }
  37. }
  38. func (l *ContainerMetricsLogic) ContainerMetrics(req *container.MetricsParam) (resp interface{}, err error) {
  39. task := &types.TaskModel{}
  40. l.svcCtx.DbEngin.Table("task").Where("id", req.Id).Scan(&task)
  41. if task.Name == "" {
  42. return nil, errors.New("任务不存在")
  43. }
  44. taskCloud := models.TaskCloud{}
  45. l.svcCtx.DbEngin.Table("task_cloud").Where("task_id", req.Id).Scan(&taskCloud)
  46. if taskCloud.Name == "" {
  47. return nil, errors.New("通算任务不存在")
  48. }
  49. if taskCloud.BusinessCode != "" && taskCloud.BusinessCode != "null" {
  50. var eciRequestParam cloud.EciRequestParam
  51. err := json.Unmarshal([]byte(taskCloud.BusinessCode), &eciRequestParam)
  52. if err != nil {
  53. logx.Errorf("Failed to unmarshal BusinessCode: %v", err)
  54. return nil, err
  55. }
  56. req.Name = eciRequestParam.ContainerGroupId
  57. } else {
  58. req.Name = taskCloud.Name
  59. }
  60. req.ClusterId = strconv.FormatInt(taskCloud.ClusterId, 10)
  61. get, err := l.svcCtx.Cloud.ContainerMetrics(req.ClusterId, req)
  62. if err != nil {
  63. return nil, err
  64. }
  65. if get.Code != http.StatusOK {
  66. return nil, errors.New(get.Message)
  67. }
  68. resp = get.Data
  69. return resp, nil
  70. }

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.