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.

createdeploytasklogic.go 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package inference
  2. import (
  3. "context"
  4. "errors"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
  6. "strconv"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type CreateDeployTaskLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewCreateDeployTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDeployTaskLogic {
  17. return &CreateDeployTaskLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *CreateDeployTaskLogic) CreateDeployTask(req *types.CreateDeployTaskReq) (resp *types.CreateDeployTaskResp, err error) {
  24. resp = &types.CreateDeployTaskResp{}
  25. if len(req.AdapterClusterMap) == 0 {
  26. return nil, errors.New("adapters are empty")
  27. }
  28. opt := &option.InferOption{
  29. TaskName: req.TaskName,
  30. ModelType: req.ModelType,
  31. ModelName: req.ModelName,
  32. Cmd: "",
  33. }
  34. taskId, err := l.svcCtx.Scheduler.AiStorages.SaveInferDeployTask(req.TaskName, req.ModelName, req.ModelType, req.TaskDesc)
  35. if err != nil {
  36. return nil, err
  37. }
  38. for aid, v := range req.AdapterClusterMap {
  39. for _, cid := range v {
  40. err = l.createDeployInstance(taskId, aid, cid, opt)
  41. if err != nil {
  42. return nil, err
  43. }
  44. }
  45. }
  46. return
  47. }
  48. func (l *CreateDeployTaskLogic) createDeployInstance(taskId int64, adapterId string, clusterId string, opt *option.InferOption) error {
  49. cmap, found := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[adapterId]
  50. if !found {
  51. return errors.New("adapterId not exist: " + adapterId)
  52. }
  53. iCluster, found := cmap[clusterId]
  54. if !found {
  55. return errors.New("clusterId not exist: " + clusterId)
  56. }
  57. insId, err := iCluster.CreateInferDeployInstance(l.ctx, opt)
  58. if err != nil {
  59. return err
  60. }
  61. aid, err := strconv.ParseInt(adapterId, 10, 64)
  62. if err != nil {
  63. return err
  64. }
  65. cid, err := strconv.ParseInt(clusterId, 10, 64)
  66. if err != nil {
  67. return err
  68. }
  69. adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(adapterId)
  70. if err != nil {
  71. return err
  72. }
  73. clusterName, err := l.svcCtx.Scheduler.AiStorages.GetClusterNameById(clusterId)
  74. if err != nil {
  75. return err
  76. }
  77. ins, err := iCluster.GetInferDeployInstance(l.ctx, insId)
  78. if err != nil {
  79. return err
  80. }
  81. _, err = l.svcCtx.Scheduler.AiStorages.SaveInferDeployInstance(taskId, ins.InstanceId, ins.InstanceName, aid, adapterName, cid, clusterName, ins.ModelName, ins.ModelType, ins.InferCard, ins.ClusterType)
  82. if err != nil {
  83. return err
  84. }
  85. return nil
  86. }

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.