Browse Source

parse task result

tags/v1.21.12.1
palytoxin 5 years ago
parent
commit
c83397ac56
3 changed files with 98 additions and 1 deletions
  1. +91
    -0
      models/cloudbrain.go
  2. +5
    -1
      routers/repo/cloudbrain.go
  3. +2
    -0
      templates/repo/cloudbrain/show.tmpl

+ 91
- 0
models/cloudbrain.go View File

@@ -1,8 +1,10 @@
package models

import (
"encoding/json"
"errors"
"fmt"
"time"

"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
@@ -81,6 +83,95 @@ type CloudbrainsOptions struct {
SortType string
CloudbrainIDs []int64
}
type TaskPod struct {
TaskRoleStatus struct {
Name string `json:"name"`
} `json:"taskRoleStatus"`
TaskStatuses []struct {
TaskIndex int `json:"taskIndex"`
PodUID string `json:"podUid"`
PodIP string `json:"podIp"`
PodName string `json:"podName"`
ContainerID string `json:"containerId"`
ContainerIP string `json:"containerIp"`
ContainerGpus string `json:"containerGpus"`
State string `json:"state"`
StartAt time.Time `json:"startAt"`
FinishedAt time.Time `json:"finishedAt"`
ExitCode int `json:"exitCode"`
ExitDiagnostics string `json:"exitDiagnostics"`
RetriedCount int `json:"retriedCount"`
} `json:"taskStatuses"`
}

func ConvertToTaskPod(input map[string]interface{}) (TaskPod, error) {
data, _ := json.Marshal(input)
var taskPod TaskPod
err := json.Unmarshal(data, &taskPod)
return taskPod, err
}

type JobResultPayload struct {
ID string `json:"id"`
Name string `json:"name"`
Platform string `json:"platform"`
JobStatus struct {
Username string `json:"username"`
State string `json:"state"`
SubState string `json:"subState"`
ExecutionType string `json:"executionType"`
Retries int `json:"retries"`
CreatedTime int64 `json:"createdTime"`
CompletedTime int64 `json:"completedTime"`
AppID string `json:"appId"`
AppProgress string `json:"appProgress"`
AppTrackingURL string `json:"appTrackingUrl"`
AppLaunchedTime int64 `json:"appLaunchedTime"`
AppCompletedTime int64 `json:"appCompletedTime"`
AppExitCode int `json:"appExitCode"`
AppExitDiagnostics string `json:"appExitDiagnostics"`
AppExitType interface{} `json:"appExitType"`
VirtualCluster string `json:"virtualCluster"`
} `json:"jobStatus"`
TaskRoles map[string]interface{} `json:"taskRoles"`
Resource struct {
CPU int `json:"cpu"`
Memory string `json:"memory"`
NvidiaComGpu int `json:"nvidia.com/gpu"`
} `json:"resource"`
Config struct {
Image string `json:"image"`
JobID string `json:"jobId"`
GpuType string `json:"gpuType"`
JobName string `json:"jobName"`
JobType string `json:"jobType"`
TaskRoles []struct {
Name string `json:"name"`
ShmMB int `json:"shmMB"`
Command string `json:"command"`
MemoryMB int `json:"memoryMB"`
CPUNumber int `json:"cpuNumber"`
GpuNumber int `json:"gpuNumber"`
IsMainRole bool `json:"isMainRole"`
TaskNumber int `json:"taskNumber"`
NeedIBDevice bool `json:"needIBDevice"`
MinFailedTaskCount int `json:"minFailedTaskCount"`
MinSucceededTaskCount int `json:"minSucceededTaskCount"`
} `json:"taskRoles"`
RetryCount int `json:"retryCount"`
} `json:"config"`
Userinfo struct {
User string `json:"user"`
OrgID string `json:"org_id"`
} `json:"userinfo"`
}

func ConvertToJobResultPayload(input map[string]interface{}) (JobResultPayload, error) {
data, _ := json.Marshal(input)
var jobResultPayload JobResultPayload
err := json.Unmarshal(data, &jobResultPayload)
return jobResultPayload, err
}

func Cloudbrains(opts *CloudbrainsOptions) ([]*Cloudbrain, int64, error) {
sess := x.NewSession()


+ 5
- 1
routers/repo/cloudbrain.go View File

@@ -102,7 +102,11 @@ func CloudBrainShow(ctx *context.Context) {
}

if result != nil {
ctx.Data["result"] = result
jobRes, _ := models.ConvertToJobResultPayload(result.Payload)
ctx.Data["result"] = jobRes
taskRoles := jobRes.TaskRoles
taskRes, _ := models.ConvertToTaskPod(taskRoles["task1"].(map[string]interface{}))
ctx.Data["taskRes"] = taskRes
}

ctx.Data["jobID"] = jobID


+ 2
- 0
templates/repo/cloudbrain/show.tmpl View File

@@ -12,6 +12,8 @@
<div id="id">{{.JobID}}</div>
<hr>
{{end}}
<p>taskRes:</p>
<div>{{.taskRes}}</div>
<p>err:</p>
<div>{{.error}}</div>
<hr>


Loading…
Cancel
Save