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