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.

modelarts.go 2.2 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package modelarts
  2. import (
  3. "code.gitea.io/gitea/models"
  4. "code.gitea.io/gitea/modules/context"
  5. "code.gitea.io/gitea/modules/log"
  6. "code.gitea.io/gitea/modules/setting"
  7. "code.gitea.io/gitea/modules/storage"
  8. "encoding/json"
  9. "path"
  10. )
  11. const (
  12. storageTypeOBS = "obs"
  13. autoStopDuration = 4 * 60 * 60
  14. DataSetMountPath = "/home/ma-user/work"
  15. NotebookEnv = "Python3"
  16. NotebookType = "Ascend"
  17. )
  18. var (
  19. poolInfos *models.PoolInfos
  20. FlavorInfos *models.FlavorInfos
  21. )
  22. func GenerateTask(ctx *context.Context, jobName, uuid, description string) error {
  23. var dataActualPath string
  24. if uuid != "" {
  25. dataActualPath = setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/"
  26. } else {
  27. userPath := setting.UserBasePath + ctx.User.Name + "/"
  28. isExist, err := storage.ObsHasObject(userPath)
  29. if err != nil {
  30. log.Error("ObsHasObject failed:%v", err.Error(), ctx.Data["MsgID"])
  31. return err
  32. }
  33. if !isExist {
  34. if err = storage.ObsCreateObject(userPath); err != nil {
  35. log.Error("ObsCreateObject failed:%v", err.Error(), ctx.Data["MsgID"])
  36. return err
  37. }
  38. }
  39. dataActualPath = setting.Bucket + "/" + userPath
  40. }
  41. if poolInfos == nil {
  42. json.Unmarshal([]byte(setting.PoolInfos), &poolInfos)
  43. }
  44. jobResult, err := CreateJob(models.CreateNotebookParams{
  45. JobName: jobName,
  46. Description: description,
  47. ProfileID: setting.ProfileID,
  48. Flavor: setting.Flavor,
  49. Pool: models.Pool{
  50. ID: poolInfos.PoolInfo[0].PoolId,
  51. Name: poolInfos.PoolInfo[0].PoolName,
  52. Type: poolInfos.PoolInfo[0].PoolType,
  53. },
  54. Spec: models.Spec{
  55. Storage: models.Storage{
  56. Type: storageTypeOBS,
  57. Location: models.Location{
  58. Path: dataActualPath,
  59. },
  60. },
  61. AutoStop: models.AutoStop{
  62. Enable: true,
  63. Duration: autoStopDuration,
  64. },
  65. },
  66. })
  67. if err != nil {
  68. log.Error("CreateJob failed: %v", err.Error())
  69. return err
  70. }
  71. err = models.CreateCloudbrain(&models.Cloudbrain{
  72. Status: string(models.JobWaiting),
  73. UserID: ctx.User.ID,
  74. RepoID: ctx.Repo.Repository.ID,
  75. JobID: jobResult.ID,
  76. JobName: jobName,
  77. JobType: string(models.JobTypeDebug),
  78. Type: models.TypeCloudBrainTwo,
  79. })
  80. if err != nil {
  81. return err
  82. }
  83. return nil
  84. }