| @@ -12,6 +12,7 @@ import ( | |||||
| "net/http" | "net/http" | ||||
| "os" | "os" | ||||
| "sort" | "sort" | ||||
| "strconv" | |||||
| "strings" | "strings" | ||||
| "time" | "time" | ||||
| @@ -405,13 +406,67 @@ func ModelSafetyGetLog(ctx *context.APIContext) { | |||||
| log.Info("existStr=" + existStr) | log.Info("existStr=" + existStr) | ||||
| CloudbrainGetLog(ctx) | CloudbrainGetLog(ctx) | ||||
| } else if job.Type == models.TypeCloudBrainTwo { | } else if job.Type == models.TypeCloudBrainTwo { | ||||
| TrainJobForModelConvertGetLog(ctx) | |||||
| //TrainJobForModelConvertGetLog(ctx) | |||||
| var baseLine = ctx.Query("base_line") | |||||
| var order = ctx.Query("order") | |||||
| var lines = ctx.Query("lines") | |||||
| lines_int, err := strconv.Atoi(lines) | |||||
| if err != nil { | |||||
| log.Error("change lines(%d) string to int failed", lines_int) | |||||
| } | |||||
| if order != modelarts.OrderDesc && order != modelarts.OrderAsc { | |||||
| log.Error("order(%s) check failed", order) | |||||
| ctx.JSON(http.StatusBadRequest, map[string]interface{}{ | |||||
| "err_msg": "order check failed", | |||||
| }) | |||||
| return | |||||
| } | |||||
| resultLogFile, err := modelarts.GetTrainJobLogFileNames(job.JobID, strconv.FormatInt(job.VersionID, 10)) | |||||
| if err != nil { | |||||
| log.Error("GetTrainJobLogFileNames(%s) failed:%v", job.JobID, err.Error()) | |||||
| } | |||||
| result, err := modelarts.GetTrainJobLog(job.JobID, strconv.FormatInt(job.VersionID, 10), baseLine, resultLogFile.LogFileList[0], order, lines_int) | |||||
| if err != nil { | |||||
| log.Error("GetTrainJobLog(%s) failed:%v", job.JobID, err.Error()) | |||||
| } | |||||
| if err != nil { | |||||
| log.Error("trainJobGetLog(%s) failed:%v", job.JobID, err.Error()) | |||||
| // ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil) | |||||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||||
| "JobID": job.JobID, | |||||
| "LogFileName": "", | |||||
| "StartLine": "0", | |||||
| "EndLine": "0", | |||||
| "Content": "", | |||||
| "Lines": 0, | |||||
| "CanLogDownload": false, | |||||
| }) | |||||
| return | |||||
| } | |||||
| ctx.Data["log_file_name"] = resultLogFile.LogFileList[0] | |||||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||||
| "JobID": job.JobID, | |||||
| "LogFileName": resultLogFile.LogFileList[0], | |||||
| "StartLine": result.StartLine, | |||||
| "EndLine": result.EndLine, | |||||
| "Content": result.Content, | |||||
| "Lines": result.Lines, | |||||
| "CanLogDownload": isCanDownloadLog(ctx, job), | |||||
| }) | |||||
| } | } | ||||
| } | } | ||||
| //result := "" | //result := "" | ||||
| //ctx.JSON(http.StatusOK, result) | //ctx.JSON(http.StatusOK, result) | ||||
| } | } | ||||
| func isCanDownloadLog(ctx *context.APIContext, job *models.Cloudbrain) bool { | |||||
| if !ctx.IsSigned { | |||||
| return false | |||||
| } | |||||
| return ctx.IsUserSiteAdmin() || ctx.User.ID == job.UserID | |||||
| } | |||||
| func ModelSafetyDownloadLogFile(ctx *context.Context) { | func ModelSafetyDownloadLogFile(ctx *context.Context) { | ||||
| } | } | ||||