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)