You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.go 3.8 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package uopsdk
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/mq"
  4. "gitlink.org.cn/cloudream/common/pkgs/types"
  5. schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler"
  6. "gitlink.org.cn/cloudream/common/utils/serder"
  7. )
  8. type ResourceType string
  9. const (
  10. ResourceTypeCPU ResourceType = "CPU"
  11. ResourceTypeNPU ResourceType = "NPU"
  12. ResourceTypeGPU ResourceType = "GPU"
  13. ResourceTypeMLU ResourceType = "MLU"
  14. ResourceTypeStorage ResourceType = "STORAGE"
  15. ResourceTypeMemory ResourceType = "MEMORY"
  16. )
  17. type SlwNode struct {
  18. ID schsdk.SlwNodeID `json:"ID"`
  19. Name string `json:"name"`
  20. SlwRegionID int64 `json:"slwRegionID"`
  21. StgNodeID int64 `json:"stgNodeID"`
  22. StorageID int64 `json:"StorageID"`
  23. }
  24. type ResourceData interface {
  25. Noop()
  26. }
  27. var ResourceDataTypeUnion = types.NewTypeUnion[ResourceData](
  28. (*CPUResourceData)(nil),
  29. (*NPUResourceData)(nil),
  30. (*GPUResourceData)(nil),
  31. (*MLUResourceData)(nil),
  32. (*StorageResourceData)(nil),
  33. (*MemoryResourceData)(nil),
  34. )
  35. var _ = serder.RegisterNewTaggedTypeUnion(ResourceDataTypeUnion, "Name", "name")
  36. var _ = mq.RegisterUnionType(ResourceDataTypeUnion)
  37. type ResourceDataBase struct{}
  38. func (d *ResourceDataBase) Noop() {}
  39. type DetailType[T any] struct {
  40. Unit string `json:"unit"`
  41. Value T `json:"value"`
  42. }
  43. type CPUResourceData struct {
  44. ResourceDataBase
  45. Name ResourceType `json:"name" union:"CPU"`
  46. Total DetailType[int64] `json:"total"`
  47. Available DetailType[int64] `json:"available"`
  48. }
  49. func NewCPUResourceData(total DetailType[int64], available DetailType[int64]) *CPUResourceData {
  50. return &CPUResourceData{
  51. Name: ResourceTypeCPU,
  52. Total: total,
  53. Available: available,
  54. }
  55. }
  56. type NPUResourceData struct {
  57. ResourceDataBase
  58. Name ResourceType `json:"name" union:"NPU"`
  59. Total DetailType[int64] `json:"total"`
  60. Available DetailType[int64] `json:"available"`
  61. }
  62. func NewNPUResourceData(total DetailType[int64], available DetailType[int64]) *NPUResourceData {
  63. return &NPUResourceData{
  64. Name: ResourceTypeNPU,
  65. Total: total,
  66. Available: available,
  67. }
  68. }
  69. type GPUResourceData struct {
  70. ResourceDataBase
  71. Name ResourceType `json:"name" union:"GPU"`
  72. Total DetailType[int64] `json:"total"`
  73. Available DetailType[int64] `json:"available"`
  74. }
  75. func NewGPUResourceData(total DetailType[int64], available DetailType[int64]) *GPUResourceData {
  76. return &GPUResourceData{
  77. Name: ResourceTypeGPU,
  78. Total: total,
  79. Available: available,
  80. }
  81. }
  82. type MLUResourceData struct {
  83. ResourceDataBase
  84. Name ResourceType `json:"name" union:"MLU"`
  85. Total DetailType[int64] `json:"total"`
  86. Available DetailType[int64] `json:"available"`
  87. }
  88. func NewMLUResourceData(total DetailType[int64], available DetailType[int64]) *MLUResourceData {
  89. return &MLUResourceData{
  90. Name: ResourceTypeMLU,
  91. Total: total,
  92. Available: available,
  93. }
  94. }
  95. type StorageResourceData struct {
  96. ResourceDataBase
  97. Name ResourceType `json:"name" union:"STORAGE"`
  98. Total DetailType[float64] `json:"total"`
  99. Available DetailType[float64] `json:"available"`
  100. }
  101. func NewStorageResourceData(total DetailType[float64], available DetailType[float64]) *StorageResourceData {
  102. return &StorageResourceData{
  103. Name: ResourceTypeStorage,
  104. Total: total,
  105. Available: available,
  106. }
  107. }
  108. type MemoryResourceData struct {
  109. ResourceDataBase
  110. Name ResourceType `json:"name" union:"MEMORY"`
  111. Total DetailType[float64] `json:"total"`
  112. Available DetailType[float64] `json:"available"`
  113. }
  114. func NewMemoryResourceData(total DetailType[float64], available DetailType[float64]) *MemoryResourceData {
  115. return &MemoryResourceData{
  116. Name: ResourceTypeMemory,
  117. Total: total,
  118. Available: available,
  119. }
  120. }