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

6 months ago
6 months ago
6 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. SucceededStatus = "succeeded"
  48. UploadingStatus = "uploading"
  49. RunningStatus = "running"
  50. Query = "query"
  51. Delete = "delete"
  52. ChildrenType = "children"
  53. ParentType = "parent"
  54. CreateType = "create"
  55. CloneType = "clone"
  56. InsertType = "insert"
  57. PlatformSugon = "sugon"
  58. PlatformOpenI = "OpenI"
  59. PlatformModelArts = "ModelArts"
  60. PlatformAI = "AI" // 智算
  61. PlatformCloud = "CLOUD" // 云算
  62. PlatformCloudInference = "PCM_Inference"
  63. PlatformHPC = "HPCSlurm" //超算
  64. PlatformHPCArm = "HPCArm"
  65. PlatformHPCX86 = "HPCX86"
  66. PlatformOctopus = "Octopus"
  67. URL = "url"
  68. ID = "id"
  69. Startup = "startup"
  70. OnlyCreate = "onlyCreate"
  71. Schedule = "schedule"
  72. BlockChainJobCreatePrefix = "job_create_"
  73. Complete = "Complete"
  74. NodeTypeBinding = "binding"
  75. NodeTypeUpload = "upload"
  76. NodeTypeDataReturn = "DataReturn"
  77. NodeTypeHPCCreate = "hpc_create"
  78. NodeTypeInference = "inference"
  79. NodeTypeInferenceStop = "inference_stop"
  80. NodeTypeAICreate = "ai_job_create"
  81. NodeTypeAIJobRun = "ai_job_run"
  82. NodeTypeNotify = "notify"
  83. NodeTypeBroadcastWait = "broadcast_wait"
  84. Inference = "Inference"
  85. Train = "Train"
  86. BroadcastWait = "BroadcastWait"
  87. WaitBroadcast = "WaitBroadcast"
  88. Broadcast = "Broadcast"
  89. Wait = "Wait"
  90. FederatedLearning = "federatedLearning"
  91. )
  92. type TaskID int64
  93. type DataID int64
  94. type ClusterDetail struct {
  95. // 集群ID
  96. ClusterId schsdk.ClusterID `json:"clusterID"`
  97. // 集群功能类型:云算,智算,超算
  98. ClusterType string `json:"clusterType"`
  99. // 集群地区:华东地区、华南地区、华北地区、华中地区、西南地区、西北地区、东北地区
  100. Region string `json:"region"`
  101. // 资源类型
  102. Resources2 []ResourceData `json:"resources1,omitempty"`
  103. //Resources2 []ResourceData `json:"resources"`
  104. Resources []ClusterResource `json:"resources"`
  105. }
  106. type ClusterResource struct {
  107. Resource TmpResourceData `json:"resource"`
  108. BaseResources []TmpResourceData `json:"baseResources"`
  109. }
  110. type TmpResourceData struct {
  111. Type ResourceType `json:"type"`
  112. Name string `json:"name"`
  113. Total UnitValue[float64] `json:"total"`
  114. Available UnitValue[float64] `json:"available"`
  115. }
  116. type ResourceDetail struct {
  117. ID DataID `json:"id"`
  118. SourceKey string `json:"sourceKey"`
  119. Type ResourceType `json:"type"`
  120. Name string `json:"name"`
  121. TotalCount int64 `json:"totalCount"`
  122. AvailableCount int64 `json:"availableCount"`
  123. ChangeType int64 `json:"changeType"`
  124. Status int64 `json:"status"`
  125. Region string `json:"region"`
  126. ClusterID schsdk.ClusterID `json:"clusterId"`
  127. CostPerUnit float64 `json:"costPerUnit"`
  128. CostType string `json:"costType"`
  129. Tag string `json:"tag"`
  130. UserID string `json:"userId"`
  131. CreateTime string `json:"createTime"`
  132. UpdateTime string `json:"updateTime"`
  133. BaseResourceSpecs []ResourceSpec `json:"baseResourceSpecs"`
  134. }
  135. type ResourceSpec struct {
  136. ID DataID `json:"id"`
  137. ResourceSpecId DataID `json:"resourceSpecId"`
  138. Type ResourceType `json:"type"`
  139. Name string `json:"name"`
  140. TotalValue float64 `json:"totalValue"`
  141. TotalUnit string `json:"totalUnit"`
  142. AvailableValue float64 `json:"availableValue"`
  143. AvailableUnit string `json:"availableUnit"`
  144. UserID string `json:"userId"`
  145. CreateTime string `json:"createTime"`
  146. UpdateTime string `json:"updateTime"`
  147. }
  148. type ResourceData interface {
  149. Noop()
  150. }
  151. var ResourceDataTypeUnion = types.NewTypeUnion[ResourceData](
  152. (*CPUResourceData)(nil),
  153. (*NPUResourceData)(nil),
  154. (*GPUResourceData)(nil),
  155. (*MLUResourceData)(nil),
  156. (*DCUResourceData)(nil),
  157. (*GCUResourceData)(nil),
  158. (*GPGPUResourceData)(nil),
  159. (*StorageResourceData)(nil),
  160. (*MemoryResourceData)(nil),
  161. (*BalanceResourceData)(nil),
  162. (*RateResourceData)(nil),
  163. )
  164. var _ = serder.UseTypeUnionInternallyTagged(&ResourceDataTypeUnion, "type")
  165. type ResourceDataBase struct{}
  166. func (d *ResourceDataBase) Noop() {}
  167. type UnitValue[T any] struct {
  168. Unit string `json:"unit"`
  169. Value T `json:"value"`
  170. }
  171. type CPUResourceData struct {
  172. serder.Metadata `union:"CPU"`
  173. ResourceDataBase
  174. Type string `json:"type"`
  175. Name ResourceType `json:"name"`
  176. Total UnitValue[int64] `json:"total"`
  177. Available UnitValue[int64] `json:"available"`
  178. }
  179. type NPUResourceData struct {
  180. serder.Metadata `union:"NPU"`
  181. ResourceDataBase
  182. Type string `json:"type"`
  183. Name ResourceType `json:"name"`
  184. Total UnitValue[int64] `json:"total"`
  185. Available UnitValue[int64] `json:"available"`
  186. }
  187. type GPUResourceData struct {
  188. serder.Metadata `union:"GPU"`
  189. ResourceDataBase
  190. Type string `json:"type"`
  191. Name ResourceType `json:"name"`
  192. Total UnitValue[int64] `json:"total"`
  193. Available UnitValue[int64] `json:"available"`
  194. }
  195. type MLUResourceData struct {
  196. serder.Metadata `union:"MLU"`
  197. ResourceDataBase
  198. Type string `json:"type"`
  199. Name ResourceType `json:"name"`
  200. Total UnitValue[int64] `json:"total"`
  201. Available UnitValue[int64] `json:"available"`
  202. }
  203. type DCUResourceData struct {
  204. serder.Metadata `union:"DCU"`
  205. ResourceDataBase
  206. Type string `json:"type"`
  207. Name ResourceType `json:"name"`
  208. Total UnitValue[int64] `json:"total"`
  209. Available UnitValue[int64] `json:"available"`
  210. }
  211. type GCUResourceData struct {
  212. serder.Metadata `union:"GCU"`
  213. ResourceDataBase
  214. Type string `json:"type"`
  215. Name ResourceType `json:"name"`
  216. Total UnitValue[int64] `json:"total"`
  217. Available UnitValue[int64] `json:"available"`
  218. }
  219. type GPGPUResourceData struct {
  220. serder.Metadata `union:"ILUVATAR-GPGPU"`
  221. ResourceDataBase
  222. Type string `json:"type"`
  223. Name ResourceType `json:"name"`
  224. Total UnitValue[int64] `json:"total"`
  225. Available UnitValue[int64] `json:"available"`
  226. }
  227. type StorageResourceData struct {
  228. serder.Metadata `union:"STORAGE"`
  229. ResourceDataBase
  230. Type string `json:"type"`
  231. Name ResourceType `json:"name"`
  232. Total UnitValue[float64] `json:"total"`
  233. Available UnitValue[float64] `json:"available"`
  234. }
  235. type MemoryResourceData struct {
  236. serder.Metadata `union:"MEMORY"`
  237. ResourceDataBase
  238. Type string `json:"type"`
  239. Name ResourceType `json:"name"`
  240. Total UnitValue[float64] `json:"total"`
  241. Available UnitValue[float64] `json:"available"`
  242. }
  243. type BalanceResourceData struct {
  244. serder.Metadata `union:"BALANCE"`
  245. ResourceDataBase
  246. Type string `json:"type"`
  247. Name ResourceType `json:"name"`
  248. Total UnitValue[float64] `json:"total"`
  249. Available UnitValue[float64] `json:"available"`
  250. }
  251. type RateResourceData struct {
  252. serder.Metadata `union:"RATE"`
  253. ResourceDataBase
  254. Type string `json:"type"`
  255. Name ResourceType `json:"name"`
  256. Total UnitValue[float64] `json:"total"`
  257. Available UnitValue[float64] `json:"available"`
  258. }
  259. type ResourceRange struct {
  260. UserID cdssdk.UserID `json:"userID"`
  261. Type ResourceType `json:"type"`
  262. GPU Range `json:"gpu"`
  263. GPUNumber int `json:"gpuNumber"`
  264. CPU Range `json:"cpu"`
  265. Memory Range `json:"memory"`
  266. Storage Range `json:"storage"`
  267. Ids []string `json:"ids"`
  268. }
  269. type JobInfo struct {
  270. TaskID string `json:"taskID"`
  271. JobSubmitInfo JobSubmitInfo `json:"jobSubmitInfo"`
  272. ResultFiles []ResultFile `json:"resultFiles"`
  273. Status string `json:"status"`
  274. ErrorMsg string `json:"errorMsg"`
  275. }
  276. type ResultFile struct {
  277. ClusterID schsdk.ClusterID `json:"clusterID"`
  278. Objects []cdssdk.Object `json:"objects"`
  279. }
  280. type JobSubmitInfo interface {
  281. Noop()
  282. }
  283. type JobSubmitInfoBase struct {
  284. }
  285. var JobSubmitInfoTypeUnion = types.NewTypeUnion[JobSubmitInfo](
  286. (*PCMJobSubmitInfo)(nil),
  287. (*HPCJobSubmitInfo)(nil),
  288. )
  289. var _ = serder.UseTypeUnionInternallyTagged(&JobSubmitInfoTypeUnion, "type")
  290. func (d *JobSubmitInfoBase) Noop() {}
  291. type PCMJobSubmitInfo struct {
  292. serder.Metadata `union:"pcm"`
  293. JobSubmitInfoBase
  294. Type string `json:"type"`
  295. Info CreateAIJobReq `json:"info"`
  296. }
  297. type HPCJobSubmitInfo struct {
  298. serder.Metadata `union:"hpc"`
  299. JobSubmitInfoBase
  300. Type string `json:"type"`
  301. Info hpc.CreateHPCJobReq `json:"info"`
  302. }
  303. type Range struct {
  304. Min float64 `json:"min"`
  305. Max float64 `json:"max"`
  306. }
  307. type ResourcePriority interface {
  308. Noop()
  309. }
  310. type ResourcePriorityBase struct {
  311. }
  312. var ResourcePriorityTypeUnion = types.NewTypeUnion[ResourcePriority](
  313. (*RegionPriority)(nil),
  314. (*ChipPriority)(nil),
  315. (*BiasPriority)(nil),
  316. )
  317. var _ = serder.UseTypeUnionInternallyTagged(&ResourcePriorityTypeUnion, "type")
  318. func (d *ResourcePriorityBase) Noop() {}
  319. type RegionPriority struct {
  320. serder.Metadata `union:"region"`
  321. ResourcePriorityBase
  322. Type string `json:"type"`
  323. Options []string `json:"options"`
  324. }
  325. type ChipPriority struct {
  326. serder.Metadata `union:"chip"`
  327. ResourcePriorityBase
  328. Type string `json:"type"`
  329. Options []string `json:"options"`
  330. }
  331. type BiasPriority struct {
  332. serder.Metadata `union:"bias"`
  333. ResourcePriorityBase
  334. Type string `json:"type"`
  335. Options []string `json:"options"`
  336. }
  337. type TaskMessage struct {
  338. Status string `json:"status"`
  339. Message string `json:"message"`
  340. }
  341. type ReportMessage struct {
  342. TaskName string `json:"taskName"`
  343. TaskID string `json:"taskID"`
  344. Status bool `json:"status"`
  345. Message string `json:"message"`
  346. ClusterID schsdk.ClusterID `json:"clusterID"`
  347. Output string `json:"output"`
  348. }
  349. type UploadParams struct {
  350. DataType string `json:"dataType"`
  351. UploadInfo UploadInfo `json:"uploadInfo"`
  352. }
  353. type UploadInfo interface {
  354. Noop()
  355. }
  356. var UploadInfoTypeUnion = types.NewTypeUnion[UploadInfo](
  357. (*LocalUploadInfo)(nil),
  358. (*RemoteUploadInfo)(nil),
  359. )
  360. var _ = serder.UseTypeUnionInternallyTagged(&UploadInfoTypeUnion, "type")
  361. type LocalUploadInfo struct {
  362. serder.Metadata `union:"local"`
  363. UploadInfoBase
  364. Type string `json:"type"`
  365. LocalPath string `json:"localPath"`
  366. ObjectIDs []cdssdk.ObjectID `json:"objectIDs"`
  367. }
  368. type RemoteUploadInfo struct {
  369. serder.Metadata `union:"url"`
  370. UploadInfoBase
  371. Type string `json:"type"`
  372. Url string `json:"url"`
  373. Branch string `json:"branch"`
  374. DataName string `json:"dataName"`
  375. Cluster schsdk.ClusterID `json:"clusterID"`
  376. }
  377. type UploadInfoBase struct{}
  378. func (d *UploadInfoBase) Noop() {}
  379. type UploadPriority interface {
  380. Noop()
  381. }
  382. var UploadPriorityTypeUnion = types.NewTypeUnion[UploadPriority](
  383. (*Preferences)(nil),
  384. (*SpecifyCluster)(nil),
  385. )
  386. var _ = serder.UseTypeUnionInternallyTagged(&UploadPriorityTypeUnion, "type")
  387. type Preferences struct {
  388. serder.Metadata `union:"preference"`
  389. UploadPriorityBase
  390. Type string `json:"type"`
  391. ResourcePriorities []ResourcePriority `json:"priorities"`
  392. }
  393. type SpecifyCluster struct {
  394. serder.Metadata `union:"specify"`
  395. UploadPriorityBase
  396. Type string `json:"type"`
  397. Clusters []schsdk.ClusterID `json:"clusters"`
  398. }
  399. type UploadPriorityBase struct{}
  400. func (d *UploadPriorityBase) Noop() {}
  401. type QueryData struct {
  402. DataType string `json:"dataType" binding:"required"`
  403. UserID cdssdk.UserID `json:"userID" binding:"required"`
  404. Path string `json:"path"`
  405. PackageID cdssdk.PackageID `json:"packageID" binding:"required"`
  406. CurrentPage int `json:"currentPage"`
  407. PageSize int `json:"pageSize"`
  408. OrderBy string `json:"orderBy" binding:"required"`
  409. PackageName string `json:"packageName"`
  410. }
  411. type Image struct {
  412. ImageID schsdk.ImageID `json:"imageID" gorm:"column:ImageID;primaryKey"`
  413. Name string `json:"name" gorm:"column:Name"`
  414. CreateTime time.Time `json:"createTime" gorm:"column:CreateTime"`
  415. ClusterImage []ClusterImage `gorm:"foreignKey:image_id;references:ImageID" json:"clusterImages"`
  416. }
  417. type ClusterImage struct {
  418. ImageID schsdk.ImageID `gorm:"column:image_id" json:"imageID"`
  419. ClusterID schsdk.ClusterID `gorm:"column:cluster_id" json:"clusterID"`
  420. OriginImageType string `gorm:"column:origin_image_type" json:"originImageType"`
  421. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  422. OriginImageName string `gorm:"column:origin_image_name" json:"originImageName"`
  423. ClusterImageCard []ClusterImageCard `gorm:"foreignKey:origin_image_id;references:origin_image_id" json:"cards"`
  424. }
  425. func (ClusterImage) TableName() string {
  426. return "cluster_image"
  427. }
  428. type ClusterImageCard struct {
  429. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  430. Card string `gorm:"column:card" json:"card"`
  431. }
  432. func (ClusterImageCard) TableName() string {
  433. return "cluster_image_card"
  434. }
  435. type QueryBindingFilters struct {
  436. Status string `json:"status"`
  437. Name string `json:"name"`
  438. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  439. }
  440. type QueryBindingDataParam interface {
  441. Noop()
  442. }
  443. var QueryBindingDataParamTypeUnion = types.NewTypeUnion[QueryBindingDataParam](
  444. (*PrivateLevel)(nil),
  445. (*ApplyLevel)(nil),
  446. (*PublicLevel)(nil),
  447. (*CommonDataParam)(nil),
  448. )
  449. var _ = serder.UseTypeUnionInternallyTagged(&QueryBindingDataParamTypeUnion, "type")
  450. type QueryBindingDataParamBase struct{}
  451. func (d *QueryBindingDataParamBase) Noop() {}
  452. type PrivateLevel struct {
  453. serder.Metadata `union:"private"`
  454. QueryBindingDataParamBase
  455. Type string `json:"type" binding:"required"`
  456. UserID cdssdk.UserID `json:"userID" binding:"required"`
  457. BindingID int64 `json:"bindingID" binding:"required"`
  458. Info schsdk.DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  459. }
  460. type ApplyLevel struct {
  461. serder.Metadata `union:"apply"`
  462. QueryBindingDataParamBase
  463. Type string `json:"type" binding:"required"`
  464. UserID cdssdk.UserID `json:"userID" binding:"required"`
  465. Info schsdk.DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  466. }
  467. type PublicLevel struct {
  468. serder.Metadata `union:"public"`
  469. QueryBindingDataParamBase
  470. UserID cdssdk.UserID `json:"userID" binding:"required"`
  471. Type string `json:"type" binding:"required"`
  472. Info schsdk.DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  473. }
  474. type CommonDataParam struct {
  475. serder.Metadata `union:"common"`
  476. QueryBindingDataParamBase
  477. Type string `json:"type" binding:"required"`
  478. UserID cdssdk.UserID `json:"userID" binding:"required"`
  479. BindingIDs []int64 `json:"bindingIDs" binding:"required"`
  480. }