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

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