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.

cloudrbanin.js 16 kB

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
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
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
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
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
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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. export default async function initCloudrain() {
  2. let debug_button = $('.cloudbrain_debug').data('debug')
  3. let debug_again_button = $('.cloudbrain_debug').data('debug-again')
  4. let timeid = window.setInterval(loadJobStatus, 15000);
  5. let timeidShow = window.setInterval(loadShowJobStatus, 15000);
  6. $(document).ready(loadJobStatus);
  7. $(document).ready(loadShowJobStatus);
  8. function loadJobStatus() {
  9. $(".job-status").each((index, job) => {
  10. const ID = job.dataset.jobid;
  11. const repoPath = job.dataset.repopath;
  12. // const computeResource = job.dataset.resource
  13. const versionname = job.dataset.version
  14. const status_text = $(`#${ID}-text`).text()
  15. const finalState = ['STOPPED', 'CREATE_FAILED', 'UNAVAILABLE', 'DELETED', 'RESIZE_FAILED', 'SUCCEEDED', 'IMAGE_FAILED', 'SUBMIT_FAILED', 'DELETE_FAILED', 'KILLED', 'COMPLETED', 'FAILED', 'CANCELED', 'LOST', 'START_FAILED', 'SUBMIT_MODEL_FAILED', 'DEPLOY_SERVICE_FAILED', 'CHECK_FAILED']
  16. if (finalState.includes(status_text)) {
  17. return
  18. }
  19. // const diffResource = computeResource == "NPU" ? 'modelarts/notebook' : 'cloudbrain'
  20. $.get(`/api/v1/repos/${repoPath}/${ID}?version_name=${versionname}`, (data) => {
  21. const ID = data.ID || data.JobID
  22. const status = data.JobStatus
  23. const duration = data.JobDuration
  24. $('#duration-' + ID).text(duration)
  25. if (status != status_text) {
  26. $('#' + ID + '-icon').removeClass().addClass(status)
  27. $('#' + ID + '-text').text(status)
  28. finalState.includes(status) && $('#' + ID + '-stop').removeClass('blue').addClass('disabled')
  29. }
  30. if (status === "RUNNING") {
  31. $('#ai-debug-' + ID).removeClass('disabled').addClass('blue').text(debug_button).css("margin", "0 1rem")
  32. $('#model-image-' + ID).removeClass('disabled').addClass('blue')
  33. }
  34. if (status !== "RUNNING") {
  35. // $('#model-debug-'+ID).removeClass('blue')
  36. // $('#model-debug-'+ID).addClass('disabled')
  37. $('#model-image-' + ID).removeClass('blue').addClass('disabled')
  38. }
  39. if (["CREATING", "STOPPING", "WAITING", "STARTING"].includes(status)) {
  40. $('#ai-debug-' + ID).removeClass('blue').addClass('disabled')
  41. }
  42. if (['STOPPED', 'FAILED', 'START_FAILED', 'CREATE_FAILED', 'SUCCEEDED'].includes(status)) {
  43. $('#ai-debug-' + ID).removeClass('disabled').addClass('blue').text(debug_again_button).css("margin", "0")
  44. }
  45. if (["RUNNING", "WAITING"].includes(status)) {
  46. $('#ai-stop-' + ID).removeClass('disabled').addClass('blue')
  47. }
  48. if (["CREATING", "STOPPING", "STARTING", "STOPPED", "FAILED", "START_FAILED", "SUCCEEDED", "COMPLETED", "CREATE_FAILED"].includes(status)) {
  49. $('#ai-stop-' + ID).removeClass('blue').addClass('disabled')
  50. }
  51. if (["STOPPED", "FAILED", "START_FAILED", "KILLED", "COMPLETED", "SUCCEEDED"].includes(status)) {
  52. $('#ai-delete-' + ID).removeClass('disabled').addClass('blue')
  53. } else {
  54. $('#ai-delete-' + ID).removeClass('blue').addClass('disabled')
  55. }
  56. if (["COMPLETED", "SUCCEEDED"].includes(status)) {
  57. $('#ai-download-' + ID).removeClass('disabled').addClass('blue')
  58. } else {
  59. $('#ai-download-' + ID).removeClass('blue').addClass('disabled')
  60. }
  61. }).fail(function (err) {
  62. console.log(err);
  63. });
  64. });
  65. };
  66. function loadShowJobStatus() {
  67. $(".ui.accordion.border-according").each((index, job) => {
  68. const jobID = job.dataset.jobid;
  69. const repoPath = job.dataset.repopath;
  70. const versionname = job.dataset.version
  71. // ['IMAGE_FAILED','SUBMIT_FAILED','DELETE_FAILED','KILLED','COMPLETED','FAILED','CANCELED','LOST','START_FAILED']
  72. // if (job.textContent.trim() == 'IMAGE_FAILED' || job.textContent.trim() == 'SUBMIT_FAILED' || job.textContent.trim() == 'DELETE_FAILED'
  73. // || job.textContent.trim() == 'KILLED' || job.textContent.trim() == 'COMPLETED' || job.textContent.trim() == 'FAILED'
  74. // || job.textContent.trim() == 'CANCELED' || job.textContent.trim() == 'LOST') {
  75. // return
  76. // }
  77. let status = $(`#${versionname}-status-span`).text()
  78. if (['IMAGE_FAILED', 'SUBMIT_FAILED', 'DELETE_FAILED', 'KILLED', 'COMPLETED', 'FAILED', 'CANCELED', 'LOST', 'START_FAILED', 'SUCCEEDED', 'STOPPED'].includes(status)) {
  79. return
  80. }
  81. let stopArray = ["KILLED", "FAILED", "START_FAILED", "KILLING", "COMPLETED", "SUCCEEDED", "STOPPED"]
  82. $.get(`/api/v1/repos/${repoPath}/${jobID}?version_name=${versionname}`, (data) => {
  83. //$(`#${versionname}-duration-span`).text(data.JobDuration)
  84. $(`#${versionname}-status-span span`).text(data.JobStatus)
  85. $(`#${versionname}-status-span i`).attr("class", data.JobStatus)
  86. // detail status and duration
  87. //$('#'+versionname+'-duration').text(data.JobDuration)
  88. $('#' + versionname + '-status').text(data.JobStatus)
  89. if (stopArray.includes(data.JobStatus)) {
  90. $('#' + versionname + '-stop').addClass('disabled')
  91. }
  92. if (data.JobStatus === "COMPLETED") {
  93. $('#' + versionname + '-create-model').removeClass('disabled').addClass('blue')
  94. }
  95. }).fail(function (err) {
  96. console.log(err);
  97. });
  98. });
  99. };
  100. function assertDelete(obj, versionName, repoPath) {
  101. if (obj.style.color == "rgb(204, 204, 204)") {
  102. return
  103. } else {
  104. const delId = obj.parentNode.id
  105. let flag = 1;
  106. $('.ui.basic.modal')
  107. .modal({
  108. onDeny: function () {
  109. flag = false
  110. },
  111. onApprove: function () {
  112. if (!versionName) {
  113. document.getElementById(delId).submit()
  114. }
  115. else {
  116. deleteVersion(versionName, repoPath)
  117. }
  118. flag = true
  119. },
  120. onHidden: function () {
  121. if (flag == false) {
  122. $('.alert').html('您已取消操作').removeClass('alert-success').addClass('alert-danger').show().delay(1500).fadeOut();
  123. }
  124. }
  125. })
  126. .modal('show')
  127. }
  128. }
  129. function deleteVersion(versionName, repoPath) {
  130. const url = `/api/v1/repos/${repoPath}`
  131. $.post(url, { version_name: versionName }, (data) => {
  132. if (data.StatusOK === 0) {
  133. location.reload()
  134. }
  135. }).fail(function (err) {
  136. console.log(err);
  137. });
  138. }
  139. $('.ui.basic.ai_delete').click(function () {
  140. const repoPath = this.dataset.repopath
  141. const versionName = this.dataset.version
  142. if (repoPath && versionName) {
  143. assertDelete(this, versionName, repoPath)
  144. }
  145. else {
  146. assertDelete(this)
  147. }
  148. })
  149. function stopDebug(ID, stopUrl) {
  150. $.ajax({
  151. type: "POST",
  152. url: stopUrl,
  153. data: $('#stopForm-' + ID).serialize(),
  154. success: function (res) {
  155. if (res.result_code === "0") {
  156. $('#' + ID + '-icon').removeClass().addClass(res.status)
  157. $('#' + ID + '-text').text(res.status)
  158. if (res.status === "STOPPED") {
  159. $('#ai-debug-' + ID).removeClass('disabled').addClass('blue').text(debug_again_button).css("margin", "0")
  160. $('#ai-image-' + ID).removeClass('blue').addClass('disabled')
  161. $('#ai-model-debug-' + ID).removeClass('blue').addClass('disabled')
  162. $('#ai-delete-' + ID).removeClass('disabled').addClass('blue')
  163. $('#ai-stop-' + ID).removeClass('blue').addClass('disabled')
  164. }
  165. else {
  166. $('#ai-debug-' + ID).removeClass('blue').addClass('disabled')
  167. $('#ai-stop-' + ID).removeClass('blue').addClass('disabled')
  168. }
  169. } else {
  170. $('.alert').html(res.error_msg).removeClass('alert-success').addClass('alert-danger').show().delay(2000).fadeOut();
  171. }
  172. },
  173. error: function (res) {
  174. console.log(res)
  175. }
  176. })
  177. }
  178. $('.ui.basic.ai_stop').click(function () {
  179. const ID = this.dataset.jobid
  180. const repoPath = this.dataset.repopath
  181. stopDebug(ID, repoPath)
  182. })
  183. function stopVersion(version_name, ID, repoPath) {
  184. const url = `/api/v1/repos/${repoPath}/${ID}/stop_version`
  185. $.post(url, { version_name: version_name }, (data) => {
  186. if (data.StatusOK === 0) {
  187. $('#ai-stop-' + ID).removeClass('blue')
  188. $('#ai-stop-' + ID).addClass('disabled')
  189. refreshStatus(version_name, ID, repoPath)
  190. }
  191. }).fail(function (err) {
  192. console.log(err);
  193. });
  194. }
  195. function refreshStatus(version_name, ID, repoPath) {
  196. const url = `/api/v1/repos/${repoPath}/${ID}/?version_name${version_name}`
  197. $.get(url, (data) => {
  198. $(`#${ID}-icon`).attr("class", data.JobStatus)
  199. // detail status and duration
  200. $(`#${ID}-text`).text(data.JobStatus)
  201. if (["STOPPED", "FAILED", "START_FAILED", "KILLED", "COMPLETED", "SUCCEEDED"].includes(data.JobStatus)) {
  202. $('#ai-delete-' + ID).removeClass('disabled').addClass('blue')
  203. }
  204. }).fail(function (err) {
  205. console.log(err);
  206. });
  207. }
  208. $('.ui.basic.ai_stop_version').click(function () {
  209. const ID = this.dataset.jobid
  210. const repoPath = this.dataset.repopath
  211. const versionName = this.dataset.version
  212. stopVersion(versionName, ID, repoPath)
  213. })
  214. function getModelInfo(repoPath, modelName, versionName, jobName) {
  215. $.get(`${repoPath}/modelmanage/show_model_info_api?name=${modelName}`, (data) => {
  216. if (data.length === 0) {
  217. $(`#${jobName}`).popup('toggle')
  218. } else {
  219. let versionData = data.filter((item) => {
  220. return item.Version === versionName
  221. })
  222. if (versionData.length == 0) {
  223. $(`#${jobName}`).popup('toggle')
  224. }
  225. else {
  226. location.href = `${repoPath}/modelmanage/show_model_info?name=${modelName}`
  227. }
  228. }
  229. })
  230. }
  231. $('.goto_modelmanage').click(function () {
  232. const repoPath = this.dataset.repopath
  233. const modelName = this.dataset.modelname
  234. const versionName = this.dataset.version
  235. const jobName = this.dataset.jobname
  236. getModelInfo(repoPath, modelName, versionName, jobName)
  237. })
  238. function debugAgain(ID, debugUrl, redirect_to) {
  239. if ($('#' + ID + '-text').text() === "RUNNING") {
  240. window.open(debugUrl + 'debug')
  241. } else {
  242. $.ajax({
  243. type: "POST",
  244. url: debugUrl + 'restart?redirect_to=' + redirect_to,
  245. data: $('#debugAgainForm-' + ID).serialize(),
  246. success: function (res) {
  247. if (res['WechatRedirectUrl']) {
  248. window.location.href = res['WechatRedirectUrl']
  249. }
  250. else if (res.result_code === "0") {
  251. if (res.id !== ID) {
  252. location.reload()
  253. } else {
  254. $('#' + ID + '-icon').removeClass().addClass(res.status)
  255. $('#' + ID + '-text').text(res.status)
  256. $('#ai-debug-' + ID).removeClass('blue').addClass('disabled')
  257. $('#ai-delete-' + ID).removeClass('blue').addClass('disabled')
  258. $('#ai-debug-' + ID).text(debug_button).css("margin", "0 1rem")
  259. }
  260. } else {
  261. $('.alert').html(res.error_msg).removeClass('alert-success').addClass('alert-danger').show().delay(2000).fadeOut();
  262. }
  263. },
  264. error: function (res) {
  265. console.log(res)
  266. }
  267. })
  268. }
  269. }
  270. $('.ui.basic.ai_debug').click(function () {
  271. const ID = this.dataset.jobid
  272. const repoPath = this.dataset.repopath
  273. const redirect_to = this.dataset.linkpath
  274. debugAgain(ID, repoPath, redirect_to)
  275. })
  276. }
  277. function userSearchControll() {
  278. if ($('#userCloud').length === 0) {
  279. return
  280. }
  281. const params = new URLSearchParams(window.location.search)
  282. let jobType
  283. if ($('.cloudbrain_debug').length === 1) {
  284. if (!params.get('jobType')) {
  285. jobType = $('.cloudbrain_debug').data('allTask')
  286. } else {
  287. if (params.get('jobType') === 'DEBUG') {
  288. jobType = $('.cloudbrain_debug').data('debug-task')
  289. } else if (params.get('jobType') === 'TRAIN') {
  290. jobType = $('.cloudbrain_debug').data('train-task')
  291. }
  292. else if (params.get('jobType') === 'INFERENCE') {
  293. jobType = $('.cloudbrain_debug').data('inference-task')
  294. }
  295. else {
  296. jobType = $('.cloudbrain_debug').data('benchmark-task')
  297. }
  298. }
  299. }
  300. let listType = !params.get('listType') ? $('.cloudbrain_debug').data('all-compute') : params.get('listType')
  301. let jobStatus = !params.get('jobStatus') ? $('.cloudbrain_debug').data('all-status') : params.get('jobStatus').toUpperCase()
  302. const dropdownValueArray = [jobType, listType, jobStatus]
  303. $('#userCloud .default.text ').each(function (index, e) {
  304. $(e).text(dropdownValueArray[index])
  305. })
  306. }
  307. function AdaminSearchControll() {
  308. if ($('#adminCloud').length === 0) {
  309. return
  310. }
  311. const params = new URLSearchParams(window.location.search)
  312. let jobType = !params.get('jobType') ? $('.cloudbrain_debug').data('all-task') : params.get('jobType')
  313. let listType = !params.get('listType') ? $('.cloudbrain_debug').data('all-compute') : params.get('listType')
  314. let jobStatus = !params.get('jobStatus') ? $('.cloudbrain_debug').data('all-status') : params.get('jobStatus').toUpperCase()
  315. const dropdownValueArray = [jobType, listType, jobStatus]
  316. $('#adminCloud .default.text ').each(function (index, e) {
  317. $(e).text(dropdownValueArray[index])
  318. })
  319. }
  320. userSearchControll()
  321. AdaminSearchControll()