From 2c7d9faa07f5ac588e7b09e389bfb6ad6ab4d360 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Fri, 1 Apr 2022 15:11:37 +0800 Subject: [PATCH 1/4] show restart --- models/cloudbrain.go | 16 ++++++++++++++++ routers/repo/cloudbrain.go | 24 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 1662dcd96..67d1b695b 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -1370,6 +1370,16 @@ func getRepoCloudBrain(cb *Cloudbrain) (*Cloudbrain, error) { return cb, nil } +func getRepoCloudBrainWithDeleted(cb *Cloudbrain) (*Cloudbrain, error) { + has, err := x.Unscoped().Get(cb) + if err != nil { + return nil, err + } else if !has { + return nil, ErrJobNotExist{} + } + return cb, nil +} + func GetRepoCloudBrainByJobID(repoID int64, jobID string) (*Cloudbrain, error) { cb := &Cloudbrain{JobID: jobID, RepoID: repoID} return getRepoCloudBrain(cb) @@ -1386,6 +1396,12 @@ func GetCloudbrainByID(id string) (*Cloudbrain, error) { return getRepoCloudBrain(cb) } +func GetCloudbrainByIDWithDeleted(id string) (*Cloudbrain, error) { + idInt64, _ := strconv.ParseInt(id, 10, 64) + cb := &Cloudbrain{ID: idInt64} + return getRepoCloudBrainWithDeleted(cb) +} + func GetCloudbrainByJobIDAndVersionName(jobID string, versionName string) (*Cloudbrain, error) { cb := &Cloudbrain{JobID: jobID, VersionName: versionName} return getRepoCloudBrain(cb) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 898f3844f..9b3cb05d7 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -400,18 +400,22 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo if jobType == models.JobTypeTrain { task, err = models.GetCloudbrainByJobID(ctx.Params(":jobid")) } else { - task, err = models.GetCloudbrainByID(ctx.Params(":id")) + task, err = models.GetCloudbrainByIDWithDeleted(ctx.Params(":id")) } if err != nil { log.Info("error:" + err.Error()) ctx.Data["error"] = err.Error() + return } + result, err := cloudbrain.GetJob(task.JobID) if err != nil { log.Info("error:" + err.Error()) ctx.Data["error"] = err.Error() + return } + if result != nil { jobRes, _ := models.ConvertToJobResultPayload(result.Payload) jobRes.Resource.Memory = strings.ReplaceAll(jobRes.Resource.Memory, "Mi", "MB") @@ -426,6 +430,15 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo ctx.Data["resource_type"] = resourceType.Value } } + } else { + if gpuInfos == nil { + json.Unmarshal([]byte(setting.GpuTypes), &gpuInfos) + } + for _, resourceType := range gpuInfos.GpuInfo { + if resourceType.Queue == jobRes.Config.GpuType { + ctx.Data["resource_type"] = resourceType.Value + } + } } taskRoles := jobRes.TaskRoles if jobRes.JobStatus.State != string(models.JobFailed) { @@ -439,6 +452,7 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo err = models.UpdateJob(task) if err != nil { ctx.Data["error"] = err.Error() + return } } else { task.Status = jobRes.JobStatus.State @@ -455,7 +469,15 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo ctx.Data["result"] = jobRes } else { log.Info("error:" + err.Error()) + return + } + + if task.DeletedAt.IsZero() { //normal record + + } else { //restart record + } + user, err := models.GetUserByID(task.UserID) if err == nil { task.User = user From 027e512fcfb8fac170ca83721d7cf8ed4112bae1 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Fri, 1 Apr 2022 20:49:54 +0800 Subject: [PATCH 2/4] test --- routers/repo/cloudbrain.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 9b3cb05d7..59d16a5d8 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -983,6 +983,7 @@ func uploadCodeToMinio(codePath, jobName, parentDir string) error { destObject := setting.CBCodePathPrefix + jobName + parentDir + file.Name() sourceFile := codePath + file.Name() err = storage.Attachments.UploadObject(destObject, sourceFile) + if err != nil { log.Error("UploadObject(%s) failed: %s", file.Name(), err.Error()) return err From 5935583a2e71ac545ff130505dee98fb744d569e Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Sat, 2 Apr 2022 14:43:16 +0800 Subject: [PATCH 3/4] show restart record --- routers/repo/cloudbrain.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 59d16a5d8..d1465745e 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -449,10 +449,15 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo task.ContainerID = taskRes.TaskStatuses[0].ContainerID task.ContainerIp = taskRes.TaskStatuses[0].ContainerIP models.ParseAndSetDurationFromCloudBrainOne(jobRes, task) - err = models.UpdateJob(task) - if err != nil { - ctx.Data["error"] = err.Error() - return + + if task.DeletedAt.IsZero() { //normal record + err = models.UpdateJob(task) + if err != nil { + ctx.Data["error"] = err.Error() + return + } + } else { //restart record + } } else { task.Status = jobRes.JobStatus.State @@ -472,12 +477,6 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo return } - if task.DeletedAt.IsZero() { //normal record - - } else { //restart record - - } - user, err := models.GetUserByID(task.UserID) if err == nil { task.User = user From 5defcd0c8145ab58509e0466fbb6277d15b9729b Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Sat, 2 Apr 2022 16:11:22 +0800 Subject: [PATCH 4/4] format --- routers/repo/cloudbrain.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index d1465745e..0ddb1e1fe 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -456,7 +456,7 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo ctx.Data["error"] = err.Error() return } - } else { //restart record + } else { //deleted record } } else { @@ -982,7 +982,6 @@ func uploadCodeToMinio(codePath, jobName, parentDir string) error { destObject := setting.CBCodePathPrefix + jobName + parentDir + file.Name() sourceFile := codePath + file.Name() err = storage.Attachments.UploadObject(destObject, sourceFile) - if err != nil { log.Error("UploadObject(%s) failed: %s", file.Name(), err.Error()) return err