| @@ -453,6 +453,43 @@ type CommitImageResult struct { | |||||
| Payload map[string]interface{} `json:"payload"` | Payload map[string]interface{} `json:"payload"` | ||||
| } | } | ||||
| type GetJobLogParams struct { | |||||
| QueryInfo QueryInfo `json:"query"` | |||||
| } | |||||
| type QueryInfo struct { | |||||
| Size string `json:"size"` | |||||
| Sort string `json:"sort"` | |||||
| MatchInfo MatchInfo `json:"match"` | |||||
| } | |||||
| type MatchInfo struct { | |||||
| PodName string `json:"kubernetes.pod.name"` | |||||
| } | |||||
| type GetJobLogResult struct { | |||||
| ScrollID string `json:"_scroll_id"` | |||||
| Took string `json:"took"` | |||||
| TimedOut bool `json:"timed_out"` | |||||
| Shards struct { | |||||
| Total int `json:"total"` | |||||
| Successful int `json:"successful"` | |||||
| Skipped int `json:"skipped"` | |||||
| Failed int `json:"failed"` | |||||
| } `json:"_shards"` | |||||
| Hits struct { | |||||
| Hits []struct { | |||||
| Index string `json:"_index"` | |||||
| Type string `json:"_type"` | |||||
| ID string `json:"_id"` | |||||
| Source struct { | |||||
| Message string `json:"message"` | |||||
| } `json:"_source"` | |||||
| Sort []int `json:"sort"` | |||||
| } `json:"hits"` | |||||
| } `json:"hits"` | |||||
| } | |||||
| type CloudBrainResult struct { | type CloudBrainResult struct { | ||||
| Code string `json:"code"` | Code string `json:"code"` | ||||
| Msg string `json:"msg"` | Msg string `json:"msg"` | ||||
| @@ -270,3 +270,31 @@ sendjob: | |||||
| return nil | return nil | ||||
| } | } | ||||
| func GetJobLog(jobID string) (*models.GetJobLogResult, error) { | |||||
| checkSetting() | |||||
| client := getRestyClient() | |||||
| var result models.GetJobLogResult | |||||
| req := models.GetJobLogParams{ | |||||
| QueryInfo: models.QueryInfo{ | |||||
| Size: "5000", | |||||
| Sort: "log.offset", | |||||
| MatchInfo: models.MatchInfo{ | |||||
| PodName: jobID + "task1-0", | |||||
| }, | |||||
| }, | |||||
| } | |||||
| res, err := client.R(). | |||||
| SetHeader("Content-Type", "application/json"). | |||||
| SetAuthToken(TOKEN). | |||||
| SetBody(req). | |||||
| SetResult(&result). | |||||
| Post(HOST + "/es/_search?_source=message&scroll=5m") | |||||
| if err != nil { | |||||
| return &result, fmt.Errorf("resty GetJobLog: %v, %s", err, res.String()) | |||||
| } | |||||
| return &result, nil | |||||
| } | |||||
| @@ -878,6 +878,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| }, reqAnyRepoReader()) | }, reqAnyRepoReader()) | ||||
| m.Group("/cloudbrain", func() { | m.Group("/cloudbrain", func() { | ||||
| m.Get("/:jobid", repo.GetCloudbrainTask) | m.Get("/:jobid", repo.GetCloudbrainTask) | ||||
| m.Get("/:jobid/log", repo.CloudbrainGetLog) | |||||
| }, reqRepoReader(models.UnitTypeCloudBrain)) | }, reqRepoReader(models.UnitTypeCloudBrain)) | ||||
| m.Group("/modelarts", func() { | m.Group("/modelarts", func() { | ||||
| m.Group("/notebook", func() { | m.Group("/notebook", func() { | ||||
| @@ -91,3 +91,26 @@ func GetCloudbrainTask(ctx *context.APIContext) { | |||||
| }) | }) | ||||
| } | } | ||||
| func CloudbrainGetLog(ctx *context.Context) { | |||||
| jobID := ctx.Params(":jobid") | |||||
| _, err := models.GetCloudbrainByJobID(jobID) | |||||
| if err != nil { | |||||
| log.Error("GetCloudbrainByJobID failed: %v", err, ctx.Data["msgID"]) | |||||
| ctx.ServerError(err.Error(), err) | |||||
| return | |||||
| } | |||||
| result, err := cloudbrain.GetJobLog(jobID) | |||||
| if err != nil{ | |||||
| log.Error("GetJobLog failed: %v", err, ctx.Data["MsgID"]) | |||||
| return | |||||
| } | |||||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||||
| "JobID": jobID, | |||||
| "Content": result.Hits, | |||||
| }) | |||||
| return | |||||
| } | |||||
| @@ -1072,10 +1072,10 @@ func getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID int) (string, | |||||
| } | } | ||||
| var isExist bool | var isExist bool | ||||
| for id, benchmarkType := range benchmarkTypes.BenchmarkType { | |||||
| if id == benchmarkTypeID { | |||||
| for childID, childType := range benchmarkType.Second { | |||||
| if childID == benchmarkChildTypeID { | |||||
| for _, benchmarkType := range benchmarkTypes.BenchmarkType { | |||||
| if benchmarkType.Id == benchmarkTypeID { | |||||
| for _, childType := range benchmarkType.Second { | |||||
| if childType.Id == benchmarkChildTypeID { | |||||
| uuid = childType.Attachment | uuid = childType.Attachment | ||||
| isExist = true | isExist = true | ||||
| break | break | ||||
| @@ -987,7 +987,6 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.CloudBrainStop) | m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.CloudBrainStop) | ||||
| m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.BenchmarkDel) | m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.BenchmarkDel) | ||||
| m.Get("/rate", reqRepoCloudBrainReader, repo.GetRate) | m.Get("/rate", reqRepoCloudBrainReader, repo.GetRate) | ||||
| //m.Get("/log", reqRepoCloudBrainReader, repo.BenchmarkGetLog) | |||||
| }) | }) | ||||
| m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainBenchmarkNew) | m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainBenchmarkNew) | ||||
| m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainBenchmarkCreate) | m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainBenchmarkCreate) | ||||