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.

octopus.go 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package storeLink
  2. import (
  3. "context"
  4. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
  5. "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus"
  6. )
  7. type OctopusLink struct {
  8. ctx context.Context
  9. svcCtx *svc.ServiceContext
  10. platform string
  11. pageIndex int32
  12. pageSize int32
  13. }
  14. const (
  15. IMG_NAME_PREFIX = "oct_"
  16. IMG_VERSION_PREFIX = "version_"
  17. )
  18. func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, platform string) *OctopusLink {
  19. return &OctopusLink{ctx: ctx, svcCtx: svcCtx, platform: platform, pageIndex: 1, pageSize: 100}
  20. }
  21. func (o *OctopusLink) UploadImage(path string) (interface{}, error) {
  22. createReq := &octopus.CreateImageReq{
  23. Platform: o.platform,
  24. CreateImage: &octopus.CreateImage{
  25. SourceType: 1,
  26. //ImageName: IMG_NAME_PREFIX + utils.RandomString(5),
  27. //ImageVersion: IMG_VERSION_PREFIX + utils.RandomString(7),
  28. },
  29. }
  30. createResp, err := o.svcCtx.OctopusRpc.CreateImage(o.ctx, createReq)
  31. if err != nil {
  32. return nil, err
  33. }
  34. uploadReq := &octopus.UploadImageReq{
  35. Platform: o.platform,
  36. ImageId: createResp.Payload.ImageId,
  37. Params: &octopus.UploadImageParam{},
  38. }
  39. uploadResp, err := o.svcCtx.OctopusRpc.UploadImage(o.ctx, uploadReq)
  40. if err != nil {
  41. return nil, err
  42. }
  43. resp, err := ConvertType[octopus.UploadImageResp](uploadResp)
  44. if err != nil {
  45. return nil, err
  46. }
  47. return resp, nil
  48. }
  49. func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) {
  50. req := &octopus.DeleteImageReq{
  51. Platform: o.platform,
  52. ImageId: imageId,
  53. }
  54. resp, err := o.svcCtx.OctopusRpc.DeleteImage(o.ctx, req)
  55. if err != nil {
  56. return nil, err
  57. }
  58. deleteResp, err := ConvertType[octopus.DeleteImageResp](resp)
  59. if err != nil {
  60. return nil, err
  61. }
  62. return deleteResp, nil
  63. }
  64. func (o *OctopusLink) QueryImageList() (interface{}, error) {
  65. req := &octopus.GetUserImageListReq{
  66. Platform: o.platform,
  67. PageIndex: o.pageIndex,
  68. PageSize: o.pageSize,
  69. }
  70. resp, err := o.svcCtx.OctopusRpc.GetUserImageList(o.ctx, req)
  71. if err != nil {
  72. return nil, err
  73. }
  74. imgListResp, err := ConvertType[octopus.GetUserImageListResp](resp)
  75. if err != nil {
  76. return nil, err
  77. }
  78. return imgListResp, nil
  79. }
  80. func (o *OctopusLink) SubmitTask(imageId string, cmd string, envs []string) (interface{}, error) {
  81. req := &octopus.CreateTrainJobReq{
  82. Platform: o.platform,
  83. Params: &octopus.CreateTrainJobParam{},
  84. }
  85. resp, err := o.svcCtx.OctopusRpc.CreateTrainJob(o.ctx, req)
  86. if err != nil {
  87. return nil, err
  88. }
  89. submitResp, err := ConvertType[octopus.CreateTrainJobResp](resp)
  90. if err != nil {
  91. return nil, err
  92. }
  93. return submitResp, nil
  94. }
  95. func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) {
  96. req := &octopus.GetTrainJobReq{
  97. Platform: o.platform,
  98. Id: taskId,
  99. }
  100. resp, err := o.svcCtx.OctopusRpc.GetTrainJob(o.ctx, req)
  101. if err != nil {
  102. return nil, err
  103. }
  104. taskResp, err := ConvertType[octopus.GetTrainJobResp](resp)
  105. if err != nil {
  106. return nil, err
  107. }
  108. return taskResp, nil
  109. }
  110. func (o *OctopusLink) DeleteTask(taskId string) (interface{}, error) {
  111. req := &octopus.DeleteTrainJobReq{
  112. Platform: o.platform,
  113. JobIds: []string{taskId},
  114. }
  115. resp, err := o.svcCtx.OctopusRpc.DeleteTrainJob(o.ctx, req)
  116. if err != nil {
  117. return nil, err
  118. }
  119. deleteResp, err := ConvertType[octopus.DeleteTrainJobResp](resp)
  120. if err != nil {
  121. return nil, err
  122. }
  123. return deleteResp, nil
  124. }

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.