|
- package cloudbrain
-
- import (
- "code.gitea.io/gitea/modules/setting"
- "errors"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/log"
- )
-
- const (
- 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"`
- CodeMountPath = "/code"
- DataSetMountPath = "/dataset"
- ModelMountPath = "/model"
- BenchMarkMountPath = "/benchmark"
- TaskInfoName = "/taskInfo"
-
- SubTaskName = "task1"
-
- Success = "S000"
- )
-
- func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, jobType string) error {
- dataActualPath := setting.Attachment.Minio.RealPath +
- setting.Attachment.Minio.Bucket + "/" +
- setting.Attachment.Minio.BasePath +
- models.AttachmentRelativePath(uuid) +
- uuid
- jobResult, err := CreateJob(jobName, models.CreateJobParams{
- JobName: jobName,
- RetryCount: 1,
- GpuType: setting.JobType,
- Image: image,
- TaskRoles: []models.TaskRole{
- {
- Name: SubTaskName,
- TaskNumber: 1,
- MinSucceededTaskCount: 1,
- MinFailedTaskCount: 1,
- CPUNumber: 2,
- GPUNumber: 1,
- MemoryMB: 16384,
- ShmMB: 8192,
- Command: command,
- NeedIBDevice: false,
- IsMainRole: false,
- UseNNI: false,
- },
- },
- Volumes: []models.Volume{
- {
- HostPath: models.StHostPath{
- Path: codePath,
- MountPath: CodeMountPath,
- ReadOnly: false,
- },
- },
- {
- HostPath: models.StHostPath{
- Path: dataActualPath,
- MountPath: DataSetMountPath,
- ReadOnly: true,
- },
- },
- {
- HostPath: models.StHostPath{
- Path: modelPath,
- MountPath: ModelMountPath,
- ReadOnly: false,
- },
- },
- {
- HostPath: models.StHostPath{
- Path: benchmarkPath,
- MountPath: BenchMarkMountPath,
- ReadOnly: true,
- },
- },
- },
- })
- if err != nil {
- log.Error("CreateJob failed:", err.Error())
- return err
- }
- if jobResult.Code != Success {
- log.Error("CreateJob(%s) failed:%s", jobName, jobResult.Msg)
- return errors.New(jobResult.Msg)
- }
-
- var jobID = jobResult.Payload["jobId"].(string)
- err = models.CreateCloudbrain(&models.Cloudbrain{
- Status: string(models.JobWaiting),
- UserID: ctx.User.ID,
- RepoID: ctx.Repo.Repository.ID,
- JobID: jobID,
- JobName: jobName,
- SubTaskName: SubTaskName,
- JobType: jobType,
- })
-
- if err != nil {
- return err
- }
-
- return nil
- }
|