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

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

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.