Browse Source

Merge branch 'fix-2833' of git.openi.org.cn:OpenI/aiforge into fix-2833

tags/v1.22.9.1^2
zhoupzh 3 years ago
parent
commit
8118f946b5
1 changed files with 12 additions and 8 deletions
  1. +12
    -8
      routers/api/v1/repo/cloudbrain.go

+ 12
- 8
routers/api/v1/repo/cloudbrain.go View File

@@ -415,8 +415,12 @@ func CloudbrainGetLog(ctx *context.Context) {
baseLine := ctx.Query("base_line") baseLine := ctx.Query("base_line")
order := ctx.Query("order") order := ctx.Query("order")
var result map[string]interface{} var result map[string]interface{}
resultPath := "/model"
if job.JobType == string(models.JobTypeInference) {
resultPath = "/result"
}
if baseLine == "" && order == "desc" { if baseLine == "" && order == "desc" {
result = getLastLogFromModelDir(job.JobName, lines)
result = getLastLogFromModelDir(job.JobName, lines, resultPath)
} else { } else {
startLine := ctx.QueryInt("base_line") startLine := ctx.QueryInt("base_line")
endLine := startLine + lines endLine := startLine + lines
@@ -432,7 +436,7 @@ func CloudbrainGetLog(ctx *context.Context) {
} }
} }
} }
result = getLogFromModelDir(job.JobName, startLine, endLine)
result = getLogFromModelDir(job.JobName, startLine, endLine, resultPath)
if result == nil { if result == nil {
log.Error("GetJobLog failed: %v", err, ctx.Data["MsgID"]) log.Error("GetJobLog failed: %v", err, ctx.Data["MsgID"])
ctx.ServerError(err.Error(), err) ctx.ServerError(err.Error(), err)
@@ -476,8 +480,8 @@ func getAllLineFromFile(path string) int {
return count return count
} }


func getLastLogFromModelDir(jobName string, lines int) map[string]interface{} {
prefix := "/" + setting.CBCodePathPrefix + jobName + "/model"
func getLastLogFromModelDir(jobName string, lines int, resultPath string) map[string]interface{} {
prefix := "/" + setting.CBCodePathPrefix + jobName + resultPath
files, err := storage.GetOneLevelAllObjectUnderDirMinio(setting.Attachment.Minio.Bucket, prefix, "") files, err := storage.GetOneLevelAllObjectUnderDirMinio(setting.Attachment.Minio.Bucket, prefix, "")
if err != nil { if err != nil {
log.Error("query cloudbrain model failed: %v", err) log.Error("query cloudbrain model failed: %v", err)
@@ -492,7 +496,7 @@ func getLastLogFromModelDir(jobName string, lines int) map[string]interface{} {
for _, file := range files { for _, file := range files {
if strings.HasSuffix(file.FileName, "log.txt") { if strings.HasSuffix(file.FileName, "log.txt") {
fileName = file.FileName fileName = file.FileName
path := storage.GetMinioPath(jobName+"/model/", file.FileName)
path := storage.GetMinioPath(jobName+resultPath+"/", file.FileName)
allLines = getAllLineFromFile(path) allLines = getAllLineFromFile(path)
startLine = allLines - lines startLine = allLines - lines
if startLine < 0 { if startLine < 0 {
@@ -537,8 +541,8 @@ func getLastLogFromModelDir(jobName string, lines int) map[string]interface{} {
} }
} }


func getLogFromModelDir(jobName string, startLine int, endLine int) map[string]interface{} {
prefix := "/" + setting.CBCodePathPrefix + jobName + "/model"
func getLogFromModelDir(jobName string, startLine int, endLine int, resultPath string) map[string]interface{} {
prefix := "/" + setting.CBCodePathPrefix + jobName + resultPath
files, err := storage.GetOneLevelAllObjectUnderDirMinio(setting.Attachment.Minio.Bucket, prefix, "") files, err := storage.GetOneLevelAllObjectUnderDirMinio(setting.Attachment.Minio.Bucket, prefix, "")
if err != nil { if err != nil {
log.Error("query cloudbrain model failed: %v", err) log.Error("query cloudbrain model failed: %v", err)
@@ -561,7 +565,7 @@ func getLogFromModelDir(jobName string, startLine int, endLine int) map[string]i
for _, file := range files { for _, file := range files {
if strings.HasSuffix(file.FileName, "log.txt") { if strings.HasSuffix(file.FileName, "log.txt") {
fileName = file.FileName fileName = file.FileName
path := storage.GetMinioPath(jobName+"/model/", file.FileName)
path := storage.GetMinioPath(jobName+resultPath+"/", file.FileName)
log.Info("path=" + path) log.Info("path=" + path)
reader, err := os.Open(path) reader, err := os.Open(path)
defer reader.Close() defer reader.Close()


Loading…
Cancel
Save