@@ -2128,7 +2128,8 @@ func GetCloudbrainByName(jobName string) (*Cloudbrain, error) { | |||||
} | } | ||||
func GetWaitOrRunFileNotebookByRepo(repoId int64, cloudbrainType int) (*Cloudbrain, error) { | func GetWaitOrRunFileNotebookByRepo(repoId int64, cloudbrainType int) (*Cloudbrain, error) { | ||||
cloudBrain := new(Cloudbrain) | 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 { | if has { | ||||
return cloudBrain, err | return cloudBrain, err | ||||
} | } | ||||
@@ -745,8 +745,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
m.Group("/file_notebook", func() { | m.Group("/file_notebook", func() { | ||||
m.Get("", repo.GetFileNoteBookInfo) | m.Get("", repo.GetFileNoteBookInfo) | ||||
m.Post("/create", reqToken(), reqWeChat(), bind(api.CreateFileNotebookJobOption{}), repo.CreateFileNoteBook) | 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() { | m.Group("/repos", func() { | ||||
@@ -911,10 +911,13 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo | |||||
func CloudBrainDebug(ctx *context.Context) { | func CloudBrainDebug(ctx *context.Context) { | ||||
task := ctx.Cloudbrain | task := ctx.Cloudbrain | ||||
debugUrl := setting.DebugServerHost + "jpylab_" + task.JobID + "_" + task.SubTaskName | 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 { | } else { | ||||
if task.BootFile != "" { | |||||
go cloudbrainTask.UploadNotebookFiles(task) | |||||
} | |||||
ctx.Redirect(debugUrl) | ctx.Redirect(debugUrl) | ||||
} | } | ||||
@@ -439,10 +439,15 @@ func NotebookDebug2(ctx *context.Context) { | |||||
ctx.RenderWithErr(err.Error(), tplModelArtsNotebookIndex, nil) | ctx.RenderWithErr(err.Error(), tplModelArtsNotebookIndex, nil) | ||||
return | 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) { | if task.Status != string(models.ModelArtsRunning) { | ||||
log.Error("the job(%s) is not running", task.JobName, ctx.Data["MsgID"]) | log.Error("the job(%s) is not running", task.JobName, ctx.Data["MsgID"]) | ||||
resultCode = "-1" | resultCode = "-1" | ||||
errorMsg = "the job is not running" | |||||
errorMsg = ctx.Tr("cloudbrain.Already_stopped") | |||||
break | break | ||||
} | } | ||||
@@ -101,20 +101,25 @@ func FileNotebookCreate(ctx *context.Context, option api.CreateFileNotebookJobOp | |||||
} | } | ||||
if isNotebookSpecMath(option, noteBook) { | 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{ | 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 { | func isRepoFileMatch(option api.CreateFileNotebookJobOption, book *models.Cloudbrain) bool { | ||||
bootFiles := strings.Split(book.BootFile, ";") | bootFiles := strings.Split(book.BootFile, ";") | ||||
branches := strings.Split(book.BranchName, ";") | branches := strings.Split(book.BranchName, ";") | ||||
@@ -494,9 +514,9 @@ func modelartsFileNoteBookCreate(ctx *context.Context, option api.CreateFileNote | |||||
Description: getDescription(option), | Description: getDescription(option), | ||||
ImageId: setting.FileNoteBook.ImageIdNPU, | ImageId: setting.FileNoteBook.ImageIdNPU, | ||||
Spec: spec, | Spec: spec, | ||||
BootFile: "", | |||||
BootFile: getBootFile(option.File, option.OwnerName, option.ProjectName), | |||||
AutoStopDurationMs: modelarts.AutoStopDurationMs / 4, | AutoStopDurationMs: modelarts.AutoStopDurationMs / 4, | ||||
BranchName: option.BranchName, | |||||
BranchName: option.BranchName, | |||||
} | } | ||||
if setting.ModelartsCD.Enabled { | if setting.ModelartsCD.Enabled { | ||||