From 8f7d693ca9770f6fda70b01dbd3589b996cfc01d Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 30 Dec 2021 14:40:31 +0800 Subject: [PATCH] update --- routers/api/v1/api.go | 2 +- routers/repo/modelarts.go | 74 ++++++++++------------------------------------- routers/routes/routes.go | 4 +-- 3 files changed, 17 insertions(+), 63 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index a6a59f797..0da52ed09 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -888,7 +888,7 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Group("/inference-job", func() { m.Group("/:jobid", func() { - m.Get("", repo.GetModelArtsInferenceJob) + // m.Get("", repo.GetModelArtsInferenceJob) m.Get("/log", repo.TrainJobGetLog) m.Post("/del_version", repo.DelTrainJobVersion) m.Post("/stop_version", repo.StopTrainJobVersion) diff --git a/routers/repo/modelarts.go b/routers/repo/modelarts.go index f06123f76..c28f18f5d 100755 --- a/routers/repo/modelarts.go +++ b/routers/repo/modelarts.go @@ -1894,6 +1894,9 @@ func inferenceJobErrorNewDataPrepare(ctx *context.Context, form auth.CreateModel ctx.Data["bootFile"] = form.BootFile ctx.Data["uuid"] = form.Attachment ctx.Data["branch_name"] = form.BranchName + ctx.Data["model_name"] = form.ModelName + ctx.Data["model_version"] = form.ModelVersion + ctx.Data["ckpt_name"] = form.CkptName return nil } @@ -1945,52 +1948,6 @@ func InferenceJobShow(ctx *context.Context) { ctx.Data["task"] = task ctx.HTML(http.StatusOK, tplModelArtsInferenceJobShow) } -func InferenceJobStop(ctx *context.Context) { - var jobID = ctx.Params(":jobid") - task, err := models.GetCloudbrainByJobID(jobID) - if err != nil { - log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error()) - ctx.RenderWithErr(err.Error(), tplModelArtsInferenceJobIndex, nil) - return - } - - _, err = modelarts.StopTrainJob(jobID, strconv.FormatInt(task.VersionID, 10)) - if err != nil { - log.Error("StopInferenceJob(%s) failed:%v", task.JobName, err.Error()) - ctx.RenderWithErr(err.Error(), tplModelArtsInferenceJobIndex, nil) - return - } - - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/inference-job") -} - -func InferenceJobDel(ctx *context.Context) { - var jobID = ctx.Params(":jobid") - - task, err := models.GetCloudbrainByJobID(jobID) - if err != nil { - log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error()) - ctx.RenderWithErr(err.Error(), tplModelArtsInferenceJobIndex, nil) - return - } - - //删除modelarts上的任务记录 - _, err = modelarts.DelTrainJob(jobID) - if err != nil { - log.Error("DelInferenceJob(%s) failed:%v", jobID, err.Error()) - ctx.RenderWithErr(err.Error(), tplModelArtsInferenceJobIndex, nil) - return - } - - //删除数据库Cloudbrain表的记录 - err = models.DeleteJob(task) - if err != nil { - ctx.ServerError("DeleteJob failed", err) - return - } - - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/inference-job") -} func ResultDownload(ctx *context.Context) { var ( @@ -2036,28 +1993,27 @@ func DeleteJobStorage(jobName string) error { } func DownloadMultiResultFile(ctx *context.Context) { - log.Info("DownloadMultiModelFile start.") - id := ctx.Query("ID") - log.Info("id=" + id) - task, err := models.QueryModelById(id) + var jobID = ctx.Params(":jobid") + var versionName = ctx.Query("version_name") + task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName) if err != nil { - log.Error("no such model!", err.Error()) - ctx.ServerError("no such model:", err) - return - } - if !isCanDeleteOrDownload(ctx, task) { - ctx.ServerError("no right.", errors.New(ctx.Tr("repo.model_noright"))) + log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error()) return } + // if !isCanDeleteOrDownload(ctx, task) { + // ctx.ServerError("no right.", errors.New(ctx.Tr("repo.model_noright"))) + // return + // } - path := Model_prefix + models.AttachmentRelativePath(id) + "/" + // path := Model_prefix + models.AttachmentRelativePath(id) + "/" + path := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, "result/", versionName), "/") allFile, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, path) if err == nil { //count++ - models.ModifyModelDownloadCount(id) + // models.ModifyModelDownloadCount(id) - returnFileName := task.Name + "_" + task.Version + ".zip" + returnFileName := task.JobName + "_" + task.VersionName + ".zip" ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+returnFileName) ctx.Resp.Header().Set("Content-Type", "application/octet-stream") w := zip.NewWriter(ctx.Resp) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 1c5fa7b1d..45ebe9690 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -1036,9 +1036,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("", reqRepoCloudBrainReader, repo.InferenceJobIndex) m.Group("/:jobid", func() { m.Get("", reqRepoCloudBrainReader, repo.InferenceJobShow) - m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.InferenceJobStop) - m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.InferenceJobDel) - m.Get("/downloadall", repo.DownloadMultiResultFile) + m.Get("/downloadall", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.DownloadMultiResultFile) }) m.Get("/create", reqRepoCloudBrainWriter, repo.InferenceJobNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsInferenceJobForm{}), repo.InferenceJobCreate)