From 5ebd80c32ef7b37b553a0e4293883c0a71ceef48 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 21 Dec 2022 15:49:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/cloudbrain.go | 3 +- routers/api/v1/api.go | 3 +- routers/repo/cloudbrain.go | 7 ++-- routers/repo/modelarts.go | 13 ++++--- services/cloudbrain/cloudbrainTask/notebook.go | 50 ++++++++++++++++++-------- 5 files changed, 52 insertions(+), 24 deletions(-) diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 099f07c3a..f94969605 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -2128,7 +2128,8 @@ func GetCloudbrainByName(jobName string) (*Cloudbrain, error) { } func GetWaitOrRunFileNotebookByRepo(repoId int64, cloudbrainType int) (*Cloudbrain, error) { cloudBrain := new(Cloudbrain) - has, err := x.In("status", JobWaiting, JobRunning).Where("repo_id=? and type=? and boot_file!=''", repoId, cloudbrainType).Get(cloudBrain) + has, err := x.In("status", JobWaiting, JobRunning, ModelArtsCreateQueue, ModelArtsCreating, ModelArtsStarting, + ModelArtsReadyToStart, ModelArtsResizing, ModelArtsStartQueuing, ModelArtsRunning, ModelArtsDeleting, ModelArtsRestarting).Where("repo_id=? and type=? and boot_file!=''", repoId, cloudbrainType).Get(cloudBrain) if has { return cloudBrain, err } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 6a8090cd4..cae6c01bf 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -745,8 +745,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/file_notebook", func() { m.Get("", repo.GetFileNoteBookInfo) m.Post("/create", reqToken(), reqWeChat(), bind(api.CreateFileNotebookJobOption{}), repo.CreateFileNoteBook) - //m.Post("/status", reqToken(), bind(api.CreateFileNotebookJobOption{}), repo.FileNoteBookStatus) - m.Post("/status", bind(api.CreateFileNotebookJobOption{}), repo.FileNoteBookStatus) + m.Post("/status", reqToken(), bind(api.CreateFileNotebookJobOption{}), repo.FileNoteBookStatus) }) m.Group("/repos", func() { diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 905c25a64..3b45e3074 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -911,10 +911,13 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo func CloudBrainDebug(ctx *context.Context) { task := ctx.Cloudbrain debugUrl := setting.DebugServerHost + "jpylab_" + task.JobID + "_" + task.SubTaskName - if task.BootFile != "" { - ctx.Redirect(getFileUrl(debugUrl, task.BootFile)) + if ctx.QueryTrim("file") != "" { + ctx.Redirect(getFileUrl(debugUrl, ctx.QueryTrim("file"))) } else { + if task.BootFile != "" { + go cloudbrainTask.UploadNotebookFiles(task) + } ctx.Redirect(debugUrl) } diff --git a/routers/repo/modelarts.go b/routers/repo/modelarts.go index 76de80f71..2d555fc9a 100755 --- a/routers/repo/modelarts.go +++ b/routers/repo/modelarts.go @@ -439,10 +439,15 @@ func NotebookDebug2(ctx *context.Context) { ctx.RenderWithErr(err.Error(), tplModelArtsNotebookIndex, nil) return } - if task.BootFile != "" { - go cloudbrainTask.UploadNotebookFiles(task) + + if ctx.QueryTrim("file") != "" { + ctx.Redirect(getFileUrl(result.Url, ctx.QueryTrim("file")) + "?token=" + result.Token) + } else { + if task.BootFile != "" { + go cloudbrainTask.UploadNotebookFiles(task) + } + ctx.Redirect(result.Url + "?token=" + result.Token) } - ctx.Redirect(result.Url + "?token=" + result.Token) } @@ -629,7 +634,7 @@ func NotebookStop(ctx *context.Context) { if task.Status != string(models.ModelArtsRunning) { log.Error("the job(%s) is not running", task.JobName, ctx.Data["MsgID"]) resultCode = "-1" - errorMsg = "the job is not running" + errorMsg = ctx.Tr("cloudbrain.Already_stopped") break } diff --git a/services/cloudbrain/cloudbrainTask/notebook.go b/services/cloudbrain/cloudbrainTask/notebook.go index 766966843..4a06bbc79 100644 --- a/services/cloudbrain/cloudbrainTask/notebook.go +++ b/services/cloudbrain/cloudbrainTask/notebook.go @@ -101,20 +101,25 @@ func FileNotebookCreate(ctx *context.Context, option api.CreateFileNotebookJobOp } if isNotebookSpecMath(option, noteBook) { - - err = downloadCode(sourceRepo, getCodePath(noteBook.JobName, sourceRepo), option.BranchName) - if err != nil { - log.Error("download code failed", err) - ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(ctx.Tr("cloudbrain.load_code_failed"))) - return + if !isRepoMatch(option, noteBook) { + err = downloadCode(sourceRepo, getCodePath(noteBook.JobName, sourceRepo), option.BranchName) + if err != nil { + log.Error("download code failed", err) + ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(ctx.Tr("cloudbrain.load_code_failed"))) + return + } } - noteBook.BootFile += ";" + getBootFile(option.File, option.OwnerName, option.ProjectName) - noteBook.BranchName += ";" + option.BranchName - err := models.UpdateJob(noteBook) - if err != nil { - log.Error("GenerateNotebook2 failed, %v", err, ctx.Data["MsgID"]) - ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(err.Error())) - return + if !isRepoFileMatch(option, noteBook) { + noteBook.BootFile += ";" + getBootFile(option.File, option.OwnerName, option.ProjectName) + noteBook.BranchName += ";" + option.BranchName + noteBook.Description += ";" + getDescription(option) + + err := models.UpdateJob(noteBook) + if err != nil { + log.Error("GenerateNotebook2 failed, %v", err, ctx.Data["MsgID"]) + ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(err.Error())) + return + } } ctx.JSON(http.StatusOK, models.BaseMessageApi{ @@ -252,6 +257,21 @@ func isRepoConfilcts(option api.CreateFileNotebookJobOption, book *models.Cloudb } +func isRepoMatch(option api.CreateFileNotebookJobOption, book *models.Cloudbrain) bool { + bootFiles := strings.Split(book.BootFile, ";") + + for _, bootFile := range bootFiles { + splits := strings.Split(bootFile, "/") + if len(splits) >= 3 { + if splits[0] == option.OwnerName && splits[1] == option.ProjectName { + return true + } + } + } + return false + +} + func isRepoFileMatch(option api.CreateFileNotebookJobOption, book *models.Cloudbrain) bool { bootFiles := strings.Split(book.BootFile, ";") branches := strings.Split(book.BranchName, ";") @@ -494,9 +514,9 @@ func modelartsFileNoteBookCreate(ctx *context.Context, option api.CreateFileNote Description: getDescription(option), ImageId: setting.FileNoteBook.ImageIdNPU, Spec: spec, - BootFile: "", + BootFile: getBootFile(option.File, option.OwnerName, option.ProjectName), AutoStopDurationMs: modelarts.AutoStopDurationMs / 4, - BranchName: option.BranchName, + BranchName: option.BranchName, } if setting.ModelartsCD.Enabled {