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

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
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
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
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. "net/http"
  8. "strconv"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/context"
  11. "code.gitea.io/gitea/modules/log"
  12. "code.gitea.io/gitea/modules/modelarts"
  13. )
  14. func GetModelArtsNotebook(ctx *context.APIContext) {
  15. var (
  16. err error
  17. )
  18. jobID := ctx.Params(":jobid")
  19. repoID := ctx.Repo.Repository.ID
  20. job, err := models.GetRepoCloudBrainByJobID(repoID, jobID)
  21. if err != nil {
  22. ctx.NotFound(err)
  23. return
  24. }
  25. result, err := modelarts.GetJob(jobID)
  26. if err != nil {
  27. ctx.NotFound(err)
  28. return
  29. }
  30. job.Status = result.Status
  31. err = models.UpdateJob(job)
  32. if err != nil {
  33. log.Error("UpdateJob failed:", err)
  34. }
  35. ctx.JSON(http.StatusOK, map[string]interface{}{
  36. "JobID": jobID,
  37. "JobStatus": result.Status,
  38. })
  39. }
  40. func GetModelArtsTrainJob(ctx *context.APIContext) {
  41. var (
  42. err error
  43. )
  44. jobID := ctx.Params(":jobid")
  45. repoID := ctx.Repo.Repository.ID
  46. job, err := models.GetRepoCloudBrainByJobID(repoID, jobID)
  47. if err != nil {
  48. ctx.NotFound(err)
  49. return
  50. }
  51. result, err := modelarts.GetTrainJob(jobID, strconv.FormatInt(job.VersionID, 10))
  52. if err != nil {
  53. ctx.NotFound(err)
  54. return
  55. }
  56. job.Status = modelarts.TransTrainJobStatus(result.IntStatus)
  57. job.Duration = result.Duration
  58. job.TrainJobDuration = result.TrainJobDuration
  59. err = models.UpdateJob(job)
  60. if err != nil {
  61. log.Error("UpdateJob failed:", err)
  62. }
  63. ctx.JSON(http.StatusOK, map[string]interface{}{
  64. "JobID": jobID,
  65. "JobStatus": job.Status,
  66. "JobDuration": job.Duration,
  67. })
  68. }
  69. func GetModelArtsTrainJobVersion(ctx *context.APIContext) {
  70. var (
  71. err error
  72. )
  73. jobID := ctx.Params(":jobid")
  74. versionName := ctx.Query("version_name")
  75. repoID := ctx.Repo.Repository.ID
  76. job, err := models.GetRepoCloudBrainByJobIDAndVersionName(repoID, jobID, versionName)
  77. if err != nil {
  78. ctx.NotFound(err)
  79. return
  80. }
  81. result, err := modelarts.GetTrainJob(jobID, strconv.FormatInt(job.VersionID, 10))
  82. if err != nil {
  83. ctx.NotFound(err)
  84. return
  85. }
  86. job.Status = modelarts.TransTrainJobStatus(result.IntStatus)
  87. job.Duration = result.Duration
  88. job.TrainJobDuration = result.TrainJobDuration
  89. err = models.UpdateJob(job)
  90. if err != nil {
  91. log.Error("UpdateJob failed:", err)
  92. }
  93. ctx.JSON(http.StatusOK, map[string]interface{}{
  94. "JobID": jobID,
  95. "JobStatus": job.Status,
  96. "JobDuration": job.Duration,
  97. })
  98. }
  99. func TrainJobGetLog(ctx *context.APIContext) {
  100. var (
  101. err error
  102. )
  103. log.Info("test")
  104. var jobID = ctx.Params(":jobid")
  105. var versionName = ctx.Query("version_name")
  106. var logFileName = ctx.Query("file_name")
  107. var baseLine = ctx.Query("base_line")
  108. var order = ctx.Query("order")
  109. if order != modelarts.OrderDesc && order != modelarts.OrderAsc {
  110. log.Error("order(%s) check failed", order)
  111. ctx.JSON(http.StatusBadRequest, map[string]interface{}{
  112. "err_msg": "order check failed",
  113. })
  114. return
  115. }
  116. task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
  117. if err != nil {
  118. log.Error("GetCloudbrainByJobIDAndVersionName(%s) failed:%v", jobID, err.Error())
  119. ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
  120. "err_msg": "GetCloudbrainByJobIDAndVersionName failed",
  121. })
  122. return
  123. }
  124. result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), baseLine, logFileName, order, modelarts.Lines)
  125. if err != nil {
  126. log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error())
  127. ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
  128. "err_msg": "GetTrainJobLog failed",
  129. })
  130. return
  131. }
  132. ctx.JSON(http.StatusOK, map[string]interface{}{
  133. "JobID": jobID,
  134. "StartLine": result.StartLine,
  135. "EndLine": result.EndLine,
  136. "Content": result.Content,
  137. "Lines": result.Lines,
  138. })
  139. }