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.

containerdeletelogic.go 2.5 kB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
2 months ago
2 months ago
3 months ago
2 months ago
3 months ago
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 ContainerDeleteLogic struct {
  27. logx.Logger
  28. ctx context.Context
  29. svcCtx *svc.ServiceContext
  30. }
  31. func NewContainerDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContainerDeleteLogic {
  32. return &ContainerDeleteLogic{
  33. Logger: logx.WithContext(ctx),
  34. ctx: ctx,
  35. svcCtx: svcCtx,
  36. }
  37. }
  38. func (l *ContainerDeleteLogic) ContainerDelete(req *container.DeleteParam) (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. create, err := l.svcCtx.Cloud.ContainerDelete(strconv.FormatInt(taskCloud.ClusterId, 10), req)
  62. if err != nil {
  63. return nil, err
  64. }
  65. if create.Code != http.StatusOK {
  66. return nil, errors.New(create.Message)
  67. }
  68. taskCloud.Status = "Deleted"
  69. l.svcCtx.DbEngin.Updates(taskCloud)
  70. task.Status = "Deleted"
  71. l.svcCtx.DbEngin.Updates(task)
  72. return
  73. }

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.