|
- package modelarts
-
- import (
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/storage"
- "encoding/json"
- "path"
- )
-
- const (
- storageTypeOBS = "obs"
- autoStopDuration = 4 * 60 * 60
-
- DataSetMountPath = "/home/ma-user/work"
- NotebookEnv = "Python3"
- NotebookType = "Ascend"
- )
-
- var (
- poolInfos *models.PoolInfos
- FlavorInfos *models.FlavorInfos
- )
-
- func GenerateTask(ctx *context.Context, jobName, uuid, description string) error {
- var dataActualPath string
- if uuid != "" {
- dataActualPath = setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/"
- } else {
- userPath := setting.UserBasePath + ctx.User.Name + "/"
- isExist, err := storage.ObsHasObject(userPath)
- if err != nil {
- log.Error("ObsHasObject failed:%v", err.Error(), ctx.Data["MsgID"])
- return err
- }
-
- if !isExist {
- if err = storage.ObsCreateObject(userPath); err != nil {
- log.Error("ObsCreateObject failed:%v", err.Error(), ctx.Data["MsgID"])
- return err
- }
- }
-
- dataActualPath = setting.Bucket + "/" + userPath
- }
-
- if poolInfos == nil {
- json.Unmarshal([]byte(setting.PoolInfos), &poolInfos)
- }
- jobResult, err := CreateJob(models.CreateNotebookParams{
- JobName: jobName,
- Description: description,
- ProfileID: setting.ProfileID,
- Flavor: setting.Flavor,
- Pool: models.Pool{
- ID: poolInfos.PoolInfo[0].PoolId,
- Name: poolInfos.PoolInfo[0].PoolName,
- Type: poolInfos.PoolInfo[0].PoolType,
- },
- Spec: models.Spec{
- Storage: models.Storage{
- Type: storageTypeOBS,
- Location: models.Location{
- Path: dataActualPath,
- },
- },
- AutoStop: models.AutoStop{
- Enable: true,
- Duration: autoStopDuration,
- },
- },
- })
- if err != nil {
- log.Error("CreateJob failed: %v", err.Error())
- return err
- }
-
- err = models.CreateCloudbrain(&models.Cloudbrain{
- Status: string(models.JobWaiting),
- UserID: ctx.User.ID,
- RepoID: ctx.Repo.Repository.ID,
- JobID: jobResult.ID,
- JobName: jobName,
- JobType: string(models.JobTypeDebug),
- Type: models.TypeCloudBrainTwo,
- })
-
- if err != nil {
- return err
- }
-
- return nil
- }
|