Browse Source

get log

tags/v1.22.1.3
lewis 3 years ago
parent
commit
f6111c6315
6 changed files with 93 additions and 5 deletions
  1. +37
    -0
      models/cloudbrain.go
  2. +28
    -0
      modules/cloudbrain/resty.go
  3. +1
    -0
      routers/api/v1/api.go
  4. +23
    -0
      routers/api/v1/repo/cloudbrain.go
  5. +4
    -4
      routers/repo/cloudbrain.go
  6. +0
    -1
      routers/routes/routes.go

+ 37
- 0
models/cloudbrain.go View File

@@ -453,6 +453,43 @@ type CommitImageResult struct {
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 {
Code string `json:"code"`
Msg string `json:"msg"`


+ 28
- 0
modules/cloudbrain/resty.go View File

@@ -270,3 +270,31 @@ sendjob:

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
}

+ 1
- 0
routers/api/v1/api.go View File

@@ -878,6 +878,7 @@ func RegisterRoutes(m *macaron.Macaron) {
}, reqAnyRepoReader())
m.Group("/cloudbrain", func() {
m.Get("/:jobid", repo.GetCloudbrainTask)
m.Get("/:jobid/log", repo.CloudbrainGetLog)
}, reqRepoReader(models.UnitTypeCloudBrain))
m.Group("/modelarts", func() {
m.Group("/notebook", func() {


+ 23
- 0
routers/api/v1/repo/cloudbrain.go View File

@@ -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
}

+ 4
- 4
routers/repo/cloudbrain.go View File

@@ -1072,10 +1072,10 @@ func getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID int) (string,
}

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
isExist = true
break


+ 0
- 1
routers/routes/routes.go View File

@@ -987,7 +987,6 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.CloudBrainStop)
m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.BenchmarkDel)
m.Get("/rate", reqRepoCloudBrainReader, repo.GetRate)
//m.Get("/log", reqRepoCloudBrainReader, repo.BenchmarkGetLog)
})
m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainBenchmarkNew)
m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainBenchmarkCreate)


Loading…
Cancel
Save