From f1acf29f2da6af2b8b1bfeb380be413afd2a72b3 Mon Sep 17 00:00:00 2001 From: liuzx Date: Wed, 16 Feb 2022 16:24:07 +0800 Subject: [PATCH 1/5] fix-jobid --- routers/repo/cloudbrain.go | 8 ++++---- routers/routes/routes.go | 4 +++- templates/repo/debugjob/index.tmpl | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 0599fb03f..cea87feec 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -351,13 +351,13 @@ func CloudBrainShow(ctx *context.Context) { func cloudBrainShow(ctx *context.Context, tpName base.TplName) { ctx.Data["PageIsCloudBrain"] = true - var jobID = ctx.Params(":jobid") - task, err := models.GetCloudbrainByJobID(jobID) + var jobName = ctx.Params(":jobname") + task, err := models.GetCloudbrainByName(jobName) if err != nil { ctx.Data["error"] = err.Error() } - result, err := cloudbrain.GetJob(jobID) + result, err := cloudbrain.GetJob(task.JobID) if err != nil { ctx.Data["error"] = err.Error() } @@ -422,7 +422,7 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName) { ctx.Data["duration"] = util.AddZero(duration/3600000) + ":" + util.AddZero(duration%3600000/60000) + ":" + util.AddZero(duration%60000/1000) ctx.Data["task"] = task - ctx.Data["jobID"] = jobID + ctx.Data["jobID"] = task.JobID ctx.Data["jobName"] = task.JobName version_list_task := make([]*models.Cloudbrain, 0) version_list_task = append(version_list_task, task) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index aa85b8f2b..de355352f 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -974,8 +974,10 @@ func RegisterRoutes(m *macaron.Macaron) { }, context.RepoRef()) m.Group("/cloudbrain", func() { - m.Group("/:jobid", func() { + m.Group("/:jobname", func() { m.Get("", reqRepoCloudBrainReader, repo.CloudBrainShow) + }) + m.Group("/:jobid", func() { m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.CloudBrainDebug) m.Post("/commit_image", cloudbrain.AdminOrJobCreaterRight, bindIgnErr(auth.CommitImageCloudBrainForm{}), repo.CloudBrainCommitImage) m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.CloudBrainStop) diff --git a/templates/repo/debugjob/index.tmpl b/templates/repo/debugjob/index.tmpl index f7773cf2d..8cf58dc4f 100755 --- a/templates/repo/debugjob/index.tmpl +++ b/templates/repo/debugjob/index.tmpl @@ -287,7 +287,7 @@
From ad9494faedbf022987e72d0e3035b803aa9a632f Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 17 Feb 2022 14:46:24 +0800 Subject: [PATCH 2/5] fix-bug --- routers/api/v1/api.go | 3 ++- routers/api/v1/repo/cloudbrain.go | 23 +++++++++++------------ routers/api/v1/repo/modelarts.go | 1 + routers/repo/cloudbrain.go | 2 +- routers/repo/modelarts.go | 1 + routers/routes/routes.go | 10 ---------- templates/repo/debugjob/index.tmpl | 30 ++++++++++++++++-------------- 7 files changed, 32 insertions(+), 38 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 72a68a6d3..c6c5703b3 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -878,7 +878,8 @@ func RegisterRoutes(m *macaron.Macaron) { }, reqAdmin()) }, reqAnyRepoReader()) m.Group("/cloudbrain", func() { - m.Get("/:jobid", repo.GetCloudbrainTask) + // m.Get("/:jobid", repo.GetCloudbrainTask) + m.Get("/:jobname", repo.GetCloudbrainTask) m.Get("/:jobid/log", repo.CloudbrainGetLog) }, reqRepoReader(models.UnitTypeCloudBrain)) m.Group("/modelarts", func() { diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index dd468783d..35044a894 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -6,11 +6,12 @@ package repo import ( - "code.gitea.io/gitea/modules/log" "net/http" "sort" "time" + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/cloudbrain" "code.gitea.io/gitea/modules/context" @@ -48,14 +49,12 @@ func GetCloudbrainTask(ctx *context.APIContext) { err error ) - jobID := ctx.Params(":jobid") - repoID := ctx.Repo.Repository.ID - job, err := models.GetRepoCloudBrainByJobID(repoID, jobID) + jobName := ctx.Params(":jobname") + job, err := models.GetCloudbrainByName(jobName) if err != nil { - ctx.NotFound(err) - return + ctx.Data["error"] = err.Error() } - jobResult, err := cloudbrain.GetJob(jobID) + jobResult, err := cloudbrain.GetJob(job.JobID) if err != nil { ctx.NotFound(err) return @@ -84,7 +83,7 @@ func GetCloudbrainTask(ctx *context.APIContext) { } ctx.JSON(http.StatusOK, map[string]interface{}{ - "JobID": result.Config.JobID, + "JobName": result.Config.JobName, "JobStatus": result.JobStatus.State, "SubState": result.JobStatus.SubState, "CreatedTime": time.Unix(result.JobStatus.CreatedTime/1000, 0).Format("2006-01-02 15:04:05"), @@ -104,7 +103,7 @@ func CloudbrainGetLog(ctx *context.Context) { var hits []models.Hits result, err := cloudbrain.GetJobLog(jobID) - if err != nil{ + if err != nil { log.Error("GetJobLog failed: %v", err, ctx.Data["MsgID"]) ctx.ServerError(err.Error(), err) return @@ -115,7 +114,7 @@ func CloudbrainGetLog(ctx *context.Context) { if len(result.Hits.Hits) >= cloudbrain.LogPageSize { for { resultNext, err := cloudbrain.GetJobAllLog(result.ScrollID) - if err != nil{ + if err != nil { log.Error("GetJobAllLog failed: %v", err, ctx.Data["MsgID"]) } else { for _, hit := range resultNext.Hits.Hits { @@ -142,8 +141,8 @@ func CloudbrainGetLog(ctx *context.Context) { } ctx.JSON(http.StatusOK, map[string]interface{}{ - "JobID": jobID, - "Content": content, + "JobID": jobID, + "Content": content, }) return diff --git a/routers/api/v1/repo/modelarts.go b/routers/api/v1/repo/modelarts.go index c9f8761c9..27df10e16 100755 --- a/routers/api/v1/repo/modelarts.go +++ b/routers/api/v1/repo/modelarts.go @@ -77,6 +77,7 @@ func GetModelArtsNotebook2(ctx *context.APIContext) { ctx.JSON(http.StatusOK, map[string]interface{}{ "JobID": jobID, + "JobName": job.JobName, "JobStatus": result.Status, }) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index cea87feec..cff7f6e94 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -422,7 +422,7 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName) { ctx.Data["duration"] = util.AddZero(duration/3600000) + ":" + util.AddZero(duration%3600000/60000) + ":" + util.AddZero(duration%60000/1000) ctx.Data["task"] = task - ctx.Data["jobID"] = task.JobID + // ctx.Data["jobID"] = task.JobID ctx.Data["jobName"] = task.JobName version_list_task := make([]*models.Cloudbrain, 0) version_list_task = append(version_list_task, task) diff --git a/routers/repo/modelarts.go b/routers/repo/modelarts.go index 9dea34c82..a6a7c9d96 100755 --- a/routers/repo/modelarts.go +++ b/routers/repo/modelarts.go @@ -268,6 +268,7 @@ func NotebookShow(ctx *context.Context) { ctx.Data["task"] = task ctx.Data["jobID"] = jobID + ctx.Data["jobName"] = task.JobName ctx.Data["result"] = result ctx.HTML(200, tplModelArtsNotebookShow) } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index de355352f..840d6cf47 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -1031,7 +1031,6 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/modelarts", func() { m.Group("/notebook", func() { - /* v1.0 m.Group("/:jobid", func() { m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug) @@ -1040,15 +1039,6 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Get("/create", reqRepoCloudBrainWriter, repo.NotebookNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsNotebookForm{}), repo.NotebookCreate) - */ - m.Group("/:jobid", func() { - m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) - m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug2) - m.Post("/:action", reqRepoCloudBrainWriter, repo.NotebookManage) - m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.NotebookDel) - }) - m.Get("/create", reqRepoCloudBrainWriter, repo.NotebookNew) - m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsNotebookForm{}), repo.Notebook2Create) }) m.Group("/train-job", func() { diff --git a/templates/repo/debugjob/index.tmpl b/templates/repo/debugjob/index.tmpl index 8cf58dc4f..f093f0258 100755 --- a/templates/repo/debugjob/index.tmpl +++ b/templates/repo/debugjob/index.tmpl @@ -293,7 +293,7 @@
- + {{.Status}}
@@ -607,6 +607,7 @@ function loadJobStatus() { $(".job-status").each((index, job) => { const jobID = job.dataset.jobid; + const jobName = job.dataset.jobname; const repoPath = job.dataset.repopath; const computeResource = job.dataset.resource const initArray = ['STOPPED','FAILED','START_FAILED','CREATE_FAILED','SUCCEEDED','UNAVAILABLE','DELETED','RESIZE_FAILED'] @@ -615,38 +616,39 @@ return } const diffResource = computeResource == "NPU" ? 'modelarts/notebook' : 'cloudbrain' - $.get(`/api/v1/repos/${repoPath}/${diffResource}/${jobID}`, (data) => { - const jobID = data.JobID + const diffApi = computeResource == "NPU" ? jobID : jobName + $.get(`/api/v1/repos/${repoPath}/${diffResource}/${diffApi}`, (data) => { + const jobName = data.JobName const status = data.JobStatus if (status != job.textContent.trim()) { - $('#' + jobID+'-icon').removeClass().addClass(status) - $('#' + jobID+ '-text').text(status) + $('#' + jobName+'-icon').removeClass().addClass(status) + $('#' + jobName+ '-text').text(status) } if(status==="RUNNING"){ - $('#model-debug-'+jobID).removeClass('disabled').addClass('blue').text('调试').css("margin","0 1rem") - $('#model-image-'+jobID).removeClass('disabled').addClass('blue') + $('#model-debug-'+jobName).removeClass('disabled').addClass('blue').text('调试').css("margin","0 1rem") + $('#model-image-'+jobName).removeClass('disabled').addClass('blue') } if(status!=="RUNNING"){ // $('#model-debug-'+jobID).removeClass('blue') // $('#model-debug-'+jobID).addClass('disabled') - $('#model-image-'+jobID).removeClass('blue').addClass('disabled') + $('#model-image-'+jobName).removeClass('blue').addClass('disabled') } if(["CREATING","STOPPING","WAITING","STARTING"].includes(status)){ - $('#model-debug-'+jobID).removeClass('blue').addClass('disabled') + $('#model-debug-'+jobName).removeClass('blue').addClass('disabled') } if(['STOPPED','FAILED','START_FAILED','CREATE_FAILED','SUCCEEDED'].includes(status)){ - $('#model-debug-'+jobID).removeClass('disabled').addClass('blue').text('再次调试').css("margin","0") + $('#model-debug-'+jobName).removeClass('disabled').addClass('blue').text('再次调试').css("margin","0") } if(["RUNNING","WAITING"].includes(status)){ - $('#stop-model-debug-'+jobID).removeClass('disabled').addClass('blue') + $('#stop-model-debug-'+jobName).removeClass('disabled').addClass('blue') } if(["CREATING","STOPPING","STARTING","STOPPED","FAILED","START_FAILED","SUCCEEDED"].includes(status)){ - $('#stop-model-debug-'+jobID).removeClass('blue').addClass('disabled') + $('#stop-model-debug-'+jobName).removeClass('blue').addClass('disabled') } if(status==="STOPPED" || status==="FAILED"|| status==="START_FAILED"){ - $('#model-delete-'+jobID).removeClass('disabled').addClass('blue') + $('#model-delete-'+jobName).removeClass('disabled').addClass('blue') }else{ - $('#model-delete-'+jobID).removeClass('blue').addClass('disabled') + $('#model-delete-'+jobName).removeClass('blue').addClass('disabled') } }).fail(function(err) { console.log(err); From 341e91b2360b866d7261b4c1edf97f62fb614ff6 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 17 Feb 2022 14:59:49 +0800 Subject: [PATCH 3/5] fix-bug --- routers/routes/routes.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 840d6cf47..0f1abe5e8 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -1031,14 +1031,22 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/modelarts", func() { m.Group("/notebook", func() { + // m.Group("/:jobid", func() { + // m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) + // m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug) + // m.Post("/:action", reqRepoCloudBrainWriter, repo.NotebookManage) + // m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.NotebookDel) + // }) + // m.Get("/create", reqRepoCloudBrainWriter, repo.NotebookNew) + // m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsNotebookForm{}), repo.NotebookCreate) m.Group("/:jobid", func() { m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) - m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug) + m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug2) m.Post("/:action", reqRepoCloudBrainWriter, repo.NotebookManage) m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.NotebookDel) }) m.Get("/create", reqRepoCloudBrainWriter, repo.NotebookNew) - m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsNotebookForm{}), repo.NotebookCreate) + m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsNotebookForm{}), repo.Notebook2Create) }) m.Group("/train-job", func() { From 84928acefa7d7a504cb0019d3f87376c6c0db5cf Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 17 Feb 2022 15:03:31 +0800 Subject: [PATCH 4/5] fix 1509 --- routers/repo/cloudbrain.go | 3 ++- routers/repo/modelarts.go | 3 ++- templates/repo/debugjob/index.tmpl | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 0599fb03f..5f9e81901 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -582,12 +582,13 @@ func logErrorAndUpdateJobStatus(err error, taskInfo *models.Cloudbrain) { } func CloudBrainDel(ctx *context.Context) { + var listType = ctx.Query("debugListType") if err := deleteCloudbrainJob(ctx); err != nil { log.Error("deleteCloudbrainJob failed: %v", err, ctx.Data["msgID"]) ctx.ServerError(err.Error(), err) return } - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob?debugListType=all") + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob?debugListType=" + listType) } func deleteCloudbrainJob(ctx *context.Context) error { diff --git a/routers/repo/modelarts.go b/routers/repo/modelarts.go index 9dea34c82..8d5d03353 100755 --- a/routers/repo/modelarts.go +++ b/routers/repo/modelarts.go @@ -417,6 +417,7 @@ func NotebookManage(ctx *context.Context) { func NotebookDel(ctx *context.Context) { var jobID = ctx.Params(":jobid") + var listType = ctx.Query("debugListType") task := ctx.Cloudbrain if task.Status != string(models.ModelArtsCreateFailed) && task.Status != string(models.ModelArtsStartFailed) && task.Status != string(models.ModelArtsStopped) { @@ -442,7 +443,7 @@ func NotebookDel(ctx *context.Context) { return } - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob?debugListType=all") + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob?debugListType=" + listType) } func TrainJobIndex(ctx *context.Context) { diff --git a/templates/repo/debugjob/index.tmpl b/templates/repo/debugjob/index.tmpl index f7773cf2d..ef06d12b6 100755 --- a/templates/repo/debugjob/index.tmpl +++ b/templates/repo/debugjob/index.tmpl @@ -366,7 +366,7 @@
- + {{$.CsrfTokenHtml}} {{if .CanDel}} From dda9a7ee777ea6c7fedf381b41d06a633b1508d2 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 17 Feb 2022 15:04:53 +0800 Subject: [PATCH 5/5] fix-bug --- routers/routes/routes.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 0f1abe5e8..de355352f 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -1031,14 +1031,16 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/modelarts", func() { m.Group("/notebook", func() { - // m.Group("/:jobid", func() { - // m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) - // m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug) - // m.Post("/:action", reqRepoCloudBrainWriter, repo.NotebookManage) - // m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.NotebookDel) - // }) - // m.Get("/create", reqRepoCloudBrainWriter, repo.NotebookNew) - // m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsNotebookForm{}), repo.NotebookCreate) + /* v1.0 + m.Group("/:jobid", func() { + m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) + m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug) + m.Post("/:action", reqRepoCloudBrainWriter, repo.NotebookManage) + m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.NotebookDel) + }) + m.Get("/create", reqRepoCloudBrainWriter, repo.NotebookNew) + m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsNotebookForm{}), repo.NotebookCreate) + */ m.Group("/:jobid", func() { m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug2)