From a0479daf2ea3e524126d0f201d22b27aa735b817 Mon Sep 17 00:00:00 2001 From: Gitea Date: Wed, 27 Oct 2021 16:11:01 +0800 Subject: [PATCH] commit --- modules/modelarts/modelarts.go | 6 +-- routers/repo/cloudbrain.go | 52 +++++++++++++++----- routers/routes/routes.go | 2 +- templates/repo/modelarts/trainjob/index.tmpl | 2 +- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/modules/modelarts/modelarts.go b/modules/modelarts/modelarts.go index a0d068b56..59cff4238 100755 --- a/modules/modelarts/modelarts.go +++ b/modules/modelarts/modelarts.go @@ -221,7 +221,7 @@ func TransTrainJobStatus(status int) string { case 0: return "UNKNOWN" case 1: - return "INIT" + return "CREATING" case 2: return "IMAGE_CREATING" case 3: @@ -237,13 +237,13 @@ func TransTrainJobStatus(status int) string { case 8: return "RUNNING" case 9: - return "KILLING" + return "STOPED" case 10: return "COMPLETED" case 11: return "FAILED" case 12: - return "KILLED" + return "STOPED" case 13: return "CANCELED" case 14: diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 33e8b807f..d6f78a80e 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -202,7 +202,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { gpuQueue := setting.JobType codePath := setting.JobPath + jobName + cloudbrain.CodeMountPath resourceSpecId := form.ResourceSpecId - + if !jobNamePattern.MatchString(jobName) { ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_jobname_err"), tplModelArtsNew, &form) return @@ -474,7 +474,7 @@ func CloudBrainDel(ctx *context.Context) { return } - if task.Status != string(models.JobStopped) && task.Status != string(models.JobFailed){ + if task.Status != string(models.JobStopped) && task.Status != string(models.JobFailed) { log.Error("the job(%s) has not been stopped", task.JobName, ctx.Data["msgID"]) ctx.ServerError("the job has not been stopped", errors.New("the job has not been stopped")) return @@ -584,19 +584,47 @@ func CloudBrainDownloadModel(ctx *context.Context) { http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) } +// func TrainJobloadModel(ctx *context.Context) { +// parentDir := ctx.Query("parentDir") +// fileName := ctx.Query("fileName") +// jobName := ctx.Query("jobName") +// filePath := "jobs/" + jobName + "/model/" + parentDir +// url, err := storage.Attachments.PresignedGetURL(filePath, fileName) +// if err != nil { +// log.Error("PresignedGetURL failed: %v", err.Error(), ctx.Data["msgID"]) +// ctx.ServerError("PresignedGetURL", err) +// return +// } + +// http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) +// } + func TrainJobloadModel(ctx *context.Context) { - parentDir := ctx.Query("parentDir") - fileName := ctx.Query("fileName") - jobName := ctx.Query("jobName") - filePath := "jobs/" + jobName + "/model/" + parentDir - url, err := storage.Attachments.PresignedGetURL(filePath, fileName) + uuid := ctx.Query("uuid") + fileName := ctx.Query("file_name") + + body, err := storage.ObsDownload(uuid, fileName) if err != nil { - log.Error("PresignedGetURL failed: %v", err.Error(), ctx.Data["msgID"]) - ctx.ServerError("PresignedGetURL", err) - return + log.Info("download error.") + } else { + defer body.Close() + ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+fileName) + ctx.Resp.Header().Set("Content-Type", "application/octet-stream") + p := make([]byte, 1024) + var readErr error + var readCount int + // 读取对象内容 + for { + readCount, readErr = body.Read(p) + if readCount > 0 { + ctx.Resp.Write(p[:readCount]) + //fmt.Printf("%s", p[:readCount]) + } + if readErr != nil { + break + } + } } - - http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) } func GetRate(ctx *context.Context) { diff --git a/routers/routes/routes.go b/routers/routes/routes.go index b7b9333d0..69c03c42f 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -991,11 +991,11 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/stop", reqRepoCloudBrainWriter, repo.TrainJobStop) m.Post("/del", reqRepoCloudBrainWriter, repo.TrainJobDel) m.Get("/log", reqRepoCloudBrainReader, repo.TrainJobGetLog) + m.Get("/download_model", reqRepoCloudBrainReader, repo.TrainJobloadModel) }) m.Get("/create", reqRepoCloudBrainReader, repo.TrainJobNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsTrainJobForm{}), repo.TrainJobCreate) m.Get("/para-config-list", reqRepoCloudBrainReader, repo.TrainJobGetConfigList) - m.Get("/download_model", reqRepoCloudBrainReader, repo.TrainJobloadModel) }) }, context.RepoRef()) diff --git a/templates/repo/modelarts/trainjob/index.tmpl b/templates/repo/modelarts/trainjob/index.tmpl index f6fbf9c51..807442340 100755 --- a/templates/repo/modelarts/trainjob/index.tmpl +++ b/templates/repo/modelarts/trainjob/index.tmpl @@ -360,7 +360,7 @@
- + 模型下载