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 27 kB

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

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.