Browse Source

优化类型定义

pull/24/head
Sydonian 2 years ago
parent
commit
9a26bcf5b9
3 changed files with 29 additions and 24 deletions
  1. +4
    -2
      sdks/scheduler/models.go
  2. +20
    -18
      sdks/unifyops/models.go
  3. +5
    -4
      utils/serder/serder_test.go

+ 4
- 2
sdks/scheduler/models.go View File

@@ -21,6 +21,8 @@ type JobID string


type JobSetID string type JobSetID string


type ImageID string

type JobSetInfo struct { type JobSetInfo struct {
Jobs []JobInfo `json:"jobs"` Jobs []JobInfo `json:"jobs"`
} }
@@ -101,8 +103,8 @@ type ResourceJobFileInfo struct {


type ImageJobFileInfo struct { type ImageJobFileInfo struct {
JobFileInfoBase JobFileInfoBase
Type string `json:"type" union:"Image"`
ImageID string `json:"imageID"`
Type string `json:"type" union:"Image"`
ImageID ImageID `json:"imageID"`
} }


type JobRuntimeInfo struct { type JobRuntimeInfo struct {


+ 20
- 18
sdks/unifyops/models.go View File

@@ -6,13 +6,15 @@ import (
"gitlink.org.cn/cloudream/common/utils/serder" "gitlink.org.cn/cloudream/common/utils/serder"
) )


type ResourceType string

const ( const (
ResourceTypeCPU = "CPU"
ResourceTypeNPU = "NPU"
ResourceTypeGPU = "GPU"
ResourceTypeMLU = "MLU"
ResourceTypeStorage = "STORAGE"
ResourceTypeMemory = "MEMORY"
ResourceTypeCPU ResourceType = "CPU"
ResourceTypeNPU ResourceType = "NPU"
ResourceTypeGPU ResourceType = "GPU"
ResourceTypeMLU ResourceType = "MLU"
ResourceTypeStorage ResourceType = "STORAGE"
ResourceTypeMemory ResourceType = "MEMORY"
) )


type SlwNodeID int64 type SlwNodeID int64
@@ -52,12 +54,12 @@ type DetailType[T any] struct {


type CPUResourceData struct { type CPUResourceData struct {
ResourceDataBase ResourceDataBase
Name string `json:"name" union:"CPU"`
Name ResourceType `json:"name" union:"CPU"`
Total DetailType[int64] `json:"total"` Total DetailType[int64] `json:"total"`
Available DetailType[int64] `json:"available"` Available DetailType[int64] `json:"available"`
} }


func NewCPUResourceData(name string, total DetailType[int64], available DetailType[int64]) *CPUResourceData {
func NewCPUResourceData(name ResourceType, total DetailType[int64], available DetailType[int64]) *CPUResourceData {
return &CPUResourceData{ return &CPUResourceData{
Name: name, Name: name,
Total: total, Total: total,
@@ -67,12 +69,12 @@ func NewCPUResourceData(name string, total DetailType[int64], available DetailTy


type NPUResourceData struct { type NPUResourceData struct {
ResourceDataBase ResourceDataBase
Name string `json:"name" union:"NPU"`
Name ResourceType `json:"name" union:"NPU"`
Total DetailType[int64] `json:"total"` Total DetailType[int64] `json:"total"`
Available DetailType[int64] `json:"available"` Available DetailType[int64] `json:"available"`
} }


func NewNPUResourceData(name string, total DetailType[int64], available DetailType[int64]) *NPUResourceData {
func NewNPUResourceData(name ResourceType, total DetailType[int64], available DetailType[int64]) *NPUResourceData {
return &NPUResourceData{ return &NPUResourceData{
Name: name, Name: name,
Total: total, Total: total,
@@ -82,12 +84,12 @@ func NewNPUResourceData(name string, total DetailType[int64], available DetailTy


type GPUResourceData struct { type GPUResourceData struct {
ResourceDataBase ResourceDataBase
Name string `json:"name" union:"GPU"`
Name ResourceType `json:"name" union:"GPU"`
Total DetailType[int64] `json:"total"` Total DetailType[int64] `json:"total"`
Available DetailType[int64] `json:"available"` Available DetailType[int64] `json:"available"`
} }


func NewGPUResourceData(name string, total DetailType[int64], available DetailType[int64]) *GPUResourceData {
func NewGPUResourceData(name ResourceType, total DetailType[int64], available DetailType[int64]) *GPUResourceData {
return &GPUResourceData{ return &GPUResourceData{
Name: name, Name: name,
Total: total, Total: total,
@@ -97,12 +99,12 @@ func NewGPUResourceData(name string, total DetailType[int64], available DetailTy


type MLUResourceData struct { type MLUResourceData struct {
ResourceDataBase ResourceDataBase
Name string `json:"name" union:"MLU"`
Name ResourceType `json:"name" union:"MLU"`
Total DetailType[int64] `json:"total"` Total DetailType[int64] `json:"total"`
Available DetailType[int64] `json:"available"` Available DetailType[int64] `json:"available"`
} }


func NewMLUResourceData(name string, total DetailType[int64], available DetailType[int64]) *MLUResourceData {
func NewMLUResourceData(name ResourceType, total DetailType[int64], available DetailType[int64]) *MLUResourceData {
return &MLUResourceData{ return &MLUResourceData{
Name: name, Name: name,
Total: total, Total: total,
@@ -112,12 +114,12 @@ func NewMLUResourceData(name string, total DetailType[int64], available DetailTy


type StorageResourceData struct { type StorageResourceData struct {
ResourceDataBase ResourceDataBase
Name string `json:"name" union:"STORAGE"`
Name ResourceType `json:"name" union:"STORAGE"`
Total DetailType[float64] `json:"total"` Total DetailType[float64] `json:"total"`
Available DetailType[float64] `json:"available"` Available DetailType[float64] `json:"available"`
} }


func NewStorageResourceData(name string, total DetailType[float64], available DetailType[float64]) *StorageResourceData {
func NewStorageResourceData(name ResourceType, total DetailType[float64], available DetailType[float64]) *StorageResourceData {
return &StorageResourceData{ return &StorageResourceData{
Name: name, Name: name,
Total: total, Total: total,
@@ -127,12 +129,12 @@ func NewStorageResourceData(name string, total DetailType[float64], available De


type MemoryResourceData struct { type MemoryResourceData struct {
ResourceDataBase ResourceDataBase
Name string `json:"name" union:"MEMORY"`
Name ResourceType `json:"name" union:"MEMORY"`
Total DetailType[float64] `json:"total"` Total DetailType[float64] `json:"total"`
Available DetailType[float64] `json:"available"` Available DetailType[float64] `json:"available"`
} }


func NewMemoryResourceData(name string, total DetailType[float64], available DetailType[float64]) *MemoryResourceData {
func NewMemoryResourceData(name ResourceType, total DetailType[float64], available DetailType[float64]) *MemoryResourceData {
return &MemoryResourceData{ return &MemoryResourceData{
Name: name, Name: name,
Total: total, Total: total,


+ 5
- 4
utils/serder/serder_test.go View File

@@ -359,16 +359,17 @@ func Test_MapToObject(t *testing.T) {
}) })


Convey("包含UnionType", t, func() { Convey("包含UnionType", t, func() {
type EleType string
type UnionType interface{} type UnionType interface{}


type EleType1 struct { type EleType1 struct {
Type string `json:"type" union:"1"`
Value1 string `json:"value1"`
Type EleType `json:"type" union:"1"`
Value1 string `json:"value1"`
} }


type EleType2 struct { type EleType2 struct {
Type string `json:"type" union:"2"`
Value2 int `json:"value2"`
Type EleType `json:"type" union:"2"`
Value2 int `json:"value2"`
} }


type St struct { type St struct {


Loading…
Cancel
Save