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

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