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.

cloudbrain.go 2.4 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package cloudbrain
  2. import (
  3. "code.gitea.io/gitea/modules/setting"
  4. "errors"
  5. "code.gitea.io/gitea/models"
  6. "code.gitea.io/gitea/modules/context"
  7. "code.gitea.io/gitea/modules/log"
  8. )
  9. const (
  10. Command = `pip3 install jupyterlab==2.2.5 -i https://pypi.tuna.tsinghua.edu.cn/simple;service ssh stop;jupyter lab --no-browser --ip=0.0.0.0 --allow-root --notebook-dir="/code" --port=80 --LabApp.token="" --LabApp.allow_origin="self https://cloudbrain.pcl.ac.cn"`
  11. CodeMountPath = "/code"
  12. DataSetMountPath = "/dataset"
  13. ModelMountPath = "/model"
  14. SubTaskName = "task1"
  15. Success = "S000"
  16. )
  17. func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath string) error {
  18. dataActualPath := setting.Attachment.Minio.RealPath +
  19. setting.Attachment.Minio.Bucket + "/" +
  20. setting.Attachment.Minio.BasePath +
  21. models.AttachmentRelativePath(uuid) +
  22. uuid
  23. jobResult, err := CreateJob(jobName, models.CreateJobParams{
  24. JobName: jobName,
  25. RetryCount: 1,
  26. GpuType: setting.JobType,
  27. Image: image,
  28. TaskRoles: []models.TaskRole{
  29. {
  30. Name: SubTaskName,
  31. TaskNumber: 1,
  32. MinSucceededTaskCount: 1,
  33. MinFailedTaskCount: 1,
  34. CPUNumber: 2,
  35. GPUNumber: 1,
  36. MemoryMB: 16384,
  37. ShmMB: 8192,
  38. Command: command,
  39. NeedIBDevice: false,
  40. IsMainRole: false,
  41. UseNNI: false,
  42. },
  43. },
  44. Volumes: []models.Volume{
  45. {
  46. HostPath: models.StHostPath{
  47. Path: codePath,
  48. MountPath: CodeMountPath,
  49. ReadOnly: false,
  50. },
  51. },
  52. {
  53. HostPath: models.StHostPath{
  54. Path: dataActualPath,
  55. MountPath: DataSetMountPath,
  56. ReadOnly: true,
  57. },
  58. },
  59. {
  60. HostPath: models.StHostPath{
  61. Path: modelPath,
  62. MountPath: ModelMountPath,
  63. ReadOnly: false,
  64. },
  65. },
  66. },
  67. })
  68. if err != nil {
  69. log.Error("CreateJob failed:", err.Error())
  70. return err
  71. }
  72. if jobResult.Code != Success {
  73. log.Error("CreateJob(%s) failed:%s", jobName, jobResult.Msg)
  74. return errors.New(jobResult.Msg)
  75. }
  76. var jobID = jobResult.Payload["jobId"].(string)
  77. err = models.CreateCloudbrain(&models.Cloudbrain{
  78. Status: string(models.JobWaiting),
  79. UserID: ctx.User.ID,
  80. RepoID: ctx.Repo.Repository.ID,
  81. JobID: jobID,
  82. JobName: jobName,
  83. SubTaskName: SubTaskName,
  84. })
  85. if err != nil {
  86. return err
  87. }
  88. return nil
  89. }