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

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