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.

stopallbydeploytaskidlogic.go 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package inference
  2. import (
  3. "context"
  4. "errors"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/storeLink"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  9. "strconv"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type StopAllByDeployTaskIdLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewStopAllByDeployTaskIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StopAllByDeployTaskIdLogic {
  18. return &StopAllByDeployTaskIdLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *StopAllByDeployTaskIdLogic) StopAllByDeployTaskId(req *types.StopAllByDeployTaskIdReq) (resp *types.StopAllByDeployTaskIdResp, err error) {
  25. resp = &types.StopAllByDeployTaskIdResp{}
  26. id, err := strconv.ParseInt(req.Id, 10, 64)
  27. list, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(id)
  28. if err != nil {
  29. return nil, err
  30. }
  31. for _, ins := range list {
  32. in, err := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].GetInferDeployInstance(l.ctx, ins.InstanceId)
  33. if err != nil {
  34. return nil, err
  35. }
  36. if checkStatus(in) {
  37. success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].StopInferDeployInstance(l.ctx, ins.InstanceId)
  38. if !success {
  39. return nil, errors.New(ins.InstanceName + " stop failed")
  40. }
  41. }
  42. }
  43. err = l.svcCtx.Scheduler.AiStorages.UpdateDeployTaskById(id)
  44. if err != nil {
  45. return nil, err
  46. }
  47. return resp, nil
  48. }
  49. func checkStatus(in *inference.DeployInstance) bool {
  50. switch in.ClusterType {
  51. case storeLink.TYPE_OCTOPUS:
  52. switch in.Status {
  53. case "running":
  54. return true
  55. default:
  56. return false
  57. }
  58. case storeLink.TYPE_MODELARTS:
  59. switch in.Status {
  60. case "running":
  61. return true
  62. default:
  63. return false
  64. }
  65. case storeLink.TYPE_SHUGUANGAI:
  66. switch in.Status {
  67. case "Running":
  68. return true
  69. default:
  70. return false
  71. }
  72. default:
  73. return false
  74. }
  75. }

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.