|
|
|
@@ -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 |
|
|
|
|