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