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.

storeLink.go 29 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. /*
  2. Copyright (c) [2023] [pcm]
  3. [pcm-coordinator] is licensed under Mulan PSL v2.
  4. You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. You may obtain a copy of Mulan PSL v2 at:
  6. http://license.coscl.org.cn/MulanPSL2
  7. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. See the Mulan PSL v2 for more details.
  11. */
  12. package storeLink
  13. import (
  14. "context"
  15. "fmt"
  16. "github.com/pkg/errors"
  17. "gitlink.org.cn/JointCloud/pcm-ac/hpcAC"
  18. hpcacclient "gitlink.org.cn/JointCloud/pcm-ac/hpcacclient"
  19. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/common"
  20. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
  21. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  22. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  23. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/timeutils"
  24. "gitlink.org.cn/JointCloud/pcm-modelarts/client/imagesservice"
  25. "gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice"
  26. "gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
  27. "gitlink.org.cn/JointCloud/pcm-octopus/octopus"
  28. "gitlink.org.cn/JointCloud/pcm-octopus/octopusclient"
  29. "gorm.io/gorm"
  30. "strings"
  31. "sync"
  32. )
  33. type Linkage interface {
  34. UploadImage(ctx context.Context, path string) (interface{}, error)
  35. DeleteImage(ctx context.Context, imageId string) (interface{}, error)
  36. QueryImageList(ctx context.Context) (interface{}, error)
  37. SubmitTask(ctx context.Context, imageId string, cmd string, envs []string, params []string, resourceId string, datasetsId string, algorithmId string, aiType string) (interface{}, error)
  38. QueryTask(ctx context.Context, taskId string) (interface{}, error)
  39. QuerySpecs(ctx context.Context) (interface{}, error)
  40. DeleteTask(ctx context.Context, taskId string) (interface{}, error)
  41. }
  42. const (
  43. COLON = ":"
  44. PY_PARAM_PREFIX = "--"
  45. SPACE = " "
  46. UNDERSCORE = "_"
  47. EQUAL = "="
  48. DASH = "-"
  49. FORWARD_SLASH = "/"
  50. COMMA = ","
  51. STAR = "*"
  52. TYPE_OCTOPUS = "1"
  53. TYPE_MODELARTS = "2"
  54. TYPE_SHUGUANGAI = "3"
  55. TYPE_SHUGUANGHPC = "4"
  56. OCTOPUS = "Octopus"
  57. MODELARTS = "Modelarts"
  58. SHUGUANGAI = "ShuguangAi"
  59. SHUGUANGHPC = "ShuguangHpc"
  60. CPU = "cpu"
  61. GPU = "gpu"
  62. NPU = "npu"
  63. CARD = "computeCard"
  64. PYTORCH_TASK = "pytorch"
  65. TENSORFLOW_TASK = "tensorflow"
  66. DEPLOY_INSTANCE_PREFIEX = "infer"
  67. )
  68. var (
  69. Datasets = []string{"mnist", "cifar10"}
  70. AlgorithmsForDatasets = map[string][]string{
  71. "mnist": {"fcn"},
  72. "cifar10": {"cnn"},
  73. }
  74. OctImgStatus = map[int32]string{
  75. 1: "未上传",
  76. 3: "制作完成",
  77. 4: "制作失败",
  78. }
  79. ModelTypeMap = map[string][]string{
  80. "image_classification": {"imagenet_resnet50"},
  81. "text_to_text": {"ChatGLM-6B"},
  82. "image_to_text": {"blip-image-captioning-base"},
  83. "text_to_image": {"stable-diffusion-xl-base-1.0"},
  84. }
  85. AITYPE = map[string]string{
  86. "1": OCTOPUS,
  87. "2": MODELARTS,
  88. "3": SHUGUANGAI,
  89. "4": SHUGUANGHPC,
  90. }
  91. resourceTypes = []string{CARD}
  92. taskTypes = []string{PYTORCH_TASK}
  93. ERROR_RESP_EMPTY = errors.New("resp empty error")
  94. ERROR_CONVERT_EMPTY = errors.New("convert empty error")
  95. )
  96. type StoreLink struct {
  97. ILinkage Linkage
  98. }
  99. func NewStoreLink(octopusRpc octopusclient.Octopus, modelArtsRpc modelartsservice.ModelArtsService, modelArtsImgRpc imagesservice.ImagesService, aCRpc hpcacclient.HpcAC, participant *models.StorelinkCenter) *StoreLink {
  100. switch participant.Type {
  101. case TYPE_OCTOPUS:
  102. linkStruct := NewOctopusLink(octopusRpc, participant.Name, participant.Id)
  103. return &StoreLink{ILinkage: linkStruct}
  104. case TYPE_MODELARTS:
  105. linkStruct := NewModelArtsLink(modelArtsRpc, modelArtsImgRpc, participant.Name, participant.Id, "")
  106. return &StoreLink{ILinkage: linkStruct}
  107. case TYPE_SHUGUANGAI:
  108. linkStruct := NewShuguangAi(aCRpc, participant.Name, participant.Id)
  109. return &StoreLink{ILinkage: linkStruct}
  110. case TYPE_SHUGUANGHPC:
  111. linkStruct := NewShuguangHpc(aCRpc, participant.Name, participant.Id)
  112. return &StoreLink{ILinkage: linkStruct}
  113. default:
  114. return nil
  115. }
  116. }
  117. func GetParticipants(dbEngin *gorm.DB) []*models.StorelinkCenter {
  118. var participants []*models.StorelinkCenter
  119. dbEngin.Raw("select * from storelink_center").Scan(&participants)
  120. return participants
  121. }
  122. func GetParticipantById(partId int64, dbEngin *gorm.DB) *models.StorelinkCenter {
  123. var participant models.StorelinkCenter
  124. dbEngin.Raw("select * from storelink_center where id = ?", partId).Scan(&participant)
  125. return &participant
  126. }
  127. func GetResourceTypes() []string {
  128. return resourceTypes
  129. }
  130. func GetModelTypes() []string {
  131. var mTypes []string
  132. for k, _ := range ModelTypeMap {
  133. mTypes = append(mTypes, k)
  134. }
  135. return mTypes
  136. }
  137. func GetModelNamesByType(t string) ([]string, error) {
  138. _, ok := ModelTypeMap[t]
  139. if !ok {
  140. return nil, errors.New("model type does not exist")
  141. }
  142. return ModelTypeMap[t], nil
  143. }
  144. func GetDatasetsNames(ctx context.Context, collectorMap map[string]collector.AiCollector) ([]string, error) {
  145. return Datasets, nil
  146. }
  147. func GetDatasetsNamesSync(ctx context.Context, collectorMap map[string]collector.AiCollector) ([]string, error) {
  148. var wg sync.WaitGroup
  149. var errCh = make(chan interface{}, len(collectorMap))
  150. var errs []interface{}
  151. var names []string
  152. var mu sync.Mutex
  153. colMap := collectorMap
  154. for s, col := range colMap {
  155. wg.Add(1)
  156. c := col
  157. id := s
  158. go func() {
  159. var ns []string
  160. specs, err := c.GetDatasetsSpecs(ctx)
  161. if err != nil {
  162. e := struct {
  163. err error
  164. clusterId string
  165. }{
  166. err: err,
  167. clusterId: id,
  168. }
  169. errCh <- e
  170. wg.Done()
  171. return
  172. }
  173. for _, spec := range specs {
  174. ns = append(ns, spec.Name)
  175. }
  176. if len(ns) == 0 {
  177. wg.Done()
  178. return
  179. }
  180. mu.Lock()
  181. if len(names) == 0 {
  182. names = ns
  183. wg.Done()
  184. mu.Unlock()
  185. return
  186. }
  187. names = common.IntersectString(names, ns)
  188. wg.Done()
  189. mu.Unlock()
  190. }()
  191. }
  192. wg.Wait()
  193. close(errCh)
  194. if len(errs) == len(colMap) {
  195. return nil, errors.New("get DatasetsNames failed")
  196. }
  197. for e := range errCh {
  198. errs = append(errs, e)
  199. }
  200. if len(errs) != 0 {
  201. var msg string
  202. for _, err := range errs {
  203. e := (err).(struct {
  204. err error
  205. clusterId string
  206. })
  207. msg += fmt.Sprintf("clusterId: %v , error: %v \n", e.clusterId, e.err.Error())
  208. }
  209. return nil, errors.New(msg)
  210. }
  211. names = common.RemoveDuplicates(names)
  212. return names, nil
  213. }
  214. func GetAlgorithms(ctx context.Context, collectorMap map[string]collector.AiCollector, resourceType string, taskType string, dataset string) ([]string, error) {
  215. algorithm := AlgorithmsForDatasets[dataset]
  216. if len(algorithm) != 0 {
  217. return algorithm, nil
  218. }
  219. return nil, errors.New("not found")
  220. }
  221. func GetAlgorithmsSync(ctx context.Context, collectorMap map[string]collector.AiCollector, resourceType string, taskType string, dataset string) ([]string, error) {
  222. var names []string
  223. var wg sync.WaitGroup
  224. var errCh = make(chan interface{}, len(collectorMap))
  225. var errs []interface{}
  226. var mu sync.Mutex
  227. colMap := collectorMap
  228. for s, col := range colMap {
  229. wg.Add(1)
  230. c := col
  231. id := s
  232. go func() {
  233. var ns []string
  234. algorithms, err := c.GetAlgorithms(ctx)
  235. if err != nil {
  236. e := struct {
  237. err error
  238. clusterId string
  239. }{
  240. err: err,
  241. clusterId: id,
  242. }
  243. errCh <- e
  244. wg.Done()
  245. return
  246. }
  247. for _, algorithm := range algorithms {
  248. if algorithm.TaskType != taskType {
  249. continue
  250. }
  251. switch algorithm.Platform {
  252. case OCTOPUS:
  253. splitns := strings.Split(algorithm.Name, UNDERSCORE)
  254. if dataset != splitns[0] || len(splitns) == 1 {
  255. continue
  256. }
  257. ns = append(ns, splitns[1])
  258. case SHUGUANGAI:
  259. splitns := strings.Split(algorithm.Name, DASH)
  260. if dataset != splitns[0] || len(splitns) == 1 {
  261. continue
  262. }
  263. ns = append(ns, splitns[1])
  264. }
  265. }
  266. if len(ns) == 0 {
  267. wg.Done()
  268. return
  269. }
  270. mu.Lock()
  271. if len(names) == 0 {
  272. names = ns
  273. wg.Done()
  274. mu.Unlock()
  275. return
  276. }
  277. names = common.IntersectString(names, ns)
  278. wg.Done()
  279. mu.Unlock()
  280. }()
  281. }
  282. wg.Wait()
  283. close(errCh)
  284. for e := range errCh {
  285. errs = append(errs, e)
  286. }
  287. if len(errs) == len(colMap) {
  288. return nil, errors.New("get Algorithms failed")
  289. }
  290. if len(errs) != 0 {
  291. var msg string
  292. for _, err := range errs {
  293. e := (err).(struct {
  294. err error
  295. clusterId string
  296. })
  297. msg += fmt.Sprintf("clusterId: %v , error: %v \n", e.clusterId, e.err.Error())
  298. }
  299. return nil, errors.New(msg)
  300. }
  301. names = common.RemoveDuplicates(names)
  302. return names, nil
  303. }
  304. func GetTaskTypes() []string {
  305. return taskTypes
  306. }
  307. func ConvertType(in interface{}, out interface{}, participant *models.StorelinkCenter) (interface{}, error) {
  308. switch (interface{})(in).(type) {
  309. case *types.GetResourceSpecsResp:
  310. return in, nil
  311. case *octopus.UploadImageResp:
  312. inresp := (interface{})(in).(*octopus.UploadImageResp)
  313. switch (interface{})(out).(type) {
  314. case *types.UploadLinkImageResp:
  315. resp := (interface{})(out).(*types.UploadLinkImageResp)
  316. resp.Success = inresp.Success
  317. if !resp.Success {
  318. resp.ErrorMsg = inresp.Error.Message
  319. return resp, nil
  320. }
  321. return resp, nil
  322. }
  323. return nil, nil
  324. case *octopus.DeleteImageResp:
  325. inresp := (interface{})(in).(*octopus.DeleteImageResp)
  326. switch (interface{})(out).(type) {
  327. case *types.DeleteLinkImageResp:
  328. resp := (interface{})(out).(*types.DeleteLinkImageResp)
  329. resp.Success = inresp.Success
  330. if !resp.Success {
  331. resp.ErrorMsg = inresp.Error.Message
  332. return resp, nil
  333. }
  334. return resp, nil
  335. }
  336. return nil, nil
  337. case *octopus.GetUserImageListResp:
  338. inresp := (interface{})(in).(*octopus.GetUserImageListResp)
  339. switch (interface{})(out).(type) {
  340. case *types.GetLinkImageListResp:
  341. resp := (interface{})(out).(*types.GetLinkImageListResp)
  342. resp.Success = inresp.Success
  343. if !resp.Success {
  344. resp.ErrorMsg = inresp.Error.Message
  345. resp.Images = nil
  346. return resp, nil
  347. }
  348. for _, v := range inresp.Payload.Images {
  349. var image types.ImageSl
  350. image.ImageId = v.Image.Id
  351. image.ImageName = v.Image.ImageName
  352. image.ImageStatus = OctImgStatus[v.Image.ImageStatus]
  353. resp.Images = append(resp.Images, &image)
  354. }
  355. return resp, nil
  356. }
  357. return nil, nil
  358. case *modelarts.ListReposDetailsResp:
  359. inresp := (interface{})(in).(*modelarts.ListReposDetailsResp)
  360. switch (interface{})(out).(type) {
  361. case *types.GetLinkImageListResp:
  362. resp := (interface{})(out).(*types.GetLinkImageListResp)
  363. if inresp.Errors != nil {
  364. resp.Success = false
  365. resp.ErrorMsg = inresp.Errors[0].ErrorMessage
  366. resp.Images = nil
  367. return resp, nil
  368. }
  369. resp.Success = true
  370. for _, v := range inresp.Items {
  371. for _, r := range v.Tags {
  372. var image types.ImageSl
  373. image.ImageId = v.Namespace + "/" + v.Name + ":" + r
  374. image.ImageName = v.Name
  375. image.ImageStatus = "created"
  376. resp.Images = append(resp.Images, &image)
  377. }
  378. }
  379. return resp, nil
  380. }
  381. return nil, nil
  382. case *hpcAC.GetImageListAiResp:
  383. inresp := (interface{})(in).(*hpcAC.GetImageListAiResp)
  384. switch (interface{})(out).(type) {
  385. case *types.GetLinkImageListResp:
  386. resp := (interface{})(out).(*types.GetLinkImageListResp)
  387. if inresp.Code == "0" {
  388. resp.Success = true
  389. for _, img := range inresp.Data {
  390. var image types.ImageSl
  391. image.ImageId = img.ImageId
  392. image.ImageName = img.Version
  393. image.ImageStatus = "created"
  394. resp.Images = append(resp.Images, &image)
  395. }
  396. } else {
  397. resp.Success = false
  398. resp.ErrorMsg = inresp.Msg
  399. resp.Images = nil
  400. }
  401. return resp, nil
  402. }
  403. return nil, nil
  404. case *octopus.CreateTrainJobResp:
  405. inresp := (interface{})(in).(*octopus.CreateTrainJobResp)
  406. switch (interface{})(out).(type) {
  407. case *types.SubmitLinkTaskResp:
  408. resp := (interface{})(out).(*types.SubmitLinkTaskResp)
  409. resp.Success = inresp.Success
  410. if !resp.Success {
  411. resp.ErrorMsg = inresp.Error.Message
  412. return resp, nil
  413. }
  414. resp.TaskId = inresp.Payload.JobId
  415. return resp, nil
  416. case *types.ScheduleResp:
  417. resp := (interface{})(out).(*types.ScheduleResp)
  418. return resp, nil
  419. }
  420. return nil, nil
  421. case *modelarts.CreateTrainingJobResp:
  422. inresp := (interface{})(in).(*modelarts.CreateTrainingJobResp)
  423. switch (interface{})(out).(type) {
  424. case *types.SubmitLinkTaskResp:
  425. resp := (interface{})(out).(*types.SubmitLinkTaskResp)
  426. if inresp.ErrorMsg != "" {
  427. resp.ErrorMsg = inresp.ErrorMsg
  428. resp.Success = false
  429. return resp, nil
  430. }
  431. resp.Success = true
  432. resp.TaskId = inresp.Metadata.Id
  433. return resp, nil
  434. }
  435. return nil, nil
  436. case *hpcAC.SubmitTaskAiResp:
  437. inresp := (interface{})(in).(*hpcAC.SubmitTaskAiResp)
  438. switch (interface{})(out).(type) {
  439. case *types.SubmitLinkTaskResp:
  440. resp := (interface{})(out).(*types.SubmitLinkTaskResp)
  441. if inresp.Code == "0" {
  442. resp.Success = true
  443. resp.TaskId = inresp.Data
  444. } else {
  445. resp.Success = false
  446. resp.ErrorMsg = inresp.Msg
  447. }
  448. return resp, nil
  449. case *types.ScheduleResp:
  450. resp := (interface{})(out).(*types.ScheduleResp)
  451. return resp, nil
  452. }
  453. return nil, nil
  454. case *hpcAC.SubmitJobResp:
  455. inresp := (interface{})(in).(*hpcAC.SubmitJobResp)
  456. switch (interface{})(out).(type) {
  457. case *types.SubmitLinkTaskResp:
  458. resp := (interface{})(out).(*types.SubmitLinkTaskResp)
  459. if inresp.Code == "0" {
  460. resp.Success = true
  461. resp.TaskId = inresp.Data
  462. } else {
  463. resp.Success = false
  464. resp.ErrorMsg = inresp.Msg
  465. }
  466. return resp, nil
  467. }
  468. return nil, nil
  469. case *octopus.GetTrainJobResp:
  470. inresp := (interface{})(in).(*octopus.GetTrainJobResp)
  471. switch (interface{})(out).(type) {
  472. case *types.GetLinkTaskResp:
  473. resp := (interface{})(out).(*types.GetLinkTaskResp)
  474. resp.Success = inresp.Success
  475. if !resp.Success {
  476. resp.ErrorMsg = inresp.Error.Message
  477. return resp, nil
  478. }
  479. var task types.TaskSl
  480. task.TaskId = inresp.Payload.TrainJob.Id
  481. task.TaskName = inresp.Payload.TrainJob.Name
  482. task.StartedAt = inresp.Payload.TrainJob.StartedAt
  483. task.CompletedAt = inresp.Payload.TrainJob.CompletedAt
  484. task.TaskStatus = inresp.Payload.TrainJob.Status
  485. resp.Task = &task
  486. return resp, nil
  487. }
  488. return nil, nil
  489. case *modelarts.JobResponse:
  490. inresp := (interface{})(in).(*modelarts.JobResponse)
  491. switch (interface{})(out).(type) {
  492. case *types.GetLinkTaskResp:
  493. resp := (interface{})(out).(*types.GetLinkTaskResp)
  494. if inresp.ErrorMsg != "" {
  495. resp.ErrorMsg = inresp.ErrorMsg
  496. resp.Success = false
  497. return resp, nil
  498. }
  499. resp.Success = true
  500. resp.Task = &types.TaskSl{}
  501. resp.Task.TaskId = inresp.Metadata.Id
  502. resp.Task.TaskName = inresp.Metadata.Name
  503. resp.Task.StartedAt = int64(inresp.Status.StartTime)
  504. resp.Task.CompletedAt = int64(inresp.Status.Duration)
  505. resp.Task.TaskStatus = inresp.Status.Phase
  506. return resp, nil
  507. }
  508. return nil, nil
  509. case *hpcAC.GetPytorchTaskResp:
  510. inresp := (interface{})(in).(*hpcAC.GetPytorchTaskResp)
  511. switch (interface{})(out).(type) {
  512. case *types.GetLinkTaskResp:
  513. resp := (interface{})(out).(*types.GetLinkTaskResp)
  514. if inresp.Code == "0" {
  515. resp.Success = true
  516. var task types.TaskSl
  517. task.TaskId = inresp.Data.Id
  518. task.TaskName = inresp.Data.TaskName
  519. task.TaskStatus = inresp.Data.Status
  520. task.StartedAt = timeutils.StringToUnixTime(inresp.Data.StartTime)
  521. task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.EndTime)
  522. resp.Task = &task
  523. } else {
  524. resp.Success = false
  525. resp.ErrorMsg = inresp.Msg
  526. resp.Task = nil
  527. }
  528. return resp, nil
  529. }
  530. return nil, nil
  531. case *hpcAC.GetJobDetailResp:
  532. inresp := (interface{})(in).(*hpcAC.GetJobDetailResp)
  533. switch (interface{})(out).(type) {
  534. case *types.GetLinkTaskResp:
  535. resp := (interface{})(out).(*types.GetLinkTaskResp)
  536. if inresp.Code == "0" {
  537. resp.Success = true
  538. var task types.TaskSl
  539. task.TaskId = inresp.Data.JobId
  540. task.TaskName = inresp.Data.JobName
  541. task.TaskStatus = AcStatus[inresp.Data.JobStatus]
  542. task.StartedAt = timeutils.StringToUnixTime(inresp.Data.JobStartTime)
  543. task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.JobEndTime)
  544. resp.Task = &task
  545. } else {
  546. resp.Success = false
  547. resp.ErrorMsg = inresp.Msg
  548. resp.Task = nil
  549. }
  550. return resp, nil
  551. }
  552. return nil, nil
  553. case *hpcAC.HistoryJobDetailResp:
  554. inresp := (interface{})(in).(*hpcAC.HistoryJobDetailResp)
  555. switch (interface{})(out).(type) {
  556. case *types.GetLinkTaskResp:
  557. resp := (interface{})(out).(*types.GetLinkTaskResp)
  558. if inresp.Code == "0" {
  559. resp.Success = true
  560. var task types.TaskSl
  561. task.TaskId = inresp.Data.JobId
  562. task.TaskName = inresp.Data.JobName
  563. task.TaskStatus = AcStatus[inresp.Data.JobState]
  564. task.StartedAt = timeutils.StringToUnixTime(inresp.Data.JobStartTime)
  565. task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.JobEndTime)
  566. resp.Task = &task
  567. } else {
  568. resp.Success = false
  569. resp.ErrorMsg = inresp.Msg
  570. resp.Task = nil
  571. }
  572. return resp, nil
  573. }
  574. return nil, nil
  575. case *octopus.DeleteTrainJobResp:
  576. inresp := (interface{})(in).(*octopus.DeleteTrainJobResp)
  577. switch (interface{})(out).(type) {
  578. case *types.DeleteLinkTaskResp:
  579. resp := (interface{})(out).(*types.DeleteLinkTaskResp)
  580. resp.Success = inresp.Success
  581. if !resp.Success {
  582. resp.ErrorMsg = inresp.Error.Message
  583. return resp, nil
  584. }
  585. return resp, nil
  586. }
  587. return nil, nil
  588. case *modelarts.DeleteTrainingJobResp:
  589. inresp := (interface{})(in).(*modelarts.DeleteTrainingJobResp)
  590. switch (interface{})(out).(type) {
  591. case *types.DeleteLinkTaskResp:
  592. resp := (interface{})(out).(*types.DeleteLinkTaskResp)
  593. if inresp.ErrorMsg != "" {
  594. resp.ErrorMsg = inresp.ErrorMsg
  595. resp.Success = false
  596. return resp, nil
  597. }
  598. resp.Success = true
  599. return resp, nil
  600. }
  601. return nil, nil
  602. case *hpcAC.DeleteTaskAiResp:
  603. inresp := (interface{})(in).(*hpcAC.DeleteTaskAiResp)
  604. switch (interface{})(out).(type) {
  605. case *types.DeleteLinkTaskResp:
  606. resp := (interface{})(out).(*types.DeleteLinkTaskResp)
  607. if inresp.Code == "0" {
  608. resp.Success = true
  609. } else {
  610. resp.Success = false
  611. resp.ErrorMsg = inresp.Msg
  612. }
  613. return resp, nil
  614. }
  615. return nil, nil
  616. case *hpcAC.DeleteJobResp:
  617. inresp := (interface{})(in).(*hpcAC.DeleteJobResp)
  618. switch (interface{})(out).(type) {
  619. case *types.DeleteLinkTaskResp:
  620. resp := (interface{})(out).(*types.DeleteLinkTaskResp)
  621. if inresp.Code == "0" {
  622. resp.Success = true
  623. } else {
  624. resp.Success = false
  625. resp.ErrorMsg = inresp.Msg
  626. }
  627. return resp, nil
  628. }
  629. return nil, nil
  630. case *octopus.GetResourceSpecsResp:
  631. inresp := (interface{})(in).(*octopus.GetResourceSpecsResp)
  632. switch (interface{})(out).(type) {
  633. case *types.GetResourceSpecsResp:
  634. resp := (interface{})(out).(*types.GetResourceSpecsResp)
  635. resp.Success = inresp.Success
  636. if !resp.Success {
  637. resp.ResourceSpecs = nil
  638. return resp, nil
  639. }
  640. for _, spec := range inresp.TrainResourceSpecs {
  641. var respec types.ResourceSpecSl
  642. respec.SpecId = spec.Id
  643. respec.SpecName = spec.Name
  644. respec.ParticipantId = participant.Id
  645. respec.ParticipantName = participant.Name
  646. respec.SpecPrice = spec.Price
  647. resp.ResourceSpecs = append(resp.ResourceSpecs, &respec)
  648. }
  649. return resp, nil
  650. }
  651. return nil, nil
  652. case *modelarts.TrainingJobFlavorsResp:
  653. inresp := (interface{})(in).(*modelarts.TrainingJobFlavorsResp)
  654. switch (interface{})(out).(type) {
  655. case *types.GetResourceSpecsResp:
  656. resp := (interface{})(out).(*types.GetResourceSpecsResp)
  657. resp.Success = true
  658. if inresp.Flavors == nil {
  659. resp.Success = false
  660. resp.ResourceSpecs = nil
  661. return resp, nil
  662. }
  663. for _, spec := range inresp.Flavors {
  664. var respec types.ResourceSpecSl
  665. respec.SpecId = spec.FlavorId
  666. respec.SpecName = spec.FlavorName
  667. respec.ParticipantId = participant.Id
  668. respec.ParticipantName = participant.Name
  669. respec.SpecPrice = 0
  670. resp.ResourceSpecs = append(resp.ResourceSpecs, &respec)
  671. }
  672. return resp, nil
  673. }
  674. return nil, nil
  675. default:
  676. return nil, errors.New("type convert fail")
  677. }
  678. }
  679. func ConvertTypeOld[T any](in *T, participant *models.StorelinkCenter) (interface{}, error) {
  680. switch (interface{})(in).(type) {
  681. case *octopus.UploadImageResp:
  682. var resp types.UploadLinkImageResp
  683. inresp := (interface{})(in).(*octopus.UploadImageResp)
  684. resp.Success = inresp.Success
  685. if !resp.Success {
  686. resp.ErrorMsg = inresp.Error.Message
  687. return resp, nil
  688. }
  689. return resp, nil
  690. case *octopus.DeleteImageResp:
  691. var resp types.DeleteLinkImageResp
  692. inresp := (interface{})(in).(*octopus.DeleteImageResp)
  693. resp.Success = inresp.Success
  694. if !resp.Success {
  695. resp.ErrorMsg = inresp.Error.Message
  696. return resp, nil
  697. }
  698. return resp, nil
  699. case *octopus.GetUserImageListResp:
  700. var resp types.GetLinkImageListResp
  701. inresp := (interface{})(in).(*octopus.GetUserImageListResp)
  702. resp.Success = inresp.Success
  703. if !resp.Success {
  704. resp.ErrorMsg = inresp.Error.Message
  705. resp.Images = nil
  706. return resp, nil
  707. }
  708. for _, v := range inresp.Payload.Images {
  709. var image types.ImageSl
  710. image.ImageId = v.Image.Id
  711. image.ImageName = v.Image.ImageName
  712. image.ImageStatus = OctImgStatus[v.Image.ImageStatus]
  713. resp.Images = append(resp.Images, &image)
  714. }
  715. return resp, nil
  716. case *modelarts.ListReposDetailsResp:
  717. var resp types.GetLinkImageListResp
  718. inresp := (interface{})(in).(*modelarts.ListReposDetailsResp)
  719. if inresp.Errors != nil {
  720. resp.Success = false
  721. resp.ErrorMsg = inresp.Errors[0].ErrorMessage
  722. resp.Images = nil
  723. return resp, nil
  724. }
  725. resp.Success = true
  726. for _, v := range inresp.Items {
  727. for _, r := range v.Tags {
  728. var image types.ImageSl
  729. image.ImageId = v.Namespace + "/" + v.Name + ":" + r
  730. image.ImageName = v.Name
  731. image.ImageStatus = "created"
  732. resp.Images = append(resp.Images, &image)
  733. }
  734. }
  735. return resp, nil
  736. case *hpcAC.GetImageListAiResp:
  737. var resp types.GetLinkImageListResp
  738. inresp := (interface{})(in).(*hpcAC.GetImageListAiResp)
  739. if inresp.Code == "0" {
  740. resp.Success = true
  741. for _, img := range inresp.Data {
  742. var image types.ImageSl
  743. image.ImageId = img.ImageId
  744. image.ImageName = img.Version
  745. image.ImageStatus = "created"
  746. resp.Images = append(resp.Images, &image)
  747. }
  748. } else {
  749. resp.Success = false
  750. resp.ErrorMsg = inresp.Msg
  751. resp.Images = nil
  752. }
  753. return resp, nil
  754. case *octopus.CreateTrainJobResp:
  755. var resp types.SubmitLinkTaskResp
  756. inresp := (interface{})(in).(*octopus.CreateTrainJobResp)
  757. resp.Success = inresp.Success
  758. if !resp.Success {
  759. resp.ErrorMsg = inresp.Error.Message
  760. return resp, nil
  761. }
  762. resp.TaskId = inresp.Payload.JobId
  763. return resp, nil
  764. case *modelarts.CreateTrainingJobResp:
  765. var resp types.SubmitLinkTaskResp
  766. inresp := (interface{})(in).(*modelarts.CreateTrainingJobResp)
  767. if inresp.ErrorMsg != "" {
  768. resp.ErrorMsg = inresp.ErrorMsg
  769. resp.Success = false
  770. return resp, nil
  771. }
  772. resp.Success = true
  773. resp.TaskId = inresp.Metadata.Id
  774. return resp, nil
  775. case *hpcAC.SubmitTaskAiResp:
  776. var resp types.SubmitLinkTaskResp
  777. inresp := (interface{})(in).(*hpcAC.SubmitTaskAiResp)
  778. if inresp.Code == "0" {
  779. resp.Success = true
  780. resp.TaskId = inresp.Data
  781. } else {
  782. resp.Success = false
  783. resp.ErrorMsg = inresp.Msg
  784. }
  785. return resp, nil
  786. case *hpcAC.SubmitJobResp:
  787. var resp types.SubmitLinkTaskResp
  788. inresp := (interface{})(in).(*hpcAC.SubmitJobResp)
  789. if inresp.Code == "0" {
  790. resp.Success = true
  791. resp.TaskId = inresp.Data
  792. } else {
  793. resp.Success = false
  794. resp.ErrorMsg = inresp.Msg
  795. }
  796. return resp, nil
  797. case *octopus.GetTrainJobResp:
  798. var resp types.GetLinkTaskResp
  799. inresp := (interface{})(in).(*octopus.GetTrainJobResp)
  800. resp.Success = inresp.Success
  801. if !resp.Success {
  802. resp.ErrorMsg = inresp.Error.Message
  803. return resp, nil
  804. }
  805. var task types.TaskSl
  806. task.TaskId = inresp.Payload.TrainJob.Id
  807. task.TaskName = inresp.Payload.TrainJob.Name
  808. task.StartedAt = inresp.Payload.TrainJob.StartedAt
  809. task.CompletedAt = inresp.Payload.TrainJob.CompletedAt
  810. task.TaskStatus = inresp.Payload.TrainJob.Status
  811. resp.Task = &task
  812. return resp, nil
  813. case *modelarts.JobResponse:
  814. var resp types.GetLinkTaskResp
  815. inresp := (interface{})(in).(*modelarts.JobResponse)
  816. if inresp.ErrorMsg != "" {
  817. resp.ErrorMsg = inresp.ErrorMsg
  818. resp.Success = false
  819. return resp, nil
  820. }
  821. resp.Success = true
  822. resp.Task = &types.TaskSl{}
  823. resp.Task.TaskId = inresp.Metadata.Id
  824. resp.Task.TaskName = inresp.Metadata.Name
  825. resp.Task.StartedAt = int64(inresp.Status.StartTime)
  826. resp.Task.CompletedAt = int64(inresp.Status.Duration)
  827. resp.Task.TaskStatus = inresp.Status.Phase
  828. return resp, nil
  829. case *hpcAC.GetPytorchTaskResp:
  830. var resp types.GetLinkTaskResp
  831. inresp := (interface{})(in).(*hpcAC.GetPytorchTaskResp)
  832. if inresp.Code == "0" {
  833. resp.Success = true
  834. var task types.TaskSl
  835. task.TaskId = inresp.Data.Id
  836. task.TaskName = inresp.Data.TaskName
  837. task.TaskStatus = inresp.Data.Status
  838. task.StartedAt = timeutils.StringToUnixTime(inresp.Data.StartTime)
  839. task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.EndTime)
  840. resp.Task = &task
  841. } else {
  842. resp.Success = false
  843. resp.ErrorMsg = inresp.Msg
  844. resp.Task = nil
  845. }
  846. return resp, nil
  847. case *hpcAC.GetJobDetailResp:
  848. var resp types.GetLinkTaskResp
  849. inresp := (interface{})(in).(*hpcAC.GetJobDetailResp)
  850. if inresp.Code == "0" {
  851. resp.Success = true
  852. var task types.TaskSl
  853. task.TaskId = inresp.Data.JobId
  854. task.TaskName = inresp.Data.JobName
  855. task.TaskStatus = AcStatus[inresp.Data.JobStatus]
  856. task.StartedAt = timeutils.StringToUnixTime(inresp.Data.JobStartTime)
  857. task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.JobEndTime)
  858. resp.Task = &task
  859. } else {
  860. resp.Success = false
  861. resp.ErrorMsg = inresp.Msg
  862. resp.Task = nil
  863. }
  864. return resp, nil
  865. case *hpcAC.HistoryJobDetailResp:
  866. var resp types.GetLinkTaskResp
  867. inresp := (interface{})(in).(*hpcAC.HistoryJobDetailResp)
  868. if inresp.Code == "0" {
  869. resp.Success = true
  870. var task types.TaskSl
  871. task.TaskId = inresp.Data.JobId
  872. task.TaskName = inresp.Data.JobName
  873. task.TaskStatus = AcStatus[inresp.Data.JobState]
  874. task.StartedAt = timeutils.StringToUnixTime(inresp.Data.JobStartTime)
  875. task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.JobEndTime)
  876. resp.Task = &task
  877. } else {
  878. resp.Success = false
  879. resp.ErrorMsg = inresp.Msg
  880. resp.Task = nil
  881. }
  882. return resp, nil
  883. case *octopus.DeleteTrainJobResp:
  884. var resp types.DeleteLinkTaskResp
  885. inresp := (interface{})(in).(*octopus.DeleteTrainJobResp)
  886. resp.Success = inresp.Success
  887. if !resp.Success {
  888. resp.ErrorMsg = inresp.Error.Message
  889. return resp, nil
  890. }
  891. return resp, nil
  892. case *modelarts.DeleteTrainingJobResp:
  893. var resp types.DeleteLinkTaskResp
  894. inresp := (interface{})(in).(*modelarts.DeleteTrainingJobResp)
  895. if inresp.ErrorMsg != "" {
  896. resp.ErrorMsg = inresp.ErrorMsg
  897. resp.Success = false
  898. return resp, nil
  899. }
  900. resp.Success = true
  901. return resp, nil
  902. case *hpcAC.DeleteTaskAiResp:
  903. var resp types.DeleteLinkTaskResp
  904. inresp := (interface{})(in).(*hpcAC.DeleteTaskAiResp)
  905. if inresp.Code == "0" {
  906. resp.Success = true
  907. } else {
  908. resp.Success = false
  909. resp.ErrorMsg = inresp.Msg
  910. }
  911. return resp, nil
  912. case *hpcAC.DeleteJobResp:
  913. var resp types.DeleteLinkTaskResp
  914. inresp := (interface{})(in).(*hpcAC.DeleteJobResp)
  915. if inresp.Code == "0" {
  916. resp.Success = true
  917. } else {
  918. resp.Success = false
  919. resp.ErrorMsg = inresp.Msg
  920. }
  921. return resp, nil
  922. case *octopus.GetResourceSpecsResp:
  923. var resp types.GetResourceSpecsResp
  924. inresp := (interface{})(in).(*octopus.GetResourceSpecsResp)
  925. resp.Success = inresp.Success
  926. if !resp.Success {
  927. resp.ResourceSpecs = nil
  928. return resp, nil
  929. }
  930. for _, spec := range inresp.TrainResourceSpecs {
  931. var respec types.ResourceSpecSl
  932. respec.SpecId = spec.Id
  933. respec.SpecName = spec.Name
  934. respec.ParticipantId = participant.Id
  935. respec.ParticipantName = participant.Name
  936. respec.SpecPrice = spec.Price
  937. resp.ResourceSpecs = append(resp.ResourceSpecs, &respec)
  938. }
  939. return resp, nil
  940. case *modelarts.TrainingJobFlavorsResp:
  941. var resp types.GetResourceSpecsResp
  942. resp.Success = true
  943. inresp := (interface{})(in).(*modelarts.TrainingJobFlavorsResp)
  944. if inresp.Flavors == nil {
  945. resp.Success = false
  946. resp.ResourceSpecs = nil
  947. return resp, nil
  948. }
  949. for _, spec := range inresp.Flavors {
  950. var respec types.ResourceSpecSl
  951. respec.SpecId = spec.FlavorId
  952. respec.SpecName = spec.FlavorName
  953. respec.ParticipantId = participant.Id
  954. respec.ParticipantName = participant.Name
  955. respec.SpecPrice = 0
  956. resp.ResourceSpecs = append(resp.ResourceSpecs, &respec)
  957. }
  958. return resp, nil
  959. default:
  960. return nil, errors.New("type convert fail")
  961. }
  962. }

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.