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

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