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