You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

storeLink.go 29 kB

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

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.