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 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. package sch
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/types"
  4. schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler"
  5. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  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. CODE = "code"
  17. DATASET = "dataset"
  18. IMAGE = "image"
  19. MODEL = "model"
  20. OrderByName = "name"
  21. OrderBySize = "size"
  22. OrderByTime = "time"
  23. StorageTypeURL = "url"
  24. StorageTypeJCS = "jcs"
  25. RejectedStatus = "rejected"
  26. PendingStatus = "pending"
  27. ApprovedStatus = "approved"
  28. RevokedStatus = "revoked"
  29. CancelStatus = "cancel"
  30. ExpiredStatus = "expired"
  31. ApplyAccess = "apply"
  32. PrivateAccess = "private"
  33. PublicAccess = "public"
  34. PreferencePriority = "preference"
  35. SpecifyClusterPriority = "specify"
  36. )
  37. type TaskID int64
  38. type ClusterDetail struct {
  39. // 集群ID
  40. ClusterId schsdk.ClusterID `json:"clusterID"`
  41. // 集群功能类型:云算,智算,超算
  42. ClusterType string `json:"clusterType"`
  43. // 集群地区:华东地区、华南地区、华北地区、华中地区、西南地区、西北地区、东北地区
  44. Region string `json:"region"`
  45. // 资源类型
  46. Resources2 []ResourceData `json:"resources1,omitempty"`
  47. //Resources2 []ResourceData `json:"resources"`
  48. Resources []ClusterResource `json:"resources"`
  49. }
  50. type ClusterResource struct {
  51. Resource TmpResourceData `json:"resource"`
  52. BaseResources []TmpResourceData `json:"baseResources"`
  53. }
  54. type TmpResourceData struct {
  55. Type ResourceType `json:"type"`
  56. Name string `json:"name"`
  57. Total UnitValue[float64] `json:"total"`
  58. Available UnitValue[float64] `json:"available"`
  59. }
  60. type ResourceData interface {
  61. Noop()
  62. }
  63. var ResourceDataTypeUnion = types.NewTypeUnion[ResourceData](
  64. (*CPUResourceData)(nil),
  65. (*NPUResourceData)(nil),
  66. (*GPUResourceData)(nil),
  67. (*MLUResourceData)(nil),
  68. (*DCUResourceData)(nil),
  69. (*GCUResourceData)(nil),
  70. (*GPGPUResourceData)(nil),
  71. (*StorageResourceData)(nil),
  72. (*MemoryResourceData)(nil),
  73. (*BalanceResourceData)(nil),
  74. (*RateResourceData)(nil),
  75. )
  76. var _ = serder.UseTypeUnionInternallyTagged(&ResourceDataTypeUnion, "type")
  77. type ResourceDataBase struct{}
  78. func (d *ResourceDataBase) Noop() {}
  79. type UnitValue[T any] struct {
  80. Unit string `json:"unit"`
  81. Value T `json:"value"`
  82. }
  83. type CPUResourceData struct {
  84. serder.Metadata `union:"CPU"`
  85. ResourceDataBase
  86. Type string `json:"type"`
  87. Name ResourceType `json:"name"`
  88. Total UnitValue[int64] `json:"total"`
  89. Available UnitValue[int64] `json:"available"`
  90. }
  91. type NPUResourceData struct {
  92. serder.Metadata `union:"NPU"`
  93. ResourceDataBase
  94. Type string `json:"type"`
  95. Name ResourceType `json:"name"`
  96. Total UnitValue[int64] `json:"total"`
  97. Available UnitValue[int64] `json:"available"`
  98. }
  99. type GPUResourceData struct {
  100. serder.Metadata `union:"GPU"`
  101. ResourceDataBase
  102. Type string `json:"type"`
  103. Name ResourceType `json:"name"`
  104. Total UnitValue[int64] `json:"total"`
  105. Available UnitValue[int64] `json:"available"`
  106. }
  107. type MLUResourceData struct {
  108. serder.Metadata `union:"MLU"`
  109. ResourceDataBase
  110. Type string `json:"type"`
  111. Name ResourceType `json:"name"`
  112. Total UnitValue[int64] `json:"total"`
  113. Available UnitValue[int64] `json:"available"`
  114. }
  115. type DCUResourceData struct {
  116. serder.Metadata `union:"DCU"`
  117. ResourceDataBase
  118. Type string `json:"type"`
  119. Name ResourceType `json:"name"`
  120. Total UnitValue[int64] `json:"total"`
  121. Available UnitValue[int64] `json:"available"`
  122. }
  123. type GCUResourceData struct {
  124. serder.Metadata `union:"GCU"`
  125. ResourceDataBase
  126. Type string `json:"type"`
  127. Name ResourceType `json:"name"`
  128. Total UnitValue[int64] `json:"total"`
  129. Available UnitValue[int64] `json:"available"`
  130. }
  131. type GPGPUResourceData struct {
  132. serder.Metadata `union:"ILUVATAR-GPGPU"`
  133. ResourceDataBase
  134. Type string `json:"type"`
  135. Name ResourceType `json:"name"`
  136. Total UnitValue[int64] `json:"total"`
  137. Available UnitValue[int64] `json:"available"`
  138. }
  139. type StorageResourceData struct {
  140. serder.Metadata `union:"STORAGE"`
  141. ResourceDataBase
  142. Type string `json:"type"`
  143. Name ResourceType `json:"name"`
  144. Total UnitValue[float64] `json:"total"`
  145. Available UnitValue[float64] `json:"available"`
  146. }
  147. type MemoryResourceData struct {
  148. serder.Metadata `union:"MEMORY"`
  149. ResourceDataBase
  150. Type string `json:"type"`
  151. Name ResourceType `json:"name"`
  152. Total UnitValue[float64] `json:"total"`
  153. Available UnitValue[float64] `json:"available"`
  154. }
  155. type BalanceResourceData struct {
  156. serder.Metadata `union:"BALANCE"`
  157. ResourceDataBase
  158. Type string `json:"type"`
  159. Name ResourceType `json:"name"`
  160. Total UnitValue[float64] `json:"total"`
  161. Available UnitValue[float64] `json:"available"`
  162. }
  163. type RateResourceData struct {
  164. serder.Metadata `union:"RATE"`
  165. ResourceDataBase
  166. Type string `json:"type"`
  167. Name ResourceType `json:"name"`
  168. Total UnitValue[float64] `json:"total"`
  169. Available UnitValue[float64] `json:"available"`
  170. }
  171. type ResourceRange struct {
  172. UserID cdssdk.UserID `json:"userID"`
  173. Type ResourceType `json:"type"`
  174. GPU Range `json:"gpu"`
  175. GPUNumber int `json:"gpuNumber"`
  176. CPU Range `json:"cpu"`
  177. Memory Range `json:"memory"`
  178. Storage Range `json:"storage"`
  179. }
  180. type Range struct {
  181. Min float64 `json:"min"`
  182. Max float64 `json:"max"`
  183. }
  184. type ResourcePriority interface {
  185. Noop()
  186. }
  187. type ResourcePriorityBase struct {
  188. }
  189. var ResourcePriorityTypeUnion = types.NewTypeUnion[ResourcePriority](
  190. (*RegionPriority)(nil),
  191. (*ChipPriority)(nil),
  192. (*BiasPriority)(nil),
  193. )
  194. var _ = serder.UseTypeUnionInternallyTagged(&ResourcePriorityTypeUnion, "type")
  195. func (d *ResourcePriorityBase) Noop() {}
  196. type RegionPriority struct {
  197. serder.Metadata `union:"region"`
  198. ResourcePriorityBase
  199. Type string `json:"type"`
  200. Options []string `json:"options"`
  201. }
  202. type ChipPriority struct {
  203. serder.Metadata `union:"chip"`
  204. ResourcePriorityBase
  205. Type string `json:"type"`
  206. Options []string `json:"options"`
  207. }
  208. type BiasPriority struct {
  209. serder.Metadata `union:"bias"`
  210. ResourcePriorityBase
  211. Type string `json:"type"`
  212. Options []string `json:"options"`
  213. }
  214. type UploadParams struct {
  215. DataType string `json:"dataType"`
  216. UploadInfo UploadInfo `json:"uploadInfo"`
  217. //UploadPriority UploadPriority `json:"uploadPriority"`
  218. }
  219. type UploadInfo interface {
  220. Noop()
  221. }
  222. var UploadInfoTypeUnion = types.NewTypeUnion[UploadInfo](
  223. (*LocalUploadInfo)(nil),
  224. (*RemoteUploadInfo)(nil),
  225. )
  226. var _ = serder.UseTypeUnionInternallyTagged(&UploadInfoTypeUnion, "type")
  227. type LocalUploadInfo struct {
  228. serder.Metadata `union:"local"`
  229. UploadInfoBase
  230. Type string `json:"type"`
  231. LocalPath string `json:"localPath"`
  232. ObjectIDs []cdssdk.ObjectID `json:"objectIDs"`
  233. }
  234. type RemoteUploadInfo struct {
  235. serder.Metadata `union:"url"`
  236. UploadInfoBase
  237. Type string `json:"type"`
  238. Url string `json:"url"`
  239. DataName string `json:"dataName"`
  240. Cluster schsdk.ClusterID `json:"clusterID"`
  241. PackageID cdssdk.PackageID `json:"packageID"`
  242. }
  243. type UploadInfoBase struct{}
  244. func (d *UploadInfoBase) Noop() {}
  245. type UploadPriority interface {
  246. Noop()
  247. }
  248. var UploadPriorityTypeUnion = types.NewTypeUnion[UploadPriority](
  249. (*Preferences)(nil),
  250. (*SpecifyCluster)(nil),
  251. )
  252. var _ = serder.UseTypeUnionInternallyTagged(&UploadPriorityTypeUnion, "type")
  253. type Preferences struct {
  254. serder.Metadata `union:"preference"`
  255. UploadPriorityBase
  256. Type string `json:"type"`
  257. ResourcePriorities []ResourcePriority `json:"priorities"`
  258. }
  259. type SpecifyCluster struct {
  260. serder.Metadata `union:"specify"`
  261. UploadPriorityBase
  262. Type string `json:"type"`
  263. Clusters []schsdk.ClusterID `json:"clusters"`
  264. }
  265. type UploadPriorityBase struct{}
  266. func (d *UploadPriorityBase) Noop() {}
  267. type QueryData struct {
  268. DataType string `json:"dataType" binding:"required"`
  269. UserID cdssdk.UserID `json:"userID" binding:"required"`
  270. Path string `json:"path"`
  271. PackageID cdssdk.PackageID `json:"packageID" binding:"required"`
  272. CurrentPage int `json:"currentPage" binding:"required"`
  273. PageSize int `json:"pageSize" binding:"required"`
  274. OrderBy string `json:"orderBy" binding:"required"`
  275. }
  276. type DataBinding interface {
  277. Noop()
  278. }
  279. var DataBindingTypeUnion = types.NewTypeUnion[DataBinding](
  280. (*DatasetBinding)(nil),
  281. (*ModelBinding)(nil),
  282. (*CodeBinding)(nil),
  283. (*ImageBinding)(nil),
  284. )
  285. var _ = serder.UseTypeUnionInternallyTagged(&DataBindingTypeUnion, "type")
  286. type DataBindingBase struct{}
  287. func (d *DataBindingBase) Noop() {}
  288. type DatasetBinding struct {
  289. serder.Metadata `union:"dataset"`
  290. DataBindingBase
  291. Type string `json:"type"`
  292. Name string `json:"name"`
  293. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  294. Description string `json:"description"`
  295. Category string `json:"category"`
  296. PackageIDs []cdssdk.PackageID `json:"packageIDs"`
  297. }
  298. type ModelBinding struct {
  299. serder.Metadata `union:"model"`
  300. DataBindingBase
  301. Type string `json:"type"`
  302. Name string `json:"name"`
  303. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  304. Description string `json:"description"`
  305. Category string `json:"category"`
  306. Env string `json:"env"`
  307. Version string `json:"version"`
  308. PackageIDs []cdssdk.PackageID `json:"packageIDs"`
  309. }
  310. type CodeBinding struct {
  311. serder.Metadata `union:"code"`
  312. DataBindingBase
  313. Type string `json:"type"`
  314. Name string `json:"name"`
  315. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  316. Description string `json:"description"`
  317. ImageID string `json:"imageID"`
  318. ObjectID cdssdk.ObjectID `json:"objectID"`
  319. PackageID cdssdk.PackageID `json:"packageID"`
  320. }
  321. type ImageBinding struct {
  322. serder.Metadata `union:"image"`
  323. DataBindingBase
  324. Type string `json:"type"`
  325. Name string `json:"name"`
  326. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  327. Description string `json:"description"`
  328. Architecture string `json:"architecture"`
  329. ResourceType string `json:"resourceType"`
  330. Tags []string `json:"tags"`
  331. PackageIDs []cdssdk.PackageID `json:"packageIDs"`
  332. }
  333. type ClusterImage struct {
  334. ID int64 `json:"id"`
  335. Name string `json:"name"`
  336. ClusterID schsdk.ClusterID `json:"clusterID"`
  337. ClusterImageID string `json:"clusterImageID"`
  338. CardType string `json:"cardType"`
  339. }
  340. type QueryBindingDataParam interface {
  341. Noop()
  342. }
  343. var QueryBindingDataParamTypeUnion = types.NewTypeUnion[QueryBindingDataParam](
  344. (*PrivateLevel)(nil),
  345. (*ApplyLevel)(nil),
  346. (*PublicLevel)(nil),
  347. )
  348. var _ = serder.UseTypeUnionInternallyTagged(&QueryBindingDataParamTypeUnion, "type")
  349. type QueryBindingDataParamBase struct{}
  350. func (d *QueryBindingDataParamBase) Noop() {}
  351. type PrivateLevel struct {
  352. serder.Metadata `union:"private"`
  353. QueryBindingDataParamBase
  354. Type string `json:"type" binding:"required"`
  355. UserID cdssdk.UserID `json:"userID" binding:"required"`
  356. BindingID int64 `json:"bindingID" binding:"required"`
  357. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  358. }
  359. type ApplyLevel struct {
  360. serder.Metadata `union:"apply"`
  361. QueryBindingDataParamBase
  362. Type string `json:"type" binding:"required"`
  363. UserID cdssdk.UserID `json:"userID" binding:"required"`
  364. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  365. }
  366. type PublicLevel struct {
  367. serder.Metadata `union:"public"`
  368. QueryBindingDataParamBase
  369. UserID cdssdk.UserID `json:"userID" binding:"required"`
  370. Type string `json:"type" binding:"required"`
  371. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  372. }