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.

modelarts.go 18 kB

3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package repo
  6. import (
  7. "encoding/json"
  8. "net/http"
  9. "path"
  10. "strconv"
  11. "strings"
  12. "code.gitea.io/gitea/services/cloudbrain/cloudbrainTask"
  13. "code.gitea.io/gitea/modules/urfs_client/urchin"
  14. "code.gitea.io/gitea/modules/notification"
  15. "code.gitea.io/gitea/modules/grampus"
  16. "code.gitea.io/gitea/modules/setting"
  17. "code.gitea.io/gitea/models"
  18. "code.gitea.io/gitea/modules/context"
  19. "code.gitea.io/gitea/modules/log"
  20. "code.gitea.io/gitea/modules/modelarts"
  21. "code.gitea.io/gitea/modules/storage"
  22. "code.gitea.io/gitea/modules/timeutil"
  23. routerRepo "code.gitea.io/gitea/routers/repo"
  24. cloudbrainService "code.gitea.io/gitea/services/cloudbrain"
  25. )
  26. func GetModelArtsNotebook2(ctx *context.APIContext) {
  27. var (
  28. err error
  29. )
  30. ID := ctx.Params(":id")
  31. job, err := models.GetCloudbrainByID(ID)
  32. if err != nil {
  33. job, err = models.GetCloudbrainByJobID(ID)
  34. if err != nil {
  35. ctx.NotFound(err)
  36. return
  37. }
  38. }
  39. err = modelarts.HandleNotebookInfo(job)
  40. if err != nil {
  41. ctx.NotFound(err)
  42. return
  43. }
  44. ctx.JSON(http.StatusOK, map[string]interface{}{
  45. "ID": ID,
  46. "JobName": job.JobName,
  47. "JobStatus": job.Status,
  48. "JobDuration": job.TrainJobDuration,
  49. "StartTime": job.StartTime,
  50. })
  51. }
  52. func GetModelArtsTrainJob(ctx *context.APIContext) {
  53. var (
  54. err error
  55. )
  56. jobID := ctx.Params(":jobid")
  57. repoID := ctx.Repo.Repository.ID
  58. job, err := models.GetRepoCloudBrainByJobID(repoID, jobID)
  59. if err != nil {
  60. ctx.NotFound(err)
  61. return
  62. }
  63. result, err := modelarts.GetTrainJob(jobID, strconv.FormatInt(job.VersionID, 10))
  64. if err != nil {
  65. ctx.NotFound(err)
  66. return
  67. }
  68. oldStatus := job.Status
  69. job.Status = modelarts.TransTrainJobStatus(result.IntStatus)
  70. job.Duration = result.Duration
  71. job.TrainJobDuration = result.TrainJobDuration
  72. if oldStatus != job.Status {
  73. notification.NotifyChangeCloudbrainStatus(job, oldStatus)
  74. }
  75. err = models.UpdateJob(job)
  76. if err != nil {
  77. log.Error("UpdateJob failed:", err)
  78. }
  79. ctx.JSON(http.StatusOK, map[string]interface{}{
  80. "JobID": jobID,
  81. "JobStatus": job.Status,
  82. "JobDuration": job.Duration,
  83. })
  84. }
  85. func GetModelArtsTrainJobVersion(ctx *context.APIContext) {
  86. var (
  87. err error
  88. aiCenterName string
  89. )
  90. jobID := ctx.Params(":jobid")
  91. versionName := ctx.Query("version_name")
  92. job, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
  93. if err != nil {
  94. ctx.NotFound(err)
  95. return
  96. }
  97. if job.Type == models.TypeCloudBrainOne {
  98. job, err = cloudbrainTask.SyncCloudBrainOneStatus(job)
  99. if err != nil {
  100. ctx.NotFound(err)
  101. return
  102. }
  103. } else if job.Type == models.TypeCloudBrainTwo {
  104. err := modelarts.HandleTrainJobInfo(job)
  105. if err != nil {
  106. ctx.NotFound(err)
  107. return
  108. }
  109. } else if job.Type == models.TypeC2Net {
  110. result, err := grampus.GetJob(jobID)
  111. if err != nil {
  112. log.Error("GetJob(%s) failed:%v", job.JobName, err)
  113. ctx.NotFound(err)
  114. return
  115. }
  116. if job.StartTime == 0 && result.JobInfo.StartedAt > 0 {
  117. job.StartTime = timeutil.TimeStamp(result.JobInfo.StartedAt)
  118. }
  119. oldStatus := job.Status
  120. job.Status = grampus.TransTrainJobStatus(result.JobInfo.Status)
  121. job.Duration = result.JobInfo.RunSec
  122. job.TrainJobDuration = models.ConvertDurationToStr(job.Duration)
  123. if job.EndTime == 0 && models.IsTrainJobTerminal(job.Status) && job.StartTime > 0 {
  124. job.EndTime = job.StartTime.Add(job.Duration)
  125. }
  126. job.CorrectCreateUnix()
  127. if len(job.AiCenter) == 0 {
  128. if len(result.JobInfo.Tasks) > 0 {
  129. if len(result.JobInfo.Tasks[0].CenterID) > 0 && len(result.JobInfo.Tasks[0].CenterName) > 0 {
  130. job.AiCenter = result.JobInfo.Tasks[0].CenterID[0] + "+" + result.JobInfo.Tasks[0].CenterName[0]
  131. // aiCenterName = result.JobInfo.Tasks[0].CenterName[0]
  132. aiCenterName = cloudbrainService.GetAiCenterShow(job.AiCenter, ctx.Context)
  133. }
  134. }
  135. } else {
  136. aiCenterName = cloudbrainService.GetAiCenterShow(job.AiCenter, ctx.Context)
  137. }
  138. if oldStatus != job.Status {
  139. notification.NotifyChangeCloudbrainStatus(job, oldStatus)
  140. if models.IsTrainJobTerminal(job.Status) && job.ComputeResource == models.NPUResource {
  141. if len(result.JobInfo.Tasks[0].CenterID) == 1 {
  142. urchin.GetBackNpuModel(job.ID, grampus.GetRemoteEndPoint(result.JobInfo.Tasks[0].CenterID[0]), grampus.BucketRemote, grampus.GetNpuModelObjectKey(job.JobName), grampus.GetCenterProxy(setting.Grampus.LocalCenterID))
  143. }
  144. }
  145. }
  146. err = models.UpdateTrainJobVersion(job)
  147. if err != nil {
  148. log.Error("UpdateJob failed:", err)
  149. }
  150. }
  151. ctx.JSON(http.StatusOK, map[string]interface{}{
  152. "JobID": jobID,
  153. "JobStatus": job.Status,
  154. "JobDuration": job.TrainJobDuration,
  155. "AiCenter": aiCenterName,
  156. "StartTime": job.StartTime,
  157. })
  158. }
  159. func TrainJobForModelConvertGetLog(ctx *context.APIContext) {
  160. var (
  161. err error
  162. )
  163. var jobID = ctx.Params(":id")
  164. var baseLine = ctx.Query("base_line")
  165. var order = ctx.Query("order")
  166. var lines = ctx.Query("lines")
  167. lines_int, err := strconv.Atoi(lines)
  168. if err != nil {
  169. log.Error("change lines(%d) string to int failed", lines_int)
  170. }
  171. if order != modelarts.OrderDesc && order != modelarts.OrderAsc {
  172. log.Error("order(%s) check failed", order)
  173. ctx.JSON(http.StatusBadRequest, map[string]interface{}{
  174. "err_msg": "order check failed",
  175. })
  176. return
  177. }
  178. resultLogFile, result, err := trainJobForModelConvertGetLogContent(jobID, baseLine, order, lines_int)
  179. if err != nil {
  180. log.Error("trainJobGetLog(%s) failed:%v", jobID, err.Error())
  181. // ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil)
  182. ctx.JSON(http.StatusOK, map[string]interface{}{
  183. "JobID": jobID,
  184. "LogFileName": "",
  185. "StartLine": "0",
  186. "EndLine": "0",
  187. "Content": "",
  188. "Lines": 0,
  189. })
  190. return
  191. }
  192. ctx.Data["log_file_name"] = resultLogFile.LogFileList[0]
  193. ctx.JSON(http.StatusOK, map[string]interface{}{
  194. "JobID": jobID,
  195. "LogFileName": resultLogFile.LogFileList[0],
  196. "StartLine": result.StartLine,
  197. "EndLine": result.EndLine,
  198. "Content": result.Content,
  199. "Lines": result.Lines,
  200. })
  201. }
  202. func trainJobForModelConvertGetLogContent(jobID string, baseLine string, order string, lines int) (*models.GetTrainJobLogFileNamesResult, *models.GetTrainJobLogResult, error) {
  203. task, err := models.QueryModelConvertById(jobID)
  204. if err != nil {
  205. log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error())
  206. return nil, nil, err
  207. }
  208. resultLogFile, err := modelarts.GetTrainJobLogFileNames(task.CloudBrainTaskId, task.ModelArtsVersionId)
  209. if err != nil {
  210. log.Error("GetTrainJobLogFileNames(%s) failed:%v", task.CloudBrainTaskId, err.Error())
  211. return nil, nil, err
  212. }
  213. result, err := modelarts.GetTrainJobLog(task.CloudBrainTaskId, task.ModelArtsVersionId, baseLine, resultLogFile.LogFileList[0], order, lines)
  214. if err != nil {
  215. log.Error("GetTrainJobLog(%s) failed:%v", task.CloudBrainTaskId, err.Error())
  216. return nil, nil, err
  217. }
  218. return resultLogFile, result, err
  219. }
  220. func TrainJobGetLog(ctx *context.APIContext) {
  221. var (
  222. err error
  223. )
  224. var jobID = ctx.Params(":jobid")
  225. var versionName = ctx.Query("version_name")
  226. var baseLine = ctx.Query("base_line")
  227. var order = ctx.Query("order")
  228. var lines = ctx.Query("lines")
  229. lines_int, err := strconv.Atoi(lines)
  230. if err != nil {
  231. log.Error("change lines(%d) string to int failed", lines_int)
  232. }
  233. if order != modelarts.OrderDesc && order != modelarts.OrderAsc {
  234. log.Error("order(%s) check failed", order)
  235. ctx.JSON(http.StatusBadRequest, map[string]interface{}{
  236. "err_msg": "order check failed",
  237. })
  238. return
  239. }
  240. task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
  241. if err != nil {
  242. log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error())
  243. return
  244. }
  245. resultLogFile, result, err := trainJobGetLogContent(jobID, task.VersionID, baseLine, order, lines_int)
  246. if err != nil {
  247. log.Error("trainJobGetLog(%s) failed:%v", jobID, err.Error())
  248. // ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil)
  249. return
  250. }
  251. prefix := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, modelarts.LogPath, versionName), "/") + "/job"
  252. _, err = storage.GetObsLogFileName(prefix)
  253. var canLogDownload bool
  254. if err != nil {
  255. canLogDownload = false
  256. } else {
  257. canLogDownload = true
  258. }
  259. ctx.Data["log_file_name"] = resultLogFile.LogFileList[0]
  260. ctx.JSON(http.StatusOK, map[string]interface{}{
  261. "JobID": jobID,
  262. "LogFileName": resultLogFile.LogFileList[0],
  263. "StartLine": result.StartLine,
  264. "EndLine": result.EndLine,
  265. "Content": result.Content,
  266. "Lines": result.Lines,
  267. "CanLogDownload": canLogDownload,
  268. "StartTime": task.StartTime,
  269. })
  270. }
  271. func trainJobGetLogContent(jobID string, versionID int64, baseLine string, order string, lines int) (*models.GetTrainJobLogFileNamesResult, *models.GetTrainJobLogResult, error) {
  272. resultLogFile, err := modelarts.GetTrainJobLogFileNames(jobID, strconv.FormatInt(versionID, 10))
  273. if err != nil {
  274. log.Error("GetTrainJobLogFileNames(%s) failed:%v", jobID, err.Error())
  275. return nil, nil, err
  276. }
  277. result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(versionID, 10), baseLine, resultLogFile.LogFileList[0], order, lines)
  278. if err != nil {
  279. log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error())
  280. return nil, nil, err
  281. }
  282. return resultLogFile, result, err
  283. }
  284. func DelTrainJobVersion(ctx *context.APIContext) {
  285. var (
  286. err error
  287. )
  288. var jobID = ctx.Params(":jobid")
  289. var versionName = ctx.Query("version_name")
  290. task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
  291. if err != nil {
  292. log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error())
  293. ctx.NotFound(err)
  294. return
  295. }
  296. if task.Status != string(models.ModelArtsTrainJobImageFailed) && task.Status != string(models.ModelArtsTrainJobSubmitFailed) && task.Status != string(models.ModelArtsTrainJobDeleteFailed) &&
  297. task.Status != string(models.ModelArtsTrainJobCompleted) && task.Status != string(models.ModelArtsTrainJobFailed) &&
  298. task.Status != string(models.ModelArtsTrainJobKilled) && task.Status != string(models.ModelArtsTrainJobCanceled) && task.Status != string(models.ModelArtsTrainJobLost) {
  299. log.Error("the job(%s) version has not been stopped", task.JobName)
  300. ctx.NotFound(err)
  301. return
  302. }
  303. //删除modelarts上的记录
  304. _, err = modelarts.DelTrainJobVersion(jobID, strconv.FormatInt(task.VersionID, 10))
  305. if err != nil {
  306. log.Error("DelTrainJobVersion(%s) failed:%v", task.JobName, err.Error())
  307. ctx.NotFound(err)
  308. return
  309. }
  310. //删除数据库记录
  311. err = models.DeleteJob(task)
  312. if err != nil {
  313. ctx.ServerError("DeleteJob failed", err)
  314. ctx.NotFound(err)
  315. return
  316. }
  317. //获取删除后的版本数量
  318. var jobTypes []string
  319. jobTypes = append(jobTypes, string(models.JobTypeTrain))
  320. repo := ctx.Repo.Repository
  321. VersionTaskList, VersionListCount, err := models.CloudbrainsVersionList(&models.CloudbrainsOptions{
  322. RepoID: repo.ID,
  323. Type: models.TypeCloudBrainTwo,
  324. JobTypes: jobTypes,
  325. JobID: jobID,
  326. })
  327. if err != nil {
  328. ctx.ServerError("get VersionListCount failed", err)
  329. return
  330. }
  331. if VersionListCount > 0 {
  332. // 判断当前删掉的任务是否是最新版本,若是,将排序后的TotalVersionCount置为删掉的最新版本的TotalVersionCount,若不是,按时间排序后的版本列表的第一个版本设置为最新版本,TotalVersionCount不变
  333. if task.IsLatestVersion == modelarts.IsLatestVersion {
  334. err = models.SetVersionCountAndLatestVersion(jobID, VersionTaskList[0].Cloudbrain.VersionName, VersionListCount, modelarts.IsLatestVersion, task.TotalVersionCount)
  335. if err != nil {
  336. ctx.ServerError("UpdateJobVersionCount failed", err)
  337. return
  338. }
  339. } else {
  340. err = models.SetVersionCountAndLatestVersion(jobID, VersionTaskList[0].VersionName, VersionListCount, modelarts.IsLatestVersion, VersionTaskList[0].Cloudbrain.TotalVersionCount)
  341. if err != nil {
  342. ctx.ServerError("UpdateJobVersionCount failed", err)
  343. return
  344. }
  345. }
  346. } else { //已删除该任务下的所有版本
  347. routerRepo.DeleteJobStorage(task.JobName)
  348. }
  349. ctx.JSON(http.StatusOK, map[string]interface{}{
  350. "JobID": jobID,
  351. "VersionName": versionName,
  352. "StatusOK": 0,
  353. "VersionListCount": VersionListCount,
  354. })
  355. }
  356. func StopTrainJobVersion(ctx *context.APIContext) {
  357. var (
  358. err error
  359. )
  360. var jobID = ctx.Params(":jobid")
  361. var versionName = ctx.Query("version_name")
  362. task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
  363. if err != nil {
  364. log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error())
  365. return
  366. }
  367. _, err = modelarts.StopTrainJob(jobID, strconv.FormatInt(task.VersionID, 10))
  368. if err != nil {
  369. log.Error("StopTrainJob(%s) failed:%v", task.JobName, err.Error())
  370. return
  371. }
  372. ctx.JSON(http.StatusOK, map[string]interface{}{
  373. "JobID": jobID,
  374. "VersionName": versionName,
  375. "StatusOK": 0,
  376. })
  377. }
  378. func ModelList(ctx *context.APIContext) {
  379. var (
  380. err error
  381. )
  382. var jobID = ctx.Params(":jobid")
  383. var versionName = ctx.Query("version_name")
  384. parentDir := ctx.Query("parentDir")
  385. dirArray := strings.Split(parentDir, "/")
  386. task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
  387. if err != nil {
  388. log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error())
  389. return
  390. }
  391. status := models.StorageScheduleSucceed
  392. var fileInfos []storage.FileInfo
  393. if task.ComputeResource == models.NPUResource {
  394. prefix := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, setting.OutPutPath, versionName), "/")
  395. if !strings.HasSuffix(prefix, "/") {
  396. prefix += "/"
  397. }
  398. fileInfos, err = storage.GetOneLevelAllObjectUnderDir(setting.Bucket, prefix, parentDir)
  399. if err != nil {
  400. log.Info("get TrainJobListModel failed:", err)
  401. ctx.ServerError("GetObsListObject:", err)
  402. return
  403. }
  404. if task.Type == models.TypeC2Net {
  405. if len(fileInfos) > 0 {
  406. status = models.StorageScheduleSucceed
  407. } else {
  408. if models.IsTrainJobTerminal(task.Status) {
  409. if task.Status == models.GrampusStatusStopped {
  410. status = models.StorageNoFile
  411. } else if task.Status == models.GrampusStatusFailed {
  412. if task.AiCenter == "" {
  413. status = models.StorageNoFile
  414. }
  415. } else {
  416. record, _ := models.GetScheduleRecordByCloudbrainID(task.ID)
  417. if record != nil {
  418. status = record.Status
  419. if status == models.StorageScheduleSucceed {
  420. status = models.StorageNoFile
  421. }
  422. } else {
  423. status = models.StorageScheduleProcessing
  424. }
  425. }
  426. } else {
  427. status = models.StorageScheduleWaiting
  428. }
  429. }
  430. }
  431. } else if task.ComputeResource == models.GPUResource {
  432. files, err := routerRepo.GetModelDirs(task.JobName, parentDir)
  433. if err != nil {
  434. log.Info("GetModelDirs failed:", err)
  435. ctx.ServerError("GetModelDirs:", err)
  436. return
  437. }
  438. err = json.Unmarshal([]byte(files), &fileInfos)
  439. if err != nil {
  440. log.Error("json.Unmarshal failed:%v", err.Error(), ctx.Data["msgID"])
  441. ctx.ServerError("json.Unmarshal failed:", err)
  442. return
  443. }
  444. }
  445. ctx.JSON(http.StatusOK, map[string]interface{}{
  446. "JobID": jobID,
  447. "VersionName": versionName,
  448. "StatusOK": status,
  449. "Path": dirArray,
  450. "Dirs": fileInfos,
  451. "task": task,
  452. "PageIsCloudBrain": true,
  453. })
  454. }
  455. func GetModelArtsInferenceJob(ctx *context.APIContext) {
  456. var (
  457. err error
  458. )
  459. jobID := ctx.Params(":jobid")
  460. job, err := models.GetCloudbrainByJobID(jobID)
  461. if err != nil {
  462. ctx.NotFound(err)
  463. return
  464. }
  465. err = modelarts.HandleTrainJobInfo(job)
  466. if err != nil {
  467. ctx.NotFound(err)
  468. return
  469. }
  470. ctx.JSON(http.StatusOK, map[string]interface{}{
  471. "JobID": jobID,
  472. "JobStatus": job.Status,
  473. "JobDuration": job.TrainJobDuration,
  474. "StartTime": job.StartTime,
  475. })
  476. }
  477. func ResultList(ctx *context.APIContext) {
  478. var (
  479. err error
  480. )
  481. var jobID = ctx.Params(":jobid")
  482. var versionName = ctx.Query("version_name")
  483. parentDir := ctx.Query("parentDir")
  484. dirArray := strings.Split(parentDir, "/")
  485. task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
  486. if err != nil {
  487. log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error())
  488. return
  489. }
  490. models, err := storage.GetObsListObject(task.JobName, "result/", parentDir, versionName)
  491. if err != nil {
  492. log.Info("get TrainJobListModel failed:", err)
  493. ctx.ServerError("GetObsListObject:", err)
  494. return
  495. }
  496. ctx.JSON(http.StatusOK, map[string]interface{}{
  497. "JobID": jobID,
  498. "VersionName": versionName,
  499. "StatusOK": 0,
  500. "Path": dirArray,
  501. "Dirs": models,
  502. "task": task,
  503. "PageIsCloudBrain": true,
  504. })
  505. }
  506. func TrainJobGetMetricStatistic(ctx *context.APIContext) {
  507. var (
  508. err error
  509. )
  510. var jobID = ctx.Params(":jobid")
  511. var versionName = ctx.Query("version_name")
  512. result, err := trainJobGetMetricStatistic(jobID, versionName)
  513. if err != nil {
  514. log.Error("trainJobGetMetricStatistic(%s) failed:%v", jobID, err.Error())
  515. return
  516. }
  517. ctx.JSON(http.StatusOK, map[string]interface{}{
  518. "JobID": jobID,
  519. "Interval": result.Interval,
  520. "MetricsInfo": result.MetricsInfo,
  521. })
  522. }
  523. func trainJobGetMetricStatistic(jobID string, versionName string) (*models.GetTrainJobMetricStatisticResult, error) {
  524. task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
  525. if err != nil {
  526. log.Error("GetCloudbrainByJobIDAndVersionName(%s) failed:%v", jobID, err.Error())
  527. return nil, err
  528. }
  529. resultLogFile, err := modelarts.GetTrainJobLogFileNames(jobID, strconv.FormatInt(task.VersionID, 10))
  530. if err != nil {
  531. log.Error("GetTrainJobLogFileNames(%s) failed:%v", jobID, err.Error())
  532. return nil, err
  533. }
  534. result, err := modelarts.GetTrainJobMetricStatistic(jobID, strconv.FormatInt(task.VersionID, 10), resultLogFile.LogFileList[0])
  535. if err != nil {
  536. log.Error("GetTrainJobMetricStatistic(%s) failed:%v", jobID, err.Error())
  537. return nil, err
  538. }
  539. return result, err
  540. }