|
|
|
@@ -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() |
|
|
|
|