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

3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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 = [
  16. "STOPPED",
  17. "CREATE_FAILED",
  18. "UNAVAILABLE",
  19. "DELETED",
  20. "RESIZE_FAILED",
  21. "SUCCEEDED",
  22. "IMAGE_FAILED",
  23. "SUBMIT_FAILED",
  24. "DELETE_FAILED",
  25. "KILLED",
  26. "COMPLETED",
  27. "FAILED",
  28. "CANCELED",
  29. "LOST",
  30. "START_FAILED",
  31. "SUBMIT_MODEL_FAILED",
  32. "DEPLOY_SERVICE_FAILED",
  33. "CHECK_FAILED",
  34. ];
  35. if (finalState.includes(status_text)) {
  36. return;
  37. }
  38. // const diffResource = computeResource == "NPU" ? 'modelarts/notebook' : 'cloudbrain'
  39. $.get(
  40. `/api/v1/repos/${repoPath}/${ID}?version_name=${versionname}`,
  41. (data) => {
  42. const ID = data.ID || data.JobID;
  43. const status = data.JobStatus;
  44. const duration = data.JobDuration;
  45. $("#duration-" + ID).text(duration);
  46. if (status != status_text) {
  47. $("#" + ID + "-icon")
  48. .removeClass()
  49. .addClass(status);
  50. $("#" + ID + "-text").text(status);
  51. finalState.includes(status) &&
  52. $("#" + ID + "-stop")
  53. .removeClass("blue")
  54. .addClass("disabled");
  55. }
  56. if (status === "RUNNING") {
  57. $("#ai-debug-" + ID)
  58. .removeClass("disabled")
  59. .addClass("blue")
  60. .text(debug_button)
  61. .css("margin", "0 1rem");
  62. $("#model-image-" + ID)
  63. .removeClass("disabled")
  64. .addClass("blue");
  65. }
  66. if (status !== "RUNNING") {
  67. // $('#model-debug-'+ID).removeClass('blue')
  68. // $('#model-debug-'+ID).addClass('disabled')
  69. $("#model-image-" + ID)
  70. .removeClass("blue")
  71. .addClass("disabled");
  72. }
  73. if (
  74. ["CREATING", "STOPPING", "WAITING", "STARTING"].includes(status)
  75. ) {
  76. $("#ai-debug-" + ID)
  77. .removeClass("blue")
  78. .addClass("disabled");
  79. }
  80. if (
  81. [
  82. "STOPPED",
  83. "FAILED",
  84. "START_FAILED",
  85. "CREATE_FAILED",
  86. "SUCCEEDED",
  87. ].includes(status)
  88. ) {
  89. $("#ai-debug-" + ID)
  90. .removeClass("disabled")
  91. .addClass("blue")
  92. .text(debug_again_button)
  93. .css("margin", "0");
  94. }
  95. if (["RUNNING", "WAITING"].includes(status)) {
  96. $("#ai-stop-" + ID)
  97. .removeClass("disabled")
  98. .addClass("blue");
  99. }
  100. if (
  101. [
  102. "CREATING",
  103. "STOPPING",
  104. "STARTING",
  105. "STOPPED",
  106. "FAILED",
  107. "START_FAILED",
  108. "SUCCEEDED",
  109. "COMPLETED",
  110. "CREATE_FAILED",
  111. ].includes(status)
  112. ) {
  113. $("#ai-stop-" + ID)
  114. .removeClass("blue")
  115. .addClass("disabled");
  116. }
  117. if (
  118. [
  119. "STOPPED",
  120. "FAILED",
  121. "START_FAILED",
  122. "KILLED",
  123. "COMPLETED",
  124. "SUCCEEDED",
  125. "CREATE_FAILED"
  126. ].includes(status)
  127. ) {
  128. $("#ai-delete-" + ID)
  129. .removeClass("disabled")
  130. .addClass("blue");
  131. } else {
  132. $("#ai-delete-" + ID)
  133. .removeClass("blue")
  134. .addClass("disabled");
  135. }
  136. }
  137. ).fail(function (err) {
  138. console.log(err);
  139. });
  140. });
  141. }
  142. function loadShowJobStatus() {
  143. $(".ui.accordion.border-according").each((index, job) => {
  144. const jobID = job.dataset.jobid;
  145. const repoPath = job.dataset.repopath;
  146. const versionname = job.dataset.version;
  147. // ['IMAGE_FAILED','SUBMIT_FAILED','DELETE_FAILED','KILLED','COMPLETED','FAILED','CANCELED','LOST','START_FAILED']
  148. // if (job.textContent.trim() == 'IMAGE_FAILED' || job.textContent.trim() == 'SUBMIT_FAILED' || job.textContent.trim() == 'DELETE_FAILED'
  149. // || job.textContent.trim() == 'KILLED' || job.textContent.trim() == 'COMPLETED' || job.textContent.trim() == 'FAILED'
  150. // || job.textContent.trim() == 'CANCELED' || job.textContent.trim() == 'LOST') {
  151. // return
  152. // }
  153. let status = $(`#${versionname}-status-span`).text();
  154. if (
  155. [
  156. "IMAGE_FAILED",
  157. "SUBMIT_FAILED",
  158. "DELETE_FAILED",
  159. "KILLED",
  160. "COMPLETED",
  161. "FAILED",
  162. "CANCELED",
  163. "LOST",
  164. "START_FAILED",
  165. "SUCCEEDED",
  166. "STOPPED",
  167. "CREATE_FAILED",
  168. ].includes(status)
  169. ) {
  170. return;
  171. }
  172. let stopArray = [
  173. "KILLED",
  174. "FAILED",
  175. "START_FAILED",
  176. "KILLING",
  177. "COMPLETED",
  178. "SUCCEEDED",
  179. "CREATE_FAILED",
  180. "STOPPED",
  181. ];
  182. $.get(
  183. `/api/v1/repos/${repoPath}/${jobID}?version_name=${versionname}`,
  184. (data) => {
  185. $(`#${versionname}-duration-span`).text(data.JobDuration);
  186. $(`#${versionname}-status-span span`).text(data.JobStatus);
  187. $(`#${versionname}-status-span i`).attr("class", data.JobStatus);
  188. // detail status and duration
  189. $("#" + versionname + "-duration").text(data.JobDuration);
  190. $("#" + versionname + "-status").text(data.JobStatus);
  191. if (stopArray.includes(data.JobStatus)) {
  192. $("#" + versionname + "-stop").addClass("disabled");
  193. }
  194. if (data.JobStatus === "COMPLETED") {
  195. $("#" + versionname + "-create-model")
  196. .removeClass("disabled")
  197. .addClass("blue");
  198. }
  199. }
  200. ).fail(function (err) {
  201. console.log(err);
  202. });
  203. });
  204. }
  205. function assertDelete(obj, versionName, repoPath) {
  206. if (obj.style.color == "rgb(204, 204, 204)") {
  207. return;
  208. } else {
  209. const delId = obj.parentNode.id;
  210. let flag = 1;
  211. $(".ui.basic.modal")
  212. .modal({
  213. onDeny: function () {
  214. flag = false;
  215. },
  216. onApprove: function () {
  217. if (!versionName) {
  218. document.getElementById(delId).submit();
  219. } else {
  220. deleteVersion(versionName, repoPath);
  221. }
  222. flag = true;
  223. },
  224. onHidden: function () {
  225. if (flag == false) {
  226. $(".alert")
  227. .html("您已取消操作")
  228. .removeClass("alert-success")
  229. .addClass("alert-danger")
  230. .show()
  231. .delay(1500)
  232. .fadeOut();
  233. }
  234. },
  235. })
  236. .modal("show");
  237. }
  238. }
  239. function deleteVersion(versionName, repoPath) {
  240. const url = `/api/v1/repos/${repoPath}`;
  241. $.post(url, { version_name: versionName }, (data) => {
  242. if (data.StatusOK === 0 || data.Code === 0) {
  243. location.reload();
  244. }
  245. }).fail(function (err) {
  246. console.log(err);
  247. });
  248. }
  249. $(".ui.basic.ai_delete").click(function () {
  250. const repoPath = this.dataset.repopath;
  251. const versionName = this.dataset.version;
  252. if (repoPath && versionName) {
  253. assertDelete(this, versionName, repoPath);
  254. } else {
  255. assertDelete(this);
  256. }
  257. });
  258. function stopDebug(ID, stopUrl) {
  259. $.ajax({
  260. type: "POST",
  261. url: stopUrl,
  262. data: $("#stopForm-" + ID).serialize(),
  263. success: function (res) {
  264. if (res.result_code === "0") {
  265. $("#" + ID + "-icon")
  266. .removeClass()
  267. .addClass(res.status);
  268. $("#" + ID + "-text").text(res.status);
  269. if (res.status === "STOPPED") {
  270. $("#ai-debug-" + ID)
  271. .removeClass("disabled")
  272. .addClass("blue")
  273. .text(debug_again_button)
  274. .css("margin", "0");
  275. $("#ai-image-" + ID)
  276. .removeClass("blue")
  277. .addClass("disabled");
  278. $("#ai-model-debug-" + ID)
  279. .removeClass("blue")
  280. .addClass("disabled");
  281. $("#ai-delete-" + ID)
  282. .removeClass("disabled")
  283. .addClass("blue");
  284. $("#ai-stop-" + ID)
  285. .removeClass("blue")
  286. .addClass("disabled");
  287. } else {
  288. $("#ai-debug-" + ID)
  289. .removeClass("blue")
  290. .addClass("disabled");
  291. $("#ai-stop-" + ID)
  292. .removeClass("blue")
  293. .addClass("disabled");
  294. }
  295. } else {
  296. $(".alert")
  297. .html(res.error_msg)
  298. .removeClass("alert-success")
  299. .addClass("alert-danger")
  300. .show()
  301. .delay(2000)
  302. .fadeOut();
  303. }
  304. },
  305. error: function (res) {
  306. console.log(res);
  307. },
  308. });
  309. }
  310. $(".ui.basic.ai_stop").click(function () {
  311. const ID = this.dataset.jobid;
  312. const repoPath = this.dataset.repopath;
  313. stopDebug(ID, repoPath);
  314. });
  315. function stopVersion(version_name, ID, repoPath) {
  316. const url = `/api/v1/repos/${repoPath}/${ID}/stop_version`;
  317. $.post(url, { version_name: version_name }, (data) => {
  318. if (data.StatusOK === 0) {
  319. $("#ai-stop-" + ID).removeClass("blue");
  320. $("#ai-stop-" + ID).addClass("disabled");
  321. refreshStatus(version_name, ID, repoPath);
  322. }
  323. }).fail(function (err) {
  324. console.log(err);
  325. });
  326. }
  327. $(".stop-show-version").click(function (e) {
  328. const ID = this.dataset.jobid;
  329. const repoPath = this.dataset.repopath;
  330. const version_name = this.dataset.version;
  331. const url = `/api/v1/repos/${repoPath}/${ID}/stop_version`;
  332. $.post(url, { version_name: version_name }, (data) => {
  333. if (data.StatusOK === 0) {
  334. $(`#${version_name}-stop`).removeClass("blue");
  335. $(`#${version_name}-stop`).addClass("disabled");
  336. refreshStatusShow(version_name, ID, repoPath);
  337. }
  338. }).fail(function (err) {
  339. console.log(err);
  340. });
  341. e.stopPropagation();
  342. });
  343. $("#refresh-status").click(function (e) {
  344. let version_name = $(this).data("version");
  345. let ID = $(`#accordion${version_name}`).data("jobid");
  346. let repoPath = $(`#accordion${version_name}`).data("repopath");
  347. refreshStatusShow(version_name, ID, repoPath);
  348. e.stopPropagation();
  349. });
  350. function refreshStatusShow(version_name, ID, repoPath) {
  351. $.get(
  352. `/api/v1/repos/${repoPath}/${ID}?version_name=${version_name}`,
  353. (data) => {
  354. //accroding下的状态
  355. $(`#${version_name}-status-span span`).text(data.JobStatus);
  356. //accroding下的状态图标
  357. $(`#${version_name}-status-span i`).attr("class", data.JobStatus);
  358. //accroding下的运行时长
  359. $(`#${version_name}-duration-span`).text(data.JobDuration);
  360. //配置信息详情页的状态
  361. $(`#${version_name}-status`).text(data.JobStatus);
  362. //配置信息详情页的状态
  363. $(`#${version_name}-duration`).text(data.JobDuration);
  364. }
  365. ).fail(function (err) {
  366. console.log(err);
  367. });
  368. }
  369. function refreshStatus(version_name, ID, repoPath) {
  370. const url = `/api/v1/repos/${repoPath}/${ID}/?version_name${version_name}`;
  371. $.get(url, (data) => {
  372. $(`#${ID}-icon`).attr("class", data.JobStatus);
  373. // detail status and duration
  374. $(`#${ID}-text`).text(data.JobStatus);
  375. if (
  376. [
  377. "STOPPED",
  378. "FAILED",
  379. "START_FAILED",
  380. "KILLED",
  381. "COMPLETED",
  382. "SUCCEEDED",
  383. "CREATE_FAILED",
  384. ].includes(data.JobStatus)
  385. ) {
  386. $("#ai-delete-" + ID)
  387. .removeClass("disabled")
  388. .addClass("blue");
  389. }
  390. }).fail(function (err) {
  391. console.log(err);
  392. });
  393. }
  394. $(".ui.basic.ai_stop_version").click(function () {
  395. const ID = this.dataset.jobid;
  396. const repoPath = this.dataset.repopath;
  397. const versionName = this.dataset.version;
  398. stopVersion(versionName, ID, repoPath);
  399. });
  400. function getModelInfo(repoPath, modelName, versionName, jobName) {
  401. $.get(
  402. `${repoPath}/modelmanage/show_model_info_api?name=${modelName}`,
  403. (data) => {
  404. if (data.length === 0) {
  405. $(`#${jobName}`).popup("toggle");
  406. } else {
  407. let versionData = data.filter((item) => {
  408. return item.Version === versionName;
  409. });
  410. if (versionData.length == 0) {
  411. $(`#${jobName}`).popup("toggle");
  412. } else {
  413. location.href = `${repoPath}/modelmanage/show_model_info?name=${modelName}`;
  414. }
  415. }
  416. }
  417. );
  418. }
  419. $(".goto_modelmanage").click(function () {
  420. const repoPath = this.dataset.repopath;
  421. const modelName = this.dataset.modelname;
  422. const versionName = this.dataset.version;
  423. const jobName = this.dataset.jobname;
  424. getModelInfo(repoPath, modelName, versionName, jobName);
  425. });
  426. function debugAgain(ID, debugUrl, redirect_to) {
  427. if ($("#" + ID + "-text").text() === "RUNNING") {
  428. window.open(debugUrl + "debug");
  429. } else {
  430. $.ajax({
  431. type: "POST",
  432. url: debugUrl + "restart?redirect_to=" + redirect_to,
  433. data: $("#debugAgainForm-" + ID).serialize(),
  434. success: function (res) {
  435. if (res["WechatRedirectUrl"]) {
  436. window.location.href = res["WechatRedirectUrl"];
  437. } else if (res.result_code === "0") {
  438. if (res.id !== ID) {
  439. location.reload();
  440. } else {
  441. $("#" + ID + "-icon")
  442. .removeClass()
  443. .addClass(res.status);
  444. $("#" + ID + "-text").text(res.status);
  445. $("#ai-debug-" + ID)
  446. .removeClass("blue")
  447. .addClass("disabled");
  448. $("#ai-delete-" + ID)
  449. .removeClass("blue")
  450. .addClass("disabled");
  451. $("#ai-debug-" + ID)
  452. .text(debug_button)
  453. .css("margin", "0 1rem");
  454. }
  455. } else {
  456. $(".alert")
  457. .html(res.error_msg)
  458. .removeClass("alert-success")
  459. .addClass("alert-danger")
  460. .show()
  461. .delay(2000)
  462. .fadeOut();
  463. }
  464. },
  465. error: function (res) {
  466. console.log(res);
  467. },
  468. });
  469. }
  470. }
  471. $(".ui.basic.ai_debug").click(function () {
  472. const ID = this.dataset.jobid;
  473. const repoPath = this.dataset.repopath;
  474. const redirect_to = this.dataset.linkpath;
  475. debugAgain(ID, repoPath, redirect_to);
  476. });
  477. function setWaitNums() {
  478. if ($(".cloudbrain-type").length === 0 && $(".gpu-type").length === 0) {
  479. return;
  480. }
  481. if (
  482. $(".cloudbrain-type").length !== 0 &&
  483. !$(".cloudbrain-type").data("queue")
  484. ) {
  485. return;
  486. }
  487. let waitNums = $(".cloudbrain-type").data("queue").split("map")[1];
  488. let test = new Map();
  489. let waitNumsArray = waitNums.split(" ");
  490. waitNumsArray.forEach((element, index) => {
  491. if (index === 0) {
  492. test.set(element.slice(1, -2), parseInt(element.slice(-1)));
  493. } else if (index === waitNumsArray.length - 1) {
  494. test.set(element.slice(0, -3), parseInt(element.slice(-2, -1)));
  495. } else {
  496. test.set(element.slice(0, -2), parseInt(element.slice(-1)));
  497. }
  498. });
  499. $(".ui.search.dropdown.gpu-type").dropdown({
  500. onChange: function (value, text, $selectedItem) {
  501. let gpuTypeNums = test.get(value);
  502. let gpuTypeNumString =
  503. $(".cloudbrain-type").data("queue-start") +
  504. " " +
  505. gpuTypeNums +
  506. " " +
  507. $(".cloudbrain-type").data("queue-end");
  508. $("#gpu-nums").text(gpuTypeNumString);
  509. },
  510. });
  511. }
  512. setWaitNums();
  513. }
  514. function userSearchControll() {
  515. if ($("#userCloud").length === 0) {
  516. return;
  517. }
  518. const params = new URLSearchParams(window.location.search);
  519. let jobType;
  520. if ($(".cloudbrain_debug").length === 1) {
  521. if (!params.get("jobType")) {
  522. jobType = $(".cloudbrain_debug").data("allTask");
  523. } else {
  524. if (params.get("jobType") === "DEBUG") {
  525. jobType = $(".cloudbrain_debug").data("debug-task");
  526. } else if (params.get("jobType") === "TRAIN") {
  527. jobType = $(".cloudbrain_debug").data("train-task");
  528. } else if (params.get("jobType") === "INFERENCE") {
  529. jobType = $(".cloudbrain_debug").data("inference-task");
  530. } else {
  531. jobType = $(".cloudbrain_debug").data("benchmark-task");
  532. }
  533. }
  534. }
  535. let listType = !params.get("listType")
  536. ? $(".cloudbrain_debug").data("all-compute")
  537. : params.get("listType");
  538. let jobStatus = !params.get("jobStatus")
  539. ? $(".cloudbrain_debug").data("all-status")
  540. : params.get("jobStatus").toUpperCase();
  541. const dropdownValueArray = [jobType, listType, jobStatus];
  542. $("#userCloud .default.text ").each(function (index, e) {
  543. $(e).text(dropdownValueArray[index]);
  544. });
  545. }
  546. function AdaminSearchControll() {
  547. if ($("#adminCloud").length === 0) {
  548. return;
  549. }
  550. const params = new URLSearchParams(window.location.search);
  551. let jobType = !params.get("jobType")
  552. ? $(".cloudbrain_debug").data("all-task")
  553. : params.get("jobType");
  554. let listType = !params.get("listType")
  555. ? $(".cloudbrain_debug").data("all-compute")
  556. : params.get("listType");
  557. let jobStatus = !params.get("jobStatus")
  558. ? $(".cloudbrain_debug").data("all-status")
  559. : params.get("jobStatus").toUpperCase();
  560. const dropdownValueArray = [jobType, listType, jobStatus];
  561. $("#adminCloud .default.text ").each(function (index, e) {
  562. $(e).text(dropdownValueArray[index]);
  563. });
  564. }
  565. userSearchControll();
  566. AdaminSearchControll();