From 9a26bcf5b94fcac3c45220ed67b2f93f53e02199 Mon Sep 17 00:00:00 2001 From: Sydonian <794346190@qq.com> Date: Fri, 22 Sep 2023 16:58:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=B1=BB=E5=9E=8B=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdks/scheduler/models.go | 6 ++++-- sdks/unifyops/models.go | 38 +++++++++++++++++++------------------ utils/serder/serder_test.go | 9 +++++---- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/sdks/scheduler/models.go b/sdks/scheduler/models.go index 19bb417..c4b118a 100644 --- a/sdks/scheduler/models.go +++ b/sdks/scheduler/models.go @@ -21,6 +21,8 @@ type JobID string type JobSetID string +type ImageID string + type JobSetInfo struct { Jobs []JobInfo `json:"jobs"` } @@ -101,8 +103,8 @@ type ResourceJobFileInfo struct { type ImageJobFileInfo struct { JobFileInfoBase - Type string `json:"type" union:"Image"` - ImageID string `json:"imageID"` + Type string `json:"type" union:"Image"` + ImageID ImageID `json:"imageID"` } type JobRuntimeInfo struct { diff --git a/sdks/unifyops/models.go b/sdks/unifyops/models.go index 837ff09..86495ff 100644 --- a/sdks/unifyops/models.go +++ b/sdks/unifyops/models.go @@ -6,13 +6,15 @@ import ( "gitlink.org.cn/cloudream/common/utils/serder" ) +type ResourceType string + 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 @@ -52,12 +54,12 @@ type DetailType[T any] struct { type CPUResourceData struct { ResourceDataBase - Name string `json:"name" union:"CPU"` + Name ResourceType `json:"name" union:"CPU"` Total DetailType[int64] `json:"total"` 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{ Name: name, Total: total, @@ -67,12 +69,12 @@ func NewCPUResourceData(name string, total DetailType[int64], available DetailTy type NPUResourceData struct { ResourceDataBase - Name string `json:"name" union:"NPU"` + Name ResourceType `json:"name" union:"NPU"` Total DetailType[int64] `json:"total"` 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{ Name: name, Total: total, @@ -82,12 +84,12 @@ func NewNPUResourceData(name string, total DetailType[int64], available DetailTy type GPUResourceData struct { ResourceDataBase - Name string `json:"name" union:"GPU"` + Name ResourceType `json:"name" union:"GPU"` Total DetailType[int64] `json:"total"` 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{ Name: name, Total: total, @@ -97,12 +99,12 @@ func NewGPUResourceData(name string, total DetailType[int64], available DetailTy type MLUResourceData struct { ResourceDataBase - Name string `json:"name" union:"MLU"` + Name ResourceType `json:"name" union:"MLU"` Total DetailType[int64] `json:"total"` 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{ Name: name, Total: total, @@ -112,12 +114,12 @@ func NewMLUResourceData(name string, total DetailType[int64], available DetailTy type StorageResourceData struct { ResourceDataBase - Name string `json:"name" union:"STORAGE"` + Name ResourceType `json:"name" union:"STORAGE"` Total DetailType[float64] `json:"total"` 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{ Name: name, Total: total, @@ -127,12 +129,12 @@ func NewStorageResourceData(name string, total DetailType[float64], available De type MemoryResourceData struct { ResourceDataBase - Name string `json:"name" union:"MEMORY"` + Name ResourceType `json:"name" union:"MEMORY"` Total DetailType[float64] `json:"total"` 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{ Name: name, Total: total, diff --git a/utils/serder/serder_test.go b/utils/serder/serder_test.go index dd516ae..f614015 100644 --- a/utils/serder/serder_test.go +++ b/utils/serder/serder_test.go @@ -359,16 +359,17 @@ func Test_MapToObject(t *testing.T) { }) Convey("包含UnionType", t, func() { + type EleType string type UnionType interface{} 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 string `json:"type" union:"2"` - Value2 int `json:"value2"` + Type EleType `json:"type" union:"2"` + Value2 int `json:"value2"` } type St struct {