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

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