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

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. package sch
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/types"
  4. "gitlink.org.cn/cloudream/common/sdks/hpc"
  5. schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler"
  6. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  7. "gitlink.org.cn/cloudream/common/utils/serder"
  8. "time"
  9. )
  10. type ResourceType string
  11. const (
  12. ResourceTypeCPU ResourceType = "CPU"
  13. ResourceTypeNPU ResourceType = "NPU"
  14. ResourceTypeGPU ResourceType = "GPU"
  15. ResourceTypeMLU ResourceType = "MLU"
  16. ResourceTypeStorage ResourceType = "STORAGE"
  17. ResourceTypeMemory ResourceType = "MEMORY"
  18. ResourceTypeDCU ResourceType = "DCU"
  19. ResourceTypeGCU ResourceType = "GCU"
  20. Split = "/"
  21. CODE = "code"
  22. DATASET = "dataset"
  23. IMAGE = "image"
  24. MODEL = "model"
  25. RESULT = "result"
  26. PackageTypeNormal = "normal"
  27. PackageTypeNull = "null"
  28. Null = "null"
  29. OrderByName = "name"
  30. OrderBySize = "size"
  31. OrderByTime = "time"
  32. StorageTypeURL = "url"
  33. StorageTypeJCS = "jcs"
  34. RejectedStatus = "rejected"
  35. PendingStatus = "pending"
  36. ApprovedStatus = "approved"
  37. RevokedStatus = "revoked"
  38. CancelStatus = "cancel"
  39. ExpiredStatus = "expired"
  40. ApplyAccess = "apply"
  41. PrivateAccess = "private"
  42. PublicAccess = "public"
  43. PreferencePriority = "preference"
  44. SpecifyClusterPriority = "specify"
  45. FailedStatus = "failed"
  46. SuccessStatus = "success"
  47. UploadingStatus = "uploading"
  48. RunningStatus = "running"
  49. Query = "query"
  50. Delete = "delete"
  51. ChildrenType = "children"
  52. ParentType = "parent"
  53. PlatformSugon = "sugon"
  54. PlatformOpenI = "OpenI"
  55. PlatformModelArts = "ModelArts"
  56. PlatformAI = "AI" // 智算
  57. PlatformCloud = "CLOUD" // 云算
  58. PlatformCloudInference = "PCM_Inference"
  59. PlatformHPC = "HPCSlurm" //超算
  60. URL = "url"
  61. ID = "id"
  62. Startup = "startup"
  63. Schedule = "schedule"
  64. BlockChainJobCreatePrefix = "job_create_"
  65. StartNode = "StartTask"
  66. EndNode = "EndTask"
  67. )
  68. type TaskID int64
  69. type DataID int64
  70. type ClusterDetail struct {
  71. // 集群ID
  72. ClusterId schsdk.ClusterID `json:"clusterID"`
  73. // 集群功能类型:云算,智算,超算
  74. ClusterType string `json:"clusterType"`
  75. // 集群地区:华东地区、华南地区、华北地区、华中地区、西南地区、西北地区、东北地区
  76. Region string `json:"region"`
  77. // 资源类型
  78. Resources2 []ResourceData `json:"resources1,omitempty"`
  79. //Resources2 []ResourceData `json:"resources"`
  80. Resources []ClusterResource `json:"resources"`
  81. }
  82. type ClusterResource struct {
  83. Resource TmpResourceData `json:"resource"`
  84. BaseResources []TmpResourceData `json:"baseResources"`
  85. }
  86. type TmpResourceData struct {
  87. Type ResourceType `json:"type"`
  88. Name string `json:"name"`
  89. Total UnitValue[float64] `json:"total"`
  90. Available UnitValue[float64] `json:"available"`
  91. }
  92. type ResourceData interface {
  93. Noop()
  94. }
  95. var ResourceDataTypeUnion = types.NewTypeUnion[ResourceData](
  96. (*CPUResourceData)(nil),
  97. (*NPUResourceData)(nil),
  98. (*GPUResourceData)(nil),
  99. (*MLUResourceData)(nil),
  100. (*DCUResourceData)(nil),
  101. (*GCUResourceData)(nil),
  102. (*GPGPUResourceData)(nil),
  103. (*StorageResourceData)(nil),
  104. (*MemoryResourceData)(nil),
  105. (*BalanceResourceData)(nil),
  106. (*RateResourceData)(nil),
  107. )
  108. var _ = serder.UseTypeUnionInternallyTagged(&ResourceDataTypeUnion, "type")
  109. type ResourceDataBase struct{}
  110. func (d *ResourceDataBase) Noop() {}
  111. type UnitValue[T any] struct {
  112. Unit string `json:"unit"`
  113. Value T `json:"value"`
  114. }
  115. type CPUResourceData struct {
  116. serder.Metadata `union:"CPU"`
  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 NPUResourceData struct {
  124. serder.Metadata `union:"NPU"`
  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 GPUResourceData struct {
  132. serder.Metadata `union:"GPU"`
  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 MLUResourceData struct {
  140. serder.Metadata `union:"MLU"`
  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 DCUResourceData struct {
  148. serder.Metadata `union:"DCU"`
  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 GCUResourceData struct {
  156. serder.Metadata `union:"GCU"`
  157. ResourceDataBase
  158. Type string `json:"type"`
  159. Name ResourceType `json:"name"`
  160. Total UnitValue[int64] `json:"total"`
  161. Available UnitValue[int64] `json:"available"`
  162. }
  163. type GPGPUResourceData struct {
  164. serder.Metadata `union:"ILUVATAR-GPGPU"`
  165. ResourceDataBase
  166. Type string `json:"type"`
  167. Name ResourceType `json:"name"`
  168. Total UnitValue[int64] `json:"total"`
  169. Available UnitValue[int64] `json:"available"`
  170. }
  171. type StorageResourceData struct {
  172. serder.Metadata `union:"STORAGE"`
  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 MemoryResourceData struct {
  180. serder.Metadata `union:"MEMORY"`
  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 BalanceResourceData struct {
  188. serder.Metadata `union:"BALANCE"`
  189. ResourceDataBase
  190. Type string `json:"type"`
  191. Name ResourceType `json:"name"`
  192. Total UnitValue[float64] `json:"total"`
  193. Available UnitValue[float64] `json:"available"`
  194. }
  195. type RateResourceData struct {
  196. serder.Metadata `union:"RATE"`
  197. ResourceDataBase
  198. Type string `json:"type"`
  199. Name ResourceType `json:"name"`
  200. Total UnitValue[float64] `json:"total"`
  201. Available UnitValue[float64] `json:"available"`
  202. }
  203. type ResourceRange struct {
  204. UserID cdssdk.UserID `json:"userID"`
  205. Type ResourceType `json:"type"`
  206. GPU Range `json:"gpu"`
  207. GPUNumber int `json:"gpuNumber"`
  208. CPU Range `json:"cpu"`
  209. Memory Range `json:"memory"`
  210. Storage Range `json:"storage"`
  211. Ids []string `json:"ids"`
  212. }
  213. type JobInfo struct {
  214. TaskID string `json:"taskID"`
  215. JobSubmitInfo JobSubmitInfo `json:"jobSubmitInfo"`
  216. ResultFiles []ResultFile `json:"resultFiles"`
  217. }
  218. type ResultFile struct {
  219. ClusterID schsdk.ClusterID `json:"clusterID"`
  220. Objects []cdssdk.Object `json:"objects"`
  221. }
  222. type JobSubmitInfo interface {
  223. Noop()
  224. }
  225. type JobSubmitInfoBase struct {
  226. }
  227. var JobSubmitInfoTypeUnion = types.NewTypeUnion[JobSubmitInfo](
  228. (*PCMJobSubmitInfo)(nil),
  229. (*HPCJobSubmitInfo)(nil),
  230. )
  231. var _ = serder.UseTypeUnionInternallyTagged(&JobSubmitInfoTypeUnion, "type")
  232. func (d *JobSubmitInfoBase) Noop() {}
  233. type PCMJobSubmitInfo struct {
  234. serder.Metadata `union:"pcm"`
  235. JobSubmitInfoBase
  236. Type string `json:"type"`
  237. Info CreateAIJobReq `json:"info"`
  238. }
  239. type HPCJobSubmitInfo struct {
  240. serder.Metadata `union:"hpc"`
  241. JobSubmitInfoBase
  242. Type string `json:"type"`
  243. Info hpc.CreateHPCJobReq `json:"info"`
  244. }
  245. type Range struct {
  246. Min float64 `json:"min"`
  247. Max float64 `json:"max"`
  248. }
  249. type ResourcePriority interface {
  250. Noop()
  251. }
  252. type ResourcePriorityBase struct {
  253. }
  254. var ResourcePriorityTypeUnion = types.NewTypeUnion[ResourcePriority](
  255. (*RegionPriority)(nil),
  256. (*ChipPriority)(nil),
  257. (*BiasPriority)(nil),
  258. )
  259. var _ = serder.UseTypeUnionInternallyTagged(&ResourcePriorityTypeUnion, "type")
  260. func (d *ResourcePriorityBase) Noop() {}
  261. type RegionPriority struct {
  262. serder.Metadata `union:"region"`
  263. ResourcePriorityBase
  264. Type string `json:"type"`
  265. Options []string `json:"options"`
  266. }
  267. type ChipPriority struct {
  268. serder.Metadata `union:"chip"`
  269. ResourcePriorityBase
  270. Type string `json:"type"`
  271. Options []string `json:"options"`
  272. }
  273. type BiasPriority struct {
  274. serder.Metadata `union:"bias"`
  275. ResourcePriorityBase
  276. Type string `json:"type"`
  277. Options []string `json:"options"`
  278. }
  279. type TaskMessage struct {
  280. Status string `json:"status"`
  281. Message string `json:"message"`
  282. }
  283. type ReportMessage struct {
  284. TaskName string `json:"taskName"`
  285. TaskID string `json:"taskID"`
  286. Status bool `json:"status"`
  287. Message string `json:"message"`
  288. ClusterID schsdk.ClusterID `json:"clusterID"`
  289. Output string `json:"output"`
  290. }
  291. type UploadParams struct {
  292. DataType string `json:"dataType"`
  293. UploadInfo UploadInfo `json:"uploadInfo"`
  294. }
  295. type UploadInfo interface {
  296. Noop()
  297. }
  298. var UploadInfoTypeUnion = types.NewTypeUnion[UploadInfo](
  299. (*LocalUploadInfo)(nil),
  300. (*RemoteUploadInfo)(nil),
  301. )
  302. var _ = serder.UseTypeUnionInternallyTagged(&UploadInfoTypeUnion, "type")
  303. type LocalUploadInfo struct {
  304. serder.Metadata `union:"local"`
  305. UploadInfoBase
  306. Type string `json:"type"`
  307. LocalPath string `json:"localPath"`
  308. ObjectIDs []cdssdk.ObjectID `json:"objectIDs"`
  309. }
  310. type RemoteUploadInfo struct {
  311. serder.Metadata `union:"url"`
  312. UploadInfoBase
  313. Type string `json:"type"`
  314. Url string `json:"url"`
  315. Branch string `json:"branch"`
  316. DataName string `json:"dataName"`
  317. Cluster schsdk.ClusterID `json:"clusterID"`
  318. }
  319. type UploadInfoBase struct{}
  320. func (d *UploadInfoBase) Noop() {}
  321. type UploadPriority interface {
  322. Noop()
  323. }
  324. var UploadPriorityTypeUnion = types.NewTypeUnion[UploadPriority](
  325. (*Preferences)(nil),
  326. (*SpecifyCluster)(nil),
  327. )
  328. var _ = serder.UseTypeUnionInternallyTagged(&UploadPriorityTypeUnion, "type")
  329. type Preferences struct {
  330. serder.Metadata `union:"preference"`
  331. UploadPriorityBase
  332. Type string `json:"type"`
  333. ResourcePriorities []ResourcePriority `json:"priorities"`
  334. }
  335. type SpecifyCluster struct {
  336. serder.Metadata `union:"specify"`
  337. UploadPriorityBase
  338. Type string `json:"type"`
  339. Clusters []schsdk.ClusterID `json:"clusters"`
  340. }
  341. type UploadPriorityBase struct{}
  342. func (d *UploadPriorityBase) Noop() {}
  343. type QueryData struct {
  344. DataType string `json:"dataType" binding:"required"`
  345. UserID cdssdk.UserID `json:"userID" binding:"required"`
  346. Path string `json:"path"`
  347. PackageID cdssdk.PackageID `json:"packageID" binding:"required"`
  348. CurrentPage int `json:"currentPage" binding:"required"`
  349. PageSize int `json:"pageSize" binding:"required"`
  350. OrderBy string `json:"orderBy" binding:"required"`
  351. PackageName string `json:"packageName"`
  352. }
  353. type DataBinding interface {
  354. Noop()
  355. }
  356. var DataBindingTypeUnion = types.NewTypeUnion[DataBinding](
  357. (*DatasetBinding)(nil),
  358. (*ModelBinding)(nil),
  359. (*CodeBinding)(nil),
  360. (*ImageBinding)(nil),
  361. )
  362. var _ = serder.UseTypeUnionInternallyTagged(&DataBindingTypeUnion, "type")
  363. type DataBindingBase struct {
  364. RootPath string `json:"rootPath"`
  365. }
  366. func (d *DataBindingBase) Noop() {}
  367. type DatasetBinding struct {
  368. serder.Metadata `union:"dataset"`
  369. DataBindingBase
  370. Type string `json:"type"`
  371. Name string `json:"name"`
  372. OperateType string `json:"operateType"`
  373. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  374. Description string `json:"description"`
  375. Category string `json:"category"`
  376. PackageID cdssdk.PackageID `json:"packageID"`
  377. RepositoryName string `json:"repositoryName"`
  378. ConsumptionPoints int64 `json:"points"`
  379. }
  380. type ModelBinding struct {
  381. serder.Metadata `union:"model"`
  382. DataBindingBase
  383. Type string `json:"type"`
  384. Name string `json:"name"`
  385. OperateType string `json:"operateType"`
  386. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  387. Description string `json:"description"`
  388. Category string `json:"category"`
  389. ModelType string `json:"modelType"`
  390. Env string `json:"env"`
  391. Version string `json:"version"`
  392. PackageID cdssdk.PackageID `json:"packageID"`
  393. RepositoryName string `json:"repositoryName"`
  394. }
  395. type CodeBinding struct {
  396. serder.Metadata `union:"code"`
  397. DataBindingBase
  398. Type string `json:"type"`
  399. Name string `json:"name"`
  400. OperateType string `json:"operateType"`
  401. ClusterID schsdk.ClusterID `json:"clusterID"`
  402. Description string `json:"description"`
  403. ImageID schsdk.ImageID `json:"imageID"`
  404. BootstrapObjectID cdssdk.ObjectID `json:"bootstrapObjectID"`
  405. PackageID cdssdk.PackageID `json:"packageID"`
  406. Output string `json:"output"`
  407. // 当集群为openi的时候,需要传入分支
  408. Branch string `json:"branch"`
  409. }
  410. //type ImageBinding struct {
  411. // serder.Metadata `union:"image"`
  412. // DataBindingBase
  413. // Type string `json:"type"`
  414. // Name string `json:"name"`
  415. // ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  416. // Description string `json:"description"`
  417. // Architecture string `json:"architecture"`
  418. // ResourceType string `json:"resourceType"`
  419. // Tags []string `json:"tags"`
  420. // PackageID cdssdk.PackageID `json:"packageID"`
  421. //}
  422. type ImageBinding struct {
  423. serder.Metadata `union:"image"`
  424. DataBindingBase
  425. Type string `json:"type"`
  426. ID int64 `json:"id"`
  427. OperateType string `json:"operateType"`
  428. Name string `json:"name"`
  429. IDType string `json:"idType"`
  430. ImageID string `json:"imageID"`
  431. ClusterID schsdk.ClusterID `json:"clusterID"`
  432. }
  433. type Image struct {
  434. ImageID schsdk.ImageID `json:"imageID" gorm:"column:ImageID;primaryKey"`
  435. Name string `json:"name" gorm:"column:Name"`
  436. CreateTime time.Time `json:"createTime" gorm:"column:CreateTime"`
  437. ClusterImage []ClusterImage `gorm:"foreignKey:image_id;references:ImageID" json:"clusterImages"`
  438. }
  439. type ClusterImage struct {
  440. ImageID schsdk.ImageID `gorm:"column:image_id" json:"imageID"`
  441. ClusterID schsdk.ClusterID `gorm:"column:cluster_id" json:"clusterID"`
  442. OriginImageType string `gorm:"column:origin_image_type" json:"originImageType"`
  443. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  444. OriginImageName string `gorm:"column:origin_image_name" json:"originImageName"`
  445. ClusterImageCard []ClusterImageCard `gorm:"foreignKey:origin_image_id;references:origin_image_id" json:"cards"`
  446. }
  447. func (ClusterImage) TableName() string {
  448. return "clusterImage"
  449. }
  450. type ClusterImageCard struct {
  451. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  452. Card string `gorm:"column:card" json:"card"`
  453. }
  454. func (ClusterImageCard) TableName() string {
  455. return "clusterImageCard"
  456. }
  457. type QueryBindingFilters struct {
  458. Status string `json:"status"`
  459. Name string `json:"name"`
  460. }
  461. type QueryBindingDataParam interface {
  462. Noop()
  463. }
  464. var QueryBindingDataParamTypeUnion = types.NewTypeUnion[QueryBindingDataParam](
  465. (*PrivateLevel)(nil),
  466. (*ApplyLevel)(nil),
  467. (*PublicLevel)(nil),
  468. )
  469. var _ = serder.UseTypeUnionInternallyTagged(&QueryBindingDataParamTypeUnion, "type")
  470. type QueryBindingDataParamBase struct{}
  471. func (d *QueryBindingDataParamBase) Noop() {}
  472. type PrivateLevel struct {
  473. serder.Metadata `union:"private"`
  474. QueryBindingDataParamBase
  475. Type string `json:"type" binding:"required"`
  476. UserID cdssdk.UserID `json:"userID" binding:"required"`
  477. BindingID int64 `json:"bindingID" binding:"required"`
  478. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  479. }
  480. type ApplyLevel struct {
  481. serder.Metadata `union:"apply"`
  482. QueryBindingDataParamBase
  483. Type string `json:"type" binding:"required"`
  484. UserID cdssdk.UserID `json:"userID" binding:"required"`
  485. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  486. }
  487. type PublicLevel struct {
  488. serder.Metadata `union:"public"`
  489. QueryBindingDataParamBase
  490. UserID cdssdk.UserID `json:"userID" binding:"required"`
  491. Type string `json:"type" binding:"required"`
  492. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  493. }