Browse Source

修复unifyops的问题

pull/30/head
Sydonian 2 years ago
parent
commit
46ccbe9c74
3 changed files with 36 additions and 40 deletions
  1. +26
    -26
      sdks/unifyops/models.go
  2. +3
    -7
      sdks/unifyops/unifyops.go
  3. +7
    -7
      sdks/unifyops/unifyops_test.go

+ 26
- 26
sdks/unifyops/models.go View File

@@ -19,7 +19,7 @@ const (
)

type SlwNode struct {
ID schsdk.SlwNodeID `json:"ID"`
ID schsdk.SlwNodeID `json:"id"`
Name string `json:"name"`
SlwRegionID int64 `json:"slwRegionID"`
StgNodeID int64 `json:"stgNodeID"`
@@ -45,19 +45,19 @@ type ResourceDataBase struct{}

func (d *ResourceDataBase) Noop() {}

type DetailType[T any] struct {
type UnitValue[T any] struct {
Unit string `json:"unit"`
Value T `json:"value"`
}

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

func NewCPUResourceData(total DetailType[int64], available DetailType[int64]) *CPUResourceData {
func NewCPUResourceData(total UnitValue[int64], available UnitValue[int64]) *CPUResourceData {
return &CPUResourceData{
Name: ResourceTypeCPU,
Total: total,
@@ -67,12 +67,12 @@ func NewCPUResourceData(total DetailType[int64], available DetailType[int64]) *C

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

func NewNPUResourceData(total DetailType[int64], available DetailType[int64]) *NPUResourceData {
func NewNPUResourceData(total UnitValue[int64], available UnitValue[int64]) *NPUResourceData {
return &NPUResourceData{
Name: ResourceTypeNPU,
Total: total,
@@ -82,12 +82,12 @@ func NewNPUResourceData(total DetailType[int64], available DetailType[int64]) *N

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

func NewGPUResourceData(total DetailType[int64], available DetailType[int64]) *GPUResourceData {
func NewGPUResourceData(total UnitValue[int64], available UnitValue[int64]) *GPUResourceData {
return &GPUResourceData{
Name: ResourceTypeGPU,
Total: total,
@@ -97,12 +97,12 @@ func NewGPUResourceData(total DetailType[int64], available DetailType[int64]) *G

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

func NewMLUResourceData(total DetailType[int64], available DetailType[int64]) *MLUResourceData {
func NewMLUResourceData(total UnitValue[int64], available UnitValue[int64]) *MLUResourceData {
return &MLUResourceData{
Name: ResourceTypeMLU,
Total: total,
@@ -112,12 +112,12 @@ func NewMLUResourceData(total DetailType[int64], available DetailType[int64]) *M

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

func NewStorageResourceData(total DetailType[float64], available DetailType[float64]) *StorageResourceData {
func NewStorageResourceData(total UnitValue[float64], available UnitValue[float64]) *StorageResourceData {
return &StorageResourceData{
Name: ResourceTypeStorage,
Total: total,
@@ -127,12 +127,12 @@ func NewStorageResourceData(total DetailType[float64], available DetailType[floa

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

func NewMemoryResourceData(total DetailType[float64], available DetailType[float64]) *MemoryResourceData {
func NewMemoryResourceData(total UnitValue[float64], available UnitValue[float64]) *MemoryResourceData {
return &MemoryResourceData{
Name: ResourceTypeMemory,
Total: total,


+ 3
- 7
sdks/unifyops/unifyops.go View File

@@ -12,11 +12,7 @@ import (

const CORRECT_CODE int = 200

type GetAllSlwNodeInfoResp struct {
Nodes []SlwNode `json:"nodes"`
}

func (c *Client) GetAllSlwNodeInfo() (*GetAllSlwNodeInfoResp, error) {
func (c *Client) GetAllSlwNodeInfo() ([]SlwNode, error) {
url, err := url.JoinPath(c.baseURL, "/cmdb/resApi/getSlwNodeInfo")
if err != nil {
return nil, err
@@ -28,13 +24,13 @@ func (c *Client) GetAllSlwNodeInfo() (*GetAllSlwNodeInfoResp, error) {
contType := resp.Header.Get("Content-Type")
if strings.Contains(contType, myhttp.ContentTypeJSON) {

var codeResp response[GetAllSlwNodeInfoResp]
var codeResp response[[]SlwNode]
if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
return nil, fmt.Errorf("parsing response: %w", err)
}

if codeResp.Code == CORRECT_CODE {
return &codeResp.Data, nil
return codeResp.Data, nil
}

return nil, codeResp.ToError()


+ 7
- 7
sdks/unifyops/unifyops_test.go View File

@@ -17,43 +17,43 @@ func Test_UnifyOps(t *testing.T) {
So(err, ShouldBeNil)

cpuData, err := cli.GetCPUData(GetOneResourceDataReq{
SlwNodeID: slwNodeInfos.Nodes[0].ID,
SlwNodeID: slwNodeInfos[0].ID,
})
So(err, ShouldBeNil)
fmt.Printf("cpuData: %v\n", cpuData)

gpuData, err := cli.GetGPUData(GetOneResourceDataReq{
SlwNodeID: slwNodeInfos.Nodes[0].ID,
SlwNodeID: slwNodeInfos[0].ID,
})
So(err, ShouldBeNil)
fmt.Printf("gpuData: %v\n", gpuData)

npuData, err := cli.GetNPUData(GetOneResourceDataReq{
SlwNodeID: slwNodeInfos.Nodes[0].ID,
SlwNodeID: slwNodeInfos[0].ID,
})
So(err, ShouldBeNil)
fmt.Printf("npuData: %v\n", npuData)

mluData, err := cli.GetMLUData(GetOneResourceDataReq{
SlwNodeID: slwNodeInfos.Nodes[0].ID,
SlwNodeID: slwNodeInfos[0].ID,
})
So(err, ShouldBeNil)
fmt.Printf("mluData: %v\n", mluData)

storageData, err := cli.GetStorageData(GetOneResourceDataReq{
SlwNodeID: slwNodeInfos.Nodes[0].ID,
SlwNodeID: slwNodeInfos[0].ID,
})
So(err, ShouldBeNil)
fmt.Printf("storageData: %v\n", storageData)

memoryData, err := cli.GetMemoryData(GetOneResourceDataReq{
SlwNodeID: slwNodeInfos.Nodes[0].ID,
SlwNodeID: slwNodeInfos[0].ID,
})
So(err, ShouldBeNil)
fmt.Printf("memoryData: %v\n", memoryData)

indicatorData, err := cli.GetIndicatorData(GetOneResourceDataReq{
SlwNodeID: slwNodeInfos.Nodes[0].ID,
SlwNodeID: slwNodeInfos[0].ID,
})
So(err, ShouldBeNil)
fmt.Printf("indicatorData: %v\n", indicatorData)


Loading…
Cancel
Save