Browse Source

Revert "#3157"

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

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

@@ -607,24 +607,6 @@ 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) {
@@ -668,7 +650,10 @@ func CloudbrainGetLog(ctx *context.APIContext) {
content = content + ctx.Data["existStr"].(string)
}
logFileName := result["FileName"]
canLogDownload := logFileName != nil && logFileName != ""

//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)

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


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

@@ -274,21 +274,6 @@ 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())
@@ -305,12 +290,15 @@ func TrainJobGetLog(ctx *context.APIContext) {
"EndLine": result.EndLine,
"Content": result.Content,
"Lines": result.Lines,
"CanLogDownload": canLogDownload(task),
"CanLogDownload": canLogDownload(ctx.User, task),
"StartTime": task.StartTime,
})
}

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


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

@@ -935,25 +935,17 @@ 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": true,
"CanLogDownload": canLogDownload,
})

return


Loading…
Cancel
Save