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

8 months ago
8 months ago
8 months ago
8 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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 QueryTaskResultReq struct {
  201. TaskID string `json:"taskID" binding:"required"`
  202. UserID cdssdk.UserID `json:"userID" binding:"required"`
  203. PackageID cdssdk.PackageID `json:"packageID" binding:"required"`
  204. }
  205. type PCMJobData struct {
  206. ID string `json:"id"`
  207. CreatedAt time.Time `json:"created_at"`
  208. Param string `json:"param"`
  209. }
  210. type JobInfo struct {
  211. Name string `json:"name"`
  212. Description string `json:"description,optional"`
  213. JobResources JobResources `json:"jobResources"`
  214. DataDistributeData DataDistributeData `json:"dataDistributes"`
  215. ResultFile ResultFile `json:"resultFile"`
  216. }
  217. type ResultFile struct {
  218. CommonPrefixes []interface{} `json:"commonPrefixes"`
  219. Objects []Object `json:"objects"`
  220. }
  221. // Object 表示对象结构体
  222. type Object struct {
  223. ObjectID int `json:"objectID"`
  224. PackageID int `json:"packageID"`
  225. Path string `json:"path"`
  226. Size string `json:"size"`
  227. FileHash string `json:"fileHash"`
  228. Redundancy Redundancy `json:"redundancy"`
  229. CreateTime time.Time `json:"createTime"`
  230. UpdateTime time.Time `json:"updateTime"`
  231. }
  232. // Redundancy 表示冗余信息结构体
  233. type Redundancy struct {
  234. Type string `json:"type"`
  235. RepCount int `json:"repCount"`
  236. }
  237. type DataDistributeData struct {
  238. Dataset []DataItem `json:"dataset"`
  239. Code []DataItem `json:"code"`
  240. Image []DataItem `json:"image"`
  241. Model []DataItem `json:"model"`
  242. }
  243. // DataItem 定义 dataDistributes 中的数据项结构体
  244. type DataItem struct {
  245. DataName string `json:"dataName"`
  246. PackageID int `json:"packageID"`
  247. PackageName string `json:"packageName"`
  248. ResourceFile string `json:"resourceFile"`
  249. Clusters []DataDetail `json:"clusters"`
  250. }
  251. type JobResources struct {
  252. ScheduleStrategy string `json:"scheduleStrategy"`
  253. Clusters []*JobClusterInfo `json:"clusters"`
  254. }
  255. type JobClusterInfo struct {
  256. ClusterID string `json:"clusterID"`
  257. Resources []map[string]interface{} `json:"resources,optional"`
  258. Runtime JobRuntimeInfo `json:"runtime,optional"`
  259. }
  260. type JobRuntimeInfo struct {
  261. Command string `json:"command,optional"`
  262. Envs map[string]interface{} `json:"envs,optional"`
  263. Params map[string]interface{} `json:"params,optional"`
  264. }
  265. // Engine 定义 engine 结构体
  266. type Engine struct {
  267. EngineName string `json:"EngineName"`
  268. EngineVersion string `json:"EngineVersion"`
  269. ImageUrl string `json:"ImageUrl"`
  270. InstallSysPackages bool `json:"InstallSysPackages"`
  271. }
  272. // bindingCluster 定义根结构体
  273. type BindingParam struct {
  274. Name string `json:"name"`
  275. Description string `json:"description"`
  276. Engine Engine `json:"engine"`
  277. CodeDir string `json:"codeDir"`
  278. BootFile string `json:"bootFile"`
  279. Branch string `json:"branch"`
  280. Platform string `json:"platform"`
  281. UserID int `json:"userID"`
  282. PackageId int `json:"packageId"`
  283. BucketID int `json:"bucketID"`
  284. }
  285. // bindingCluster 定义根结构体
  286. type BindingCluster struct {
  287. BindingId int `json:"binding_id"`
  288. ClusterId string `json:"cluster_id"`
  289. Status string `json:"status"`
  290. Param string `json:"param"`
  291. }
  292. /*type TaskResult struct {
  293. Name string `json:"name"`
  294. Description string `json:"description"`
  295. DataDistribute DataDistribute `json:"dataDistributes"`
  296. }
  297. type ClusterResources struct {
  298. ClusterId string `json:"clusterId"`
  299. }*/
  300. type Range struct {
  301. Min float64 `json:"min"`
  302. Max float64 `json:"max"`
  303. }
  304. type ResourcePriority interface {
  305. Noop()
  306. }
  307. type ResourcePriorityBase struct {
  308. }
  309. var ResourcePriorityTypeUnion = types.NewTypeUnion[ResourcePriority](
  310. (*RegionPriority)(nil),
  311. (*ChipPriority)(nil),
  312. (*BiasPriority)(nil),
  313. )
  314. var _ = serder.UseTypeUnionInternallyTagged(&ResourcePriorityTypeUnion, "type")
  315. func (d *ResourcePriorityBase) Noop() {}
  316. type RegionPriority struct {
  317. serder.Metadata `union:"region"`
  318. ResourcePriorityBase
  319. Type string `json:"type"`
  320. Options []string `json:"options"`
  321. }
  322. type ChipPriority struct {
  323. serder.Metadata `union:"chip"`
  324. ResourcePriorityBase
  325. Type string `json:"type"`
  326. Options []string `json:"options"`
  327. }
  328. type BiasPriority struct {
  329. serder.Metadata `union:"bias"`
  330. ResourcePriorityBase
  331. Type string `json:"type"`
  332. Options []string `json:"options"`
  333. }
  334. type TaskMessage struct {
  335. Status string `json:"status"`
  336. Message string `json:"message"`
  337. }
  338. type ReportMessage struct {
  339. TaskName string `json:"taskName"`
  340. TaskID string `json:"taskID"`
  341. Status bool `json:"status"`
  342. Message string `json:"message"`
  343. ClusterID schsdk.ClusterID `json:"clusterID"`
  344. Output string `json:"output"`
  345. }
  346. type UploadParams struct {
  347. DataType string `json:"dataType"`
  348. UploadInfo UploadInfo `json:"uploadInfo"`
  349. }
  350. type UploadInfo interface {
  351. Noop()
  352. }
  353. var UploadInfoTypeUnion = types.NewTypeUnion[UploadInfo](
  354. (*LocalUploadInfo)(nil),
  355. (*RemoteUploadInfo)(nil),
  356. )
  357. var _ = serder.UseTypeUnionInternallyTagged(&UploadInfoTypeUnion, "type")
  358. type LocalUploadInfo struct {
  359. serder.Metadata `union:"local"`
  360. UploadInfoBase
  361. Type string `json:"type"`
  362. LocalPath string `json:"localPath"`
  363. ObjectIDs []cdssdk.ObjectID `json:"objectIDs"`
  364. }
  365. type RemoteUploadInfo struct {
  366. serder.Metadata `union:"url"`
  367. UploadInfoBase
  368. Type string `json:"type"`
  369. Url string `json:"url"`
  370. Branch string `json:"branch"`
  371. DataName string `json:"dataName"`
  372. Cluster schsdk.ClusterID `json:"clusterID"`
  373. }
  374. type UploadInfoBase struct{}
  375. func (d *UploadInfoBase) Noop() {}
  376. type UploadPriority interface {
  377. Noop()
  378. }
  379. var UploadPriorityTypeUnion = types.NewTypeUnion[UploadPriority](
  380. (*Preferences)(nil),
  381. (*SpecifyCluster)(nil),
  382. )
  383. var _ = serder.UseTypeUnionInternallyTagged(&UploadPriorityTypeUnion, "type")
  384. type Preferences struct {
  385. serder.Metadata `union:"preference"`
  386. UploadPriorityBase
  387. Type string `json:"type"`
  388. ResourcePriorities []ResourcePriority `json:"priorities"`
  389. }
  390. type SpecifyCluster struct {
  391. serder.Metadata `union:"specify"`
  392. UploadPriorityBase
  393. Type string `json:"type"`
  394. Clusters []schsdk.ClusterID `json:"clusters"`
  395. }
  396. type UploadPriorityBase struct{}
  397. func (d *UploadPriorityBase) Noop() {}
  398. type QueryData struct {
  399. DataType string `json:"dataType" binding:"required"`
  400. UserID cdssdk.UserID `json:"userID" binding:"required"`
  401. Path string `json:"path"`
  402. PackageID cdssdk.PackageID `json:"packageID" binding:"required"`
  403. CurrentPage int `json:"currentPage" binding:"required"`
  404. PageSize int `json:"pageSize" binding:"required"`
  405. OrderBy string `json:"orderBy" binding:"required"`
  406. }
  407. type DataBinding interface {
  408. Noop()
  409. }
  410. var DataBindingTypeUnion = types.NewTypeUnion[DataBinding](
  411. (*DatasetBinding)(nil),
  412. (*ModelBinding)(nil),
  413. (*CodeBinding)(nil),
  414. (*ImageBinding)(nil),
  415. )
  416. var _ = serder.UseTypeUnionInternallyTagged(&DataBindingTypeUnion, "type")
  417. type DataBindingBase struct{}
  418. func (d *DataBindingBase) Noop() {}
  419. type DatasetBinding struct {
  420. serder.Metadata `union:"dataset"`
  421. DataBindingBase
  422. Type string `json:"type"`
  423. Name string `json:"name"`
  424. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  425. Description string `json:"description"`
  426. Category string `json:"category"`
  427. PackageID cdssdk.PackageID `json:"packageID"`
  428. RepositoryName string `json:"repositoryName"`
  429. ConsumptionPoints float64 `json:"points"`
  430. }
  431. type ModelBinding struct {
  432. serder.Metadata `union:"model"`
  433. DataBindingBase
  434. Type string `json:"type"`
  435. Name string `json:"name"`
  436. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  437. Description string `json:"description"`
  438. Category string `json:"category"`
  439. ModelType string `json:"modelType"`
  440. Env string `json:"env"`
  441. Version string `json:"version"`
  442. PackageID cdssdk.PackageID `json:"packageID"`
  443. RepositoryName string `json:"repositoryName"`
  444. }
  445. type CodeBinding struct {
  446. serder.Metadata `union:"code"`
  447. DataBindingBase
  448. Type string `json:"type"`
  449. Name string `json:"name"`
  450. ClusterID schsdk.ClusterID `json:"clusterID"`
  451. Description string `json:"description"`
  452. ImageID schsdk.ImageID `json:"imageID"`
  453. BootstrapObjectID cdssdk.ObjectID `json:"bootstrapObjectID"`
  454. PackageID cdssdk.PackageID `json:"packageID"`
  455. Output string `json:"output"`
  456. // 当集群为openi的时候,需要传入分支
  457. Branch string `json:"branch"`
  458. }
  459. //type ImageBinding struct {
  460. // serder.Metadata `union:"image"`
  461. // DataBindingBase
  462. // Type string `json:"type"`
  463. // Name string `json:"name"`
  464. // ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  465. // Description string `json:"description"`
  466. // Architecture string `json:"architecture"`
  467. // ResourceType string `json:"resourceType"`
  468. // Tags []string `json:"tags"`
  469. // PackageID cdssdk.PackageID `json:"packageID"`
  470. //}
  471. type ImageBinding struct {
  472. serder.Metadata `union:"image"`
  473. DataBindingBase
  474. Type string `json:"type"`
  475. ID int64 `json:"id"`
  476. Name string `json:"name"`
  477. IDType string `json:"idType"`
  478. ImageID string `json:"imageID"`
  479. ClusterID schsdk.ClusterID `json:"clusterID"`
  480. }
  481. type Image struct {
  482. ImageID schsdk.ImageID `json:"imageID" gorm:"column:ImageID;primaryKey"`
  483. Name string `json:"name" gorm:"column:Name"`
  484. CreateTime time.Time `json:"createTime" gorm:"column:CreateTime"`
  485. ClusterImage []ClusterImage `gorm:"foreignKey:image_id;references:ImageID" json:"clusterImages"`
  486. }
  487. type ClusterImage struct {
  488. ImageID schsdk.ImageID `gorm:"column:image_id" json:"imageID"`
  489. ClusterID schsdk.ClusterID `gorm:"column:cluster_id" json:"clusterID"`
  490. OriginImageType string `gorm:"column:origin_image_type" json:"originImageType"`
  491. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  492. OriginImageName string `gorm:"column:origin_image_name" json:"originImageName"`
  493. ClusterImageCard []ClusterImageCard `gorm:"foreignKey:origin_image_id;references:origin_image_id" json:"cards"`
  494. }
  495. func (ClusterImage) TableName() string {
  496. return "clusterImage"
  497. }
  498. type ClusterImageCard struct {
  499. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  500. Card string `gorm:"column:card" json:"card"`
  501. }
  502. func (ClusterImageCard) TableName() string {
  503. return "clusterImageCard"
  504. }
  505. type QueryBindingFilters struct {
  506. Status string `json:"status"`
  507. Name string `json:"name"`
  508. }
  509. type QueryBindingDataParam interface {
  510. Noop()
  511. }
  512. var QueryBindingDataParamTypeUnion = types.NewTypeUnion[QueryBindingDataParam](
  513. (*PrivateLevel)(nil),
  514. (*ApplyLevel)(nil),
  515. (*PublicLevel)(nil),
  516. )
  517. var _ = serder.UseTypeUnionInternallyTagged(&QueryBindingDataParamTypeUnion, "type")
  518. type QueryBindingDataParamBase struct{}
  519. func (d *QueryBindingDataParamBase) Noop() {}
  520. type PrivateLevel struct {
  521. serder.Metadata `union:"private"`
  522. QueryBindingDataParamBase
  523. Type string `json:"type" binding:"required"`
  524. UserID cdssdk.UserID `json:"userID" binding:"required"`
  525. BindingID int64 `json:"bindingID" binding:"required"`
  526. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  527. }
  528. type ApplyLevel struct {
  529. serder.Metadata `union:"apply"`
  530. QueryBindingDataParamBase
  531. Type string `json:"type" binding:"required"`
  532. UserID cdssdk.UserID `json:"userID" binding:"required"`
  533. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  534. }
  535. type PublicLevel struct {
  536. serder.Metadata `union:"public"`
  537. QueryBindingDataParamBase
  538. UserID cdssdk.UserID `json:"userID" binding:"required"`
  539. Type string `json:"type" binding:"required"`
  540. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  541. }