- package storeLink
-
- import (
- "context"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
- "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus"
- )
-
- type OctopusLink struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- platform string
- pageIndex int32
- pageSize int32
- }
-
- const (
- IMG_NAME_PREFIX = "oct_"
- IMG_VERSION_PREFIX = "version_"
- )
-
- func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, platform string) *OctopusLink {
- return &OctopusLink{ctx: ctx, svcCtx: svcCtx, platform: platform, pageIndex: 1, pageSize: 100}
- }
-
- func (o *OctopusLink) UploadImage(path string) (interface{}, error) {
- createReq := &octopus.CreateImageReq{
- Platform: o.platform,
- CreateImage: &octopus.CreateImage{
- SourceType: 1,
- //ImageName: IMG_NAME_PREFIX + utils.RandomString(5),
- //ImageVersion: IMG_VERSION_PREFIX + utils.RandomString(7),
- },
- }
- createResp, err := o.svcCtx.OctopusRpc.CreateImage(o.ctx, createReq)
- if err != nil {
- return nil, err
- }
- uploadReq := &octopus.UploadImageReq{
- Platform: o.platform,
- ImageId: createResp.Payload.ImageId,
- Params: &octopus.UploadImageParam{},
- }
- uploadResp, err := o.svcCtx.OctopusRpc.UploadImage(o.ctx, uploadReq)
- if err != nil {
- return nil, err
- }
-
- resp, err := ConvertType[octopus.UploadImageResp](uploadResp)
- if err != nil {
- return nil, err
- }
-
- return resp, nil
- }
-
- func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) {
- req := &octopus.DeleteImageReq{
- Platform: o.platform,
- ImageId: imageId,
- }
- resp, err := o.svcCtx.OctopusRpc.DeleteImage(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- deleteResp, err := ConvertType[octopus.DeleteImageResp](resp)
- if err != nil {
- return nil, err
- }
-
- return deleteResp, nil
- }
-
- func (o *OctopusLink) QueryImageList() (interface{}, error) {
- req := &octopus.GetUserImageListReq{
- Platform: o.platform,
- PageIndex: o.pageIndex,
- PageSize: o.pageSize,
- }
- resp, err := o.svcCtx.OctopusRpc.GetUserImageList(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- imgListResp, err := ConvertType[octopus.GetUserImageListResp](resp)
- if err != nil {
- return nil, err
- }
-
- return imgListResp, nil
- }
-
- func (o *OctopusLink) SubmitTask(imageId string, cmd string, envs []string) (interface{}, error) {
- req := &octopus.CreateTrainJobReq{
- Platform: o.platform,
- Params: &octopus.CreateTrainJobParam{},
- }
- resp, err := o.svcCtx.OctopusRpc.CreateTrainJob(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- submitResp, err := ConvertType[octopus.CreateTrainJobResp](resp)
- if err != nil {
- return nil, err
- }
-
- return submitResp, nil
- }
-
- func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) {
- req := &octopus.GetTrainJobReq{
- Platform: o.platform,
- Id: taskId,
- }
- resp, err := o.svcCtx.OctopusRpc.GetTrainJob(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- taskResp, err := ConvertType[octopus.GetTrainJobResp](resp)
- if err != nil {
- return nil, err
- }
-
- return taskResp, nil
- }
-
- func (o *OctopusLink) DeleteTask(taskId string) (interface{}, error) {
- req := &octopus.DeleteTrainJobReq{
- Platform: o.platform,
- JobIds: []string{taskId},
- }
- resp, err := o.svcCtx.OctopusRpc.DeleteTrainJob(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- deleteResp, err := ConvertType[octopus.DeleteTrainJobResp](resp)
- if err != nil {
- return nil, err
- }
-
- return deleteResp, nil
- }
|