Browse Source

#3157

fix bug
tags/v1.22.11.2^2
chenyifan01 2 years ago
parent
commit
3aca1dc074
3 changed files with 46 additions and 11 deletions
  1. +19
    -4
      routers/api/v1/repo/cloudbrain.go
  2. +17
    -5
      routers/api/v1/repo/modelarts.go
  3. +10
    -2
      routers/repo/grampus.go

+ 19
- 4
routers/api/v1/repo/cloudbrain.go View File

@@ -607,6 +607,24 @@ func CloudbrainGetLog(ctx *context.APIContext) {
lines := ctx.QueryInt("lines")
baseLine := ctx.Query("base_line")
order := ctx.Query("order")

//Logs can only be downloaded if the file exists
//and the current user is an administrator or the creator of the task
if !job.IsUserHasRight(ctx.User) {
re := map[string]interface{}{
"JobID": ID,
"LogFileName": "",
"StartLine": 0,
"EndLine": 0,
"Content": "",
"Lines": 0,
"CanLogDownload": false,
"StartTime": job.StartTime,
}
ctx.JSON(http.StatusOK, re)
return
}

var result map[string]interface{}
resultPath := "/model"
if job.JobType == string(models.JobTypeInference) || job.JobType == string(models.JobTypeModelSafety) {
@@ -650,10 +668,7 @@ func CloudbrainGetLog(ctx *context.APIContext) {
content = content + ctx.Data["existStr"].(string)
}
logFileName := result["FileName"]

//Logs can only be downloaded if the file exists
//and the current user is an administrator or the creator of the task
canLogDownload := logFileName != nil && logFileName != "" && job.IsUserHasRight(ctx.User)
canLogDownload := logFileName != nil && logFileName != ""

re := map[string]interface{}{
"JobID": ID,


+ 17
- 5
routers/api/v1/repo/modelarts.go View File

@@ -274,6 +274,21 @@ func TrainJobGetLog(ctx *context.APIContext) {
log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error())
return
}

if !task.IsUserHasRight(ctx.User) {
ctx.JSON(http.StatusOK, map[string]interface{}{
"JobID": jobID,
"LogFileName": "",
"StartLine": 0,
"EndLine": 0,
"Content": "",
"Lines": 0,
"CanLogDownload": false,
"StartTime": task.StartTime,
})
return
}

resultLogFile, result, err := trainJobGetLogContent(jobID, task.VersionID, baseLine, order, lines_int)
if err != nil {
log.Error("trainJobGetLog(%s) failed:%v", jobID, err.Error())
@@ -290,15 +305,12 @@ func TrainJobGetLog(ctx *context.APIContext) {
"EndLine": result.EndLine,
"Content": result.Content,
"Lines": result.Lines,
"CanLogDownload": canLogDownload(ctx.User, task),
"CanLogDownload": canLogDownload(task),
"StartTime": task.StartTime,
})
}

func canLogDownload(user *models.User, task *models.Cloudbrain) bool {
if task == nil || !task.IsUserHasRight(user) {
return false
}
func canLogDownload(task *models.Cloudbrain) bool {
prefix := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, modelarts.LogPath, task.VersionName), "/") + "/job"
_, err := storage.GetObsLogFileName(prefix)
if err != nil {


+ 10
- 2
routers/repo/grampus.go View File

@@ -935,17 +935,25 @@ func GrampusGetLog(ctx *context.Context) {
return
}

if !job.IsUserHasRight(ctx.User) {
ctx.JSON(http.StatusOK, map[string]interface{}{
"JobName": job.JobName,
"Content": "",
"CanLogDownload": false,
})
return
}

content, err := grampus.GetTrainJobLog(job.JobID)
if err != nil {
log.Error("GetTrainJobLog failed: %v", err, ctx.Data["MsgID"])
ctx.ServerError(err.Error(), err)
return
}
canLogDownload := err == nil && job.IsUserHasRight(ctx.User)
ctx.JSON(http.StatusOK, map[string]interface{}{
"JobName": job.JobName,
"Content": content,
"CanLogDownload": canLogDownload,
"CanLogDownload": true,
})

return


Loading…
Cancel
Save