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.

containerloglogic.go 2.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 ContainerLogLogic struct {
  27. logx.Logger
  28. ctx context.Context
  29. svcCtx *svc.ServiceContext
  30. }
  31. func NewContainerLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContainerGetLogic {
  32. return &ContainerGetLogic{
  33. Logger: logx.WithContext(ctx),
  34. ctx: ctx,
  35. svcCtx: svcCtx,
  36. }
  37. }
  38. func (l *ContainerGetLogic) ContainerLog(req *container.LogParam) (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. eciLogParam := cloud.EciLogParam{
  57. ContainerGroupId: eciRequestParam.ContainerGroupId,
  58. }
  59. req.ContainerLogParameter = eciLogParam
  60. }
  61. req.Name = taskCloud.Name
  62. req.ClusterId = strconv.FormatInt(taskCloud.ClusterId, 10)
  63. get, err := l.svcCtx.Cloud.ContainerLog(req.ClusterId, req)
  64. if err != nil {
  65. return nil, err
  66. }
  67. if get.Code != http.StatusOK {
  68. return nil, errors.New(get.Message)
  69. }
  70. resp = get.Data
  71. return resp, nil
  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.