Browse Source

调整GPU训练任务的日志显示逻辑。#2706

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.8.2^2
zouap 3 years ago
parent
commit
1a37b35523
2 changed files with 57 additions and 4 deletions
  1. +56
    -3
      routers/api/v1/repo/cloudbrain.go
  2. +1
    -1
      routers/routes/routes.go

+ 56
- 3
routers/api/v1/repo/cloudbrain.go View File

@@ -6,13 +6,17 @@
package repo

import (
"code.gitea.io/gitea/modules/notification"
"bufio"
"encoding/json"
"io"
"net/http"
"os"
"sort"
"strings"
"time"

"code.gitea.io/gitea/modules/notification"

"code.gitea.io/gitea/modules/setting"

"code.gitea.io/gitea/models"
@@ -368,14 +372,16 @@ func CloudbrainForModelConvertGetLog(ctx *context.Context) {

func CloudbrainGetLog(ctx *context.Context) {
ID := ctx.Params(":id")
startLine := ctx.QueryInt("startLine")
endLine := ctx.QueryInt("endLine")
job, err := models.GetCloudbrainByID(ID)
if err != nil {
log.Error("GetCloudbrainByJobName failed: %v", err, ctx.Data["MsgID"])
ctx.ServerError(err.Error(), err)
return
}
result := CloudbrainGetLogByJobId(job.JobID, job.JobName)
result := GetLogFromModelDir(job.JobName, startLine, endLine)
//result := CloudbrainGetLogByJobId(job.JobID, job.JobName)
if result == nil {
log.Error("GetJobLog failed: %v", err, ctx.Data["MsgID"])
ctx.ServerError(err.Error(), err)
@@ -384,6 +390,53 @@ func CloudbrainGetLog(ctx *context.Context) {
ctx.JSON(http.StatusOK, result)
}

func GetLogFromModelDir(jobName string, startLine int, endLine int) map[string]interface{} {
prefix := "/" + setting.CBCodePathPrefix + jobName + "/model"
files, err := storage.GetOneLevelAllObjectUnderDirMinio(setting.Attachment.Minio.Bucket, prefix, "")
if err != nil {
log.Error("query cloudbrain model failed: %v", err)
return nil
}

re := ""
for _, file := range files {
if strings.HasSuffix(file.FileName, "log.txt") {
path := storage.GetMinioPath(jobName+"/model/", file.FileName)
log.Info("path=" + path)
reader, err := os.Open(path)
defer reader.Close()
if err == nil {
r := bufio.NewReader(reader)
for i := 0; i < endLine; i++ {
line, error := r.ReadString('\n')
log.Info("line=" + line)
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
}
}
}
} else {
log.Info("error:" + err.Error())
}
break
}
}

return map[string]interface{}{
"JobName": jobName,
"Content": re,
}
}

func CloudBrainModelConvertList(ctx *context.APIContext) {
var (
err error


+ 1
- 1
routers/routes/routes.go View File

@@ -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("/get_log", cloudbrain.AdminOrJobCreaterRightForTrain, repo.GetLogFromModelDir)
//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)


Loading…
Cancel
Save