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.

containercreatelogic.go 3.0 kB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
  20. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  21. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  22. cloud2 "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/cloud"
  23. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  24. "net/http"
  25. "time"
  26. )
  27. type ContainerCreateLogic struct {
  28. logx.Logger
  29. ctx context.Context
  30. svcCtx *svc.ServiceContext
  31. }
  32. func NewContainerCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContainerCreateLogic {
  33. return &ContainerCreateLogic{
  34. Logger: logx.WithContext(ctx),
  35. ctx: ctx,
  36. svcCtx: svcCtx,
  37. }
  38. }
  39. func (l *ContainerCreateLogic) ContainerCreate(req *container.CreateParam) (resp interface{}, err error) {
  40. param := &cloud.CreateParam{
  41. Name: req.Name,
  42. Description: req.Description,
  43. Port: req.Port,
  44. Cpu: req.Cpu,
  45. Memory: req.Memory,
  46. Image: req.Image,
  47. Args: req.Args,
  48. MountPath: req.MountPath,
  49. Envs: req.Envs,
  50. NodePort: req.NodePort,
  51. ContainerGroupName: req.ContainerGroupName,
  52. CreateParameter: req.ContainerCreateParameter,
  53. }
  54. create, err := l.svcCtx.Cloud.ContainerCreate(req.ClusterId, param)
  55. if err != nil {
  56. return nil, err
  57. }
  58. if create.Code != http.StatusOK {
  59. return nil, errors.New(create.Message)
  60. }
  61. // 构建主任务结构体
  62. taskModel := models.Task{
  63. Id: utils.GenSnowflakeID(),
  64. Status: constants.Saved,
  65. Description: req.Description,
  66. Name: req.Name,
  67. UserId: req.UserId,
  68. AdapterTypeDict: "0",
  69. CommitTime: time.Now(),
  70. }
  71. // 保存任务数据到数据库
  72. tx := l.svcCtx.DbEngin.Create(&taskModel)
  73. if tx.Error != nil {
  74. }
  75. var adapterId int64
  76. tx.Table("t_cluster").Select("adapter_id").Where("id=?", req.ClusterId).Find(&adapterId)
  77. // 构建cloud任务结构体
  78. cloudTaskModel := cloud2.TaskCloudModel{
  79. Id: utils.GenSnowflakeID(),
  80. TaskId: taskModel.Id,
  81. Name: req.Name,
  82. AdapterId: adapterId,
  83. Status: constants.Saved,
  84. Namespace: "default",
  85. UserId: req.UserId,
  86. }
  87. // 保存任务数据到数据库
  88. tx = l.svcCtx.DbEngin.Create(&cloudTaskModel)
  89. if tx.Error != nil {
  90. }
  91. resp = taskModel.Id
  92. return
  93. }

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.