From 5fbc6b1862351241c248366ad83bf59bd0b216f3 Mon Sep 17 00:00:00 2001 From: zouap Date: Fri, 19 Aug 2022 09:43:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4GPU=E8=AE=AD=E7=BB=83?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E6=97=A5=E5=BF=97=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E3=80=82#2706?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/cloudbrain.go | 43 ++++++++++++++++++++++++++++++++++++++ routers/routes/routes.go | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index c3c6c43cb..ffa4b8dd6 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -2885,3 +2885,46 @@ func getFlavorNameByFlavorCode(flavorCode string) string { "核" + strconv.Itoa(cardNum*256) + "GB" return cloudbrainTwoFlavorName } + +func GetLogFromModelDir(ctx *context.Context) { + prefix := "/" + setting.CBCodePathPrefix + ctx.Cloudbrain.JobName + files, err := storage.GetOneLevelAllObjectUnderDirMinio(setting.Attachment.Minio.Bucket, prefix, "") + if err != nil { + log.Error("query cloudbrain model failed: %v", err) + return + } + startLine := ctx.QueryInt("startLine") + endLine := ctx.QueryInt("endLine") + re := "" + for _, file := range files { + if strings.HasSuffix(file.FileName, "log.txt") { + reader, err := os.Open(storage.GetMinioPath(ctx.Cloudbrain.JobName, file.FileName)) + defer reader.Close() + if err == nil { + r := bufio.NewReader(reader) + for i := 0; i < endLine; i++ { + line, error := r.ReadString('\n') + if error == io.EOF { + log.Info("read file completed.") + break + } + if error != nil { + log.Info("read file error." + error.Error()) + break + } + if error == nil { + if i >= startLine { + re = re + line + } + } + } + } + break + } + } + + ctx.JSON(http.StatusOK, map[string]interface{}{ + "JobName": ctx.Cloudbrain.JobName, + "Content": re, + }) +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index a4bc09472..8c2020e05 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -1100,7 +1100,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRightForTrain, repo.CloudBrainTrainJobDel) //m.Get("/models", reqRepoCloudBrainReader, repo.CloudBrainShowModels) m.Get("/download_model", cloudbrain.AdminOrOwnerOrJobCreaterRightForTrain, repo.CloudBrainDownloadModel) - //m.Get("/create_version", reqWechatBind, cloudbrain.AdminOrJobCreaterRightForTrain, repo.TrainJobNewVersion) + m.Get("/get_log", cloudbrain.AdminOrJobCreaterRightForTrain, repo.GetLogFromModelDir) //m.Post("/create_version", reqWechatBind, cloudbrain.AdminOrJobCreaterRightForTrain, bindIgnErr(auth.CreateModelArtsTrainJobForm{}), repo.TrainJobCreateVersion) }) m.Get("/create", reqWechatBind, reqRepoCloudBrainWriter, repo.CloudBrainTrainJobNew)