diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 51d8dd7e8..3676e3c56 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -858,6 +858,7 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Group("/train-job", func() { m.Get("/:jobid", repo.GetModelArtsTrainJob) + m.Get("/log", repo.TrainJobGetLog) }) }, reqRepoReader(models.UnitTypeCloudBrain)) }, repoAssignment()) diff --git a/routers/api/v1/repo/modelarts.go b/routers/api/v1/repo/modelarts.go index 1687c479a..c4793dd99 100755 --- a/routers/api/v1/repo/modelarts.go +++ b/routers/api/v1/repo/modelarts.go @@ -75,3 +75,49 @@ func GetModelArtsTrainJob(ctx *context.APIContext) { }) } + +func TrainJobGetLog(ctx *context.APIContext) { + var ( + err error + ) + + var jobID = ctx.Params(":jobid") + var logFileName = ctx.Query("file_name") + var baseLine = ctx.Query("base_line") + var order = ctx.Query("order") + + 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 + } + + task, err := models.GetCloudbrainByJobID(jobID) + if err != nil { + log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error()) + ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ + "err_msg": "GetCloudbrainByJobID failed", + }) + return + } + + result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), baseLine, logFileName, order, 20) + if err != nil { + log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error()) + ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ + "err_msg": "GetTrainJobLog failed", + }) + return + } + + ctx.Data["log"] = result + + ctx.JSON(http.StatusOK, map[string]interface{}{ + "JobID": jobID, + "StartLine": result.StartLine, + "EndLine": result.EndLine, + "Content": result.Content, + }) +}