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

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

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.