From 53cba541df6d4acd6d7ef0641e519bd4ef6cd4fa Mon Sep 17 00:00:00 2001 From: Sydonian <794346190@qq.com> Date: Wed, 5 Jun 2024 15:44:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdks/scheduler/models.go | 36 ++++++++ sdks/storage/models.go | 9 ++ sdks/storage/storage.go | 21 ++--- sdks/unifyops/unifyops.go | 183 +++++++++++++++++++++++++++++++++++++- 4 files changed, 235 insertions(+), 14 deletions(-) diff --git a/sdks/scheduler/models.go b/sdks/scheduler/models.go index 0b059b1..3bb25aa 100644 --- a/sdks/scheduler/models.go +++ b/sdks/scheduler/models.go @@ -186,3 +186,39 @@ type JobSetServiceInfo struct { CDSNodeID *cdssdk.NodeID `json:"cdsNodeID"` LocalJobID string `json:"localJobID"` } + +type Bootstrap interface { + GetBootstrapType() string +} + +type DirectBootstrap struct { + serder.Metadata `union:"Direct"` + Type string `json:"type"` +} + +type NoEnvBootstrap struct { + serder.Metadata `union:"NoEnv"` + Type string `json:"type"` + ScriptPackageID cdssdk.PackageID `json:"scriptPackageID"` + ScriptFileName string `json:"scriptFileName"` +} + +var BootstrapTypeUnion = types.NewTypeUnion[Bootstrap]( + (*DirectBootstrap)(nil), + (*NoEnvBootstrap)(nil), +) + +var _ = serder.UseTypeUnionInternallyTagged(&BootstrapTypeUnion, "type") + +func (b *DirectBootstrap) GetBootstrapType() string { + return b.Type +} + +func (b *NoEnvBootstrap) GetBootstrapType() string { + return b.Type +} + +const ( + JobDataInEnv = "SCH_DATA_IN" + JobDataOutEnv = "SCH_DATA_OUT" +) diff --git a/sdks/storage/models.go b/sdks/storage/models.go index 2597cae..b1dad0c 100644 --- a/sdks/storage/models.go +++ b/sdks/storage/models.go @@ -147,6 +147,15 @@ type NodeConnectivity struct { TestTime time.Time `db:"TestTime" json:"testTime"` } +type Storage struct { + StorageID StorageID `db:"StorageID" json:"storageID"` + Name string `db:"Name" json:"name"` + NodeID NodeID `db:"NodeID" json:"nodeID"` + LocalBase string `db:"LocalBase" json:"localBase"` // 存储服务挂载在代理节点的目录 + RemoteBase string `db:"RemoteBase" json:"remoteBase"` // 挂载在本地的目录对应存储服务的哪个路径 + State string `db:"State" json:"state"` +} + type NodePackageCachingInfo struct { NodeID NodeID `json:"nodeID"` FileSize int64 `json:"fileSize"` diff --git a/sdks/storage/storage.go b/sdks/storage/storage.go index 439119d..f4f342f 100644 --- a/sdks/storage/storage.go +++ b/sdks/storage/storage.go @@ -18,7 +18,10 @@ type StorageLoadPackageReq struct { StorageID StorageID `json:"storageID" binding:"required"` } type StorageLoadPackageResp struct { - FullPath string `json:"fullPath"` + FullPath string `json:"fullPath"` // TODO 临时保留给中期测试的前端使用,后续会删除 + PackagePath string `json:"packagePath"` + LocalBase string `json:"localBase"` + RemoteBase string `json:"remoteBase"` } func (c *Client) StorageLoadPackage(req StorageLoadPackageReq) (*StorageLoadPackageResp, error) { @@ -91,20 +94,18 @@ func (c *Client) StorageCreatePackage(req StorageCreatePackageReq) (*StorageCrea return nil, fmt.Errorf("unknow response content type: %s", contType) } -const StorageGetInfoPath = "/storage/getInfo" +const StorageGetPath = "/storage/get" -type StorageGetInfoReq struct { +type StorageGet struct { UserID UserID `form:"userID" json:"userID" binding:"required"` StorageID StorageID `form:"storageID" json:"storageID" binding:"required"` } -type StorageGetInfoResp struct { - Name string `json:"name"` - NodeID NodeID `json:"nodeID"` - Directory string `json:"directory"` +type StorageGetResp struct { + Storage } -func (c *Client) StorageGetInfo(req StorageGetInfoReq) (*StorageGetInfoResp, error) { - url, err := url.JoinPath(c.baseURL, StorageGetInfoPath) +func (c *Client) StorageGet(req StorageGet) (*StorageGetResp, error) { + url, err := url.JoinPath(c.baseURL, StorageGetPath) if err != nil { return nil, err } @@ -116,7 +117,7 @@ func (c *Client) StorageGetInfo(req StorageGetInfoReq) (*StorageGetInfoResp, err return nil, err } - codeResp, err := ParseJSONResponse[response[StorageGetInfoResp]](resp) + codeResp, err := ParseJSONResponse[response[StorageGetResp]](resp) if err != nil { return nil, err } diff --git a/sdks/unifyops/unifyops.go b/sdks/unifyops/unifyops.go index 64bb7ad..a0ba982 100644 --- a/sdks/unifyops/unifyops.go +++ b/sdks/unifyops/unifyops.go @@ -260,11 +260,18 @@ func (c *Client) GetIndicatorData(node GetOneResourceDataReq) (*[]ResourceData, //} // //return nil, fmt.Errorf("unknow response content type: %s", contType) + if node.SlwNodeID == 1 { + return mockData1() + } + + if node.SlwNodeID == 2 { + return mockData2() + } - return mockData() + return mockData3() } -func mockData() (*[]ResourceData, error) { +func mockData1() (*[]ResourceData, error) { var ret []ResourceData cpuResourceData := CPUResourceData{ @@ -283,11 +290,11 @@ func mockData() (*[]ResourceData, error) { npuResourceData := NPUResourceData{ Name: ResourceTypeNPU, Total: UnitValue[int64]{ - Value: 100, + Value: 0, Unit: "", }, Available: UnitValue[int64]{ - Value: 100, + Value: 0, Unit: "", }, } @@ -295,6 +302,19 @@ func mockData() (*[]ResourceData, error) { gpuResourceData := GPUResourceData{ Name: ResourceTypeGPU, + Total: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + Available: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + } + ret = append(ret, &gpuResourceData) + + mluResourceData := MLUResourceData{ + Name: ResourceTypeMLU, Total: UnitValue[int64]{ Value: 100, Unit: "", @@ -304,10 +324,152 @@ func mockData() (*[]ResourceData, error) { Unit: "", }, } + ret = append(ret, &mluResourceData) + + storageResourceData := StorageResourceData{ + Name: ResourceTypeStorage, + Total: UnitValue[float64]{ + Value: 100, + Unit: "GB", + }, + Available: UnitValue[float64]{ + Value: 100, + Unit: "GB", + }, + } + ret = append(ret, &storageResourceData) + + memoryResourceData := MemoryResourceData{ + Name: ResourceTypeMemory, + Total: UnitValue[float64]{ + Value: 100, + Unit: "GB", + }, + Available: UnitValue[float64]{ + Value: 100, + Unit: "GB", + }, + } + ret = append(ret, &memoryResourceData) + + return &ret, nil +} + +func mockData2() (*[]ResourceData, error) { + var ret []ResourceData + + cpuResourceData := CPUResourceData{ + Name: ResourceTypeCPU, + Total: UnitValue[int64]{ + Value: 100, + Unit: "", + }, + Available: UnitValue[int64]{ + Value: 100, + Unit: "", + }, + } + ret = append(ret, &cpuResourceData) + + npuResourceData := NPUResourceData{ + Name: ResourceTypeNPU, + Total: UnitValue[int64]{ + Value: 100, + Unit: "", + }, + Available: UnitValue[int64]{ + Value: 100, + Unit: "", + }, + } + ret = append(ret, &npuResourceData) + + gpuResourceData := GPUResourceData{ + Name: ResourceTypeGPU, + Total: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + Available: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + } ret = append(ret, &gpuResourceData) mluResourceData := MLUResourceData{ Name: ResourceTypeMLU, + Total: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + Available: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + } + ret = append(ret, &mluResourceData) + + storageResourceData := StorageResourceData{ + Name: ResourceTypeStorage, + Total: UnitValue[float64]{ + Value: 100, + Unit: "GB", + }, + Available: UnitValue[float64]{ + Value: 100, + Unit: "GB", + }, + } + ret = append(ret, &storageResourceData) + + memoryResourceData := MemoryResourceData{ + Name: ResourceTypeMemory, + Total: UnitValue[float64]{ + Value: 100, + Unit: "GB", + }, + Available: UnitValue[float64]{ + Value: 100, + Unit: "GB", + }, + } + ret = append(ret, &memoryResourceData) + + return &ret, nil +} + +func mockData3() (*[]ResourceData, error) { + var ret []ResourceData + + cpuResourceData := CPUResourceData{ + Name: ResourceTypeCPU, + Total: UnitValue[int64]{ + Value: 100, + Unit: "", + }, + Available: UnitValue[int64]{ + Value: 100, + Unit: "", + }, + } + ret = append(ret, &cpuResourceData) + + npuResourceData := NPUResourceData{ + Name: ResourceTypeNPU, + Total: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + Available: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + } + ret = append(ret, &npuResourceData) + + gpuResourceData := GPUResourceData{ + Name: ResourceTypeGPU, Total: UnitValue[int64]{ Value: 100, Unit: "", @@ -317,6 +479,19 @@ func mockData() (*[]ResourceData, error) { Unit: "", }, } + ret = append(ret, &gpuResourceData) + + mluResourceData := MLUResourceData{ + Name: ResourceTypeMLU, + Total: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + Available: UnitValue[int64]{ + Value: 0, + Unit: "", + }, + } ret = append(ret, &mluResourceData) storageResourceData := StorageResourceData{