130 lines
3.2 KiB
Go
130 lines
3.2 KiB
Go
package storeLink
|
|
|
|
import (
|
|
"context"
|
|
"github.com/pkg/errors"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus"
|
|
)
|
|
|
|
type Linkage interface {
|
|
UploadImage(path string) (interface{}, error)
|
|
DeleteImage(imageId string) (interface{}, error)
|
|
QueryImageList() (interface{}, error)
|
|
SubmitTask(imageId string, cmd string, envs []string) (interface{}, error)
|
|
QueryTask(taskId string) (interface{}, error)
|
|
DeleteTask(taskId string) (interface{}, error)
|
|
}
|
|
|
|
const (
|
|
COMMA = ","
|
|
)
|
|
|
|
var (
|
|
OctImgStatus = map[int32]string{
|
|
1: "未上传",
|
|
3: "制作完成",
|
|
4: "制作失败",
|
|
}
|
|
)
|
|
|
|
type StoreLink struct {
|
|
ILinkage Linkage
|
|
}
|
|
|
|
func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, partId int64) *StoreLink {
|
|
linkStruct := NewOctopusLink(ctx, svcCtx, "hanwuji")
|
|
return &StoreLink{ILinkage: linkStruct}
|
|
}
|
|
|
|
func ConvertType[T any](in *T) (interface{}, error) {
|
|
|
|
switch (interface{})(in).(type) {
|
|
case *octopus.UploadImageResp:
|
|
var resp types.UploadLinkImageResp
|
|
inresp := (interface{})(in).(*octopus.UploadImageResp)
|
|
resp.Success = inresp.Success
|
|
if !resp.Success {
|
|
resp.ErrorMsg = inresp.Error.Message
|
|
return resp, nil
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
case *octopus.GetUserImageListResp:
|
|
var resp types.GetLinkImageListResp
|
|
inresp := (interface{})(in).(*octopus.GetUserImageListResp)
|
|
resp.Success = inresp.Success
|
|
if !resp.Success {
|
|
resp.ErrorMsg = inresp.Error.Message
|
|
resp.Images = nil
|
|
return resp, nil
|
|
}
|
|
|
|
for _, v := range inresp.Payload.Images {
|
|
var image types.ImageSl
|
|
image.ImageId = v.Image.Id
|
|
image.ImageName = v.Image.ImageName
|
|
image.ImageStatus = OctImgStatus[v.Image.ImageStatus]
|
|
resp.Images = append(resp.Images, image)
|
|
}
|
|
return resp, nil
|
|
|
|
case *octopus.DeleteImageResp:
|
|
var resp types.DeleteLinkImageResp
|
|
inresp := (interface{})(in).(*octopus.DeleteImageResp)
|
|
resp.Success = inresp.Success
|
|
if !resp.Success {
|
|
resp.ErrorMsg = inresp.Error.Message
|
|
return resp, nil
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
case *octopus.CreateTrainJobResp:
|
|
var resp types.SubmitLinkTaskResp
|
|
inresp := (interface{})(in).(*octopus.CreateTrainJobResp)
|
|
resp.Success = inresp.Success
|
|
if !resp.Success {
|
|
resp.ErrorMsg = inresp.Error.Message
|
|
return resp, nil
|
|
}
|
|
|
|
resp.TaskId = inresp.Payload.JobId
|
|
|
|
return resp, nil
|
|
|
|
case *octopus.GetTrainJobResp:
|
|
var resp types.GetLinkTaskResp
|
|
inresp := (interface{})(in).(*octopus.GetTrainJobResp)
|
|
resp.Success = inresp.Success
|
|
if !resp.Success {
|
|
resp.ErrorMsg = inresp.Error.Message
|
|
return resp, nil
|
|
}
|
|
|
|
resp.Task.TaskId = inresp.Payload.TrainJob.Id
|
|
resp.Task.TaskName = inresp.Payload.TrainJob.Name
|
|
resp.Task.StartedAt = inresp.Payload.TrainJob.StartedAt
|
|
resp.Task.CompletedAt = inresp.Payload.TrainJob.CompletedAt
|
|
resp.Task.TaskStatus = inresp.Payload.TrainJob.Status
|
|
|
|
return resp, nil
|
|
|
|
case *octopus.DeleteTrainJobResp:
|
|
var resp types.DeleteLinkTaskResp
|
|
inresp := (interface{})(in).(*octopus.DeleteTrainJobResp)
|
|
resp.Success = inresp.Success
|
|
if !resp.Success {
|
|
resp.ErrorMsg = inresp.Error.Message
|
|
return resp, nil
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
default:
|
|
return nil, errors.New("type convert fail")
|
|
}
|
|
}
|