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