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