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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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. let deleteArray = [
  183. "KILLED",
  184. "FAILED",
  185. "START_FAILED",
  186. "COMPLETED",
  187. "SUCCEEDED",
  188. "CREATE_FAILED",
  189. "STOPPED",
  190. ];
  191. $.get(
  192. `/api/v1/repos/${repoPath}/${jobID}?version_name=${versionname}`,
  193. (data) => {
  194. $(`#${versionname}-duration-span`).text(data.JobDuration);
  195. $(`#${versionname}-status-span span`).text(data.JobStatus);
  196. $(`#${versionname}-status-span i`).attr("class", data.JobStatus);
  197. // detail status and duration
  198. $("#" + versionname + "-duration").text(data.JobDuration);
  199. $("#" + versionname + "-status").text(data.JobStatus);
  200. if (stopArray.includes(data.JobStatus)) {
  201. $("#" + versionname + "-stop").addClass("disabled");
  202. }
  203. if (deleteArray.includes(data.JobStatus)) {
  204. $(`#${versionname}-delete`).removeClass("disabled");
  205. $(`#${versionname}-delete`).addClass("blue");
  206. }
  207. if (data.JobStatus === "COMPLETED") {
  208. $("#" + versionname + "-create-model")
  209. .removeClass("disabled")
  210. .addClass("blue");
  211. }
  212. }
  213. ).fail(function (err) {
  214. console.log(err);
  215. });
  216. });
  217. }
  218. function assertDelete(obj, versionName, repoPath) {
  219. if (obj.style.color == "rgb(204, 204, 204)") {
  220. return;
  221. } else {
  222. const delId = obj.parentNode.id;
  223. let flag = 1;
  224. $(".ui.basic.modal")
  225. .modal({
  226. onDeny: function () {
  227. flag = false;
  228. },
  229. onApprove: function () {
  230. if (!versionName) {
  231. document.getElementById(delId).submit();
  232. } else {
  233. deleteVersion(versionName, repoPath);
  234. }
  235. flag = true;
  236. },
  237. onHidden: function () {
  238. if (flag == false) {
  239. $(".alert")
  240. .html("您已取消操作")
  241. .removeClass("alert-success")
  242. .addClass("alert-danger")
  243. .show()
  244. .delay(1500)
  245. .fadeOut();
  246. }
  247. },
  248. })
  249. .modal("show");
  250. }
  251. }
  252. function deleteVersion(versionName, repoPath) {
  253. const url = `/api/v1/repos/${repoPath}`;
  254. $.post(url, { version_name: versionName }, (data) => {
  255. if (data.StatusOK === 0 || data.Code === 0) {
  256. location.reload();
  257. }
  258. }).fail(function (err) {
  259. console.log(err);
  260. });
  261. }
  262. $(".ui.basic.ai_delete").click(function () {
  263. const repoPath = this.dataset.repopath;
  264. const versionName = this.dataset.version;
  265. if (repoPath && versionName) {
  266. assertDelete(this, versionName, repoPath);
  267. } else {
  268. assertDelete(this);
  269. }
  270. });
  271. function stopDebug(ID, stopUrl) {
  272. $.ajax({
  273. type: "POST",
  274. url: stopUrl,
  275. data: $("#stopForm-" + ID).serialize(),
  276. success: function (res) {
  277. if (res.result_code === "0") {
  278. $("#" + ID + "-icon")
  279. .removeClass()
  280. .addClass(res.status);
  281. $("#" + ID + "-text").text(res.status);
  282. if (res.status === "STOPPED") {
  283. $("#ai-debug-" + ID)
  284. .removeClass("disabled")
  285. .addClass("blue")
  286. .text(debug_again_button)
  287. .css("margin", "0");
  288. $("#ai-image-" + ID)
  289. .removeClass("blue")
  290. .addClass("disabled");
  291. $("#ai-model-debug-" + ID)
  292. .removeClass("blue")
  293. .addClass("disabled");
  294. $("#ai-delete-" + ID)
  295. .removeClass("disabled")
  296. .addClass("blue");
  297. $("#ai-stop-" + ID)
  298. .removeClass("blue")
  299. .addClass("disabled");
  300. } else {
  301. $("#ai-debug-" + ID)
  302. .removeClass("blue")
  303. .addClass("disabled");
  304. $("#ai-stop-" + ID)
  305. .removeClass("blue")
  306. .addClass("disabled");
  307. }
  308. } else {
  309. $(".alert")
  310. .html(res.error_msg)
  311. .removeClass("alert-success")
  312. .addClass("alert-danger")
  313. .show()
  314. .delay(2000)
  315. .fadeOut();
  316. }
  317. },
  318. error: function (res) {
  319. console.log(res);
  320. },
  321. });
  322. }
  323. $(".ui.basic.ai_stop").click(function () {
  324. const ID = this.dataset.jobid;
  325. const repoPath = this.dataset.repopath;
  326. stopDebug(ID, repoPath);
  327. });
  328. function stopVersion(version_name, ID, repoPath) {
  329. const url = `/api/v1/repos/${repoPath}/${ID}/stop_version`;
  330. $.post(url, { version_name: version_name }, (data) => {
  331. if (data.StatusOK === 0) {
  332. $("#ai-stop-" + ID).removeClass("blue");
  333. $("#ai-stop-" + ID).addClass("disabled");
  334. refreshStatus(version_name, ID, repoPath);
  335. }
  336. }).fail(function (err) {
  337. console.log(err);
  338. });
  339. }
  340. function refreshStatus(version_name, ID, repoPath) {
  341. const url = `/api/v1/repos/${repoPath}/${ID}/?version_name${version_name}`;
  342. $.get(url, (data) => {
  343. $(`#${ID}-icon`).attr("class", data.JobStatus);
  344. // detail status and duration
  345. $(`#${ID}-text`).text(data.JobStatus);
  346. if (
  347. [
  348. "STOPPED",
  349. "FAILED",
  350. "START_FAILED",
  351. "KILLED",
  352. "COMPLETED",
  353. "SUCCEEDED",
  354. "CREATE_FAILED",
  355. ].includes(data.JobStatus)
  356. ) {
  357. $("#ai-delete-" + ID)
  358. .removeClass("disabled")
  359. .addClass("blue");
  360. }
  361. }).fail(function (err) {
  362. console.log(err);
  363. });
  364. }
  365. $(".ui.basic.ai_stop_version").click(function () {
  366. const ID = this.dataset.jobid;
  367. const repoPath = this.dataset.repopath;
  368. const versionName = this.dataset.version;
  369. stopVersion(versionName, ID, repoPath);
  370. });
  371. function getModelInfo(repoPath, modelName, versionName, jobName) {
  372. $.get(
  373. `${repoPath}/modelmanage/show_model_info_api?name=${modelName}`,
  374. (data) => {
  375. if (data.length === 0) {
  376. $(`#${jobName}`).popup("toggle");
  377. } else {
  378. let versionData = data.filter((item) => {
  379. return item.Version === versionName;
  380. });
  381. if (versionData.length == 0) {
  382. $(`#${jobName}`).popup("toggle");
  383. } else {
  384. location.href = `${repoPath}/modelmanage/show_model_info?name=${modelName}`;
  385. }
  386. }
  387. }
  388. );
  389. }
  390. $(".goto_modelmanage").click(function () {
  391. const repoPath = this.dataset.repopath;
  392. const modelName = this.dataset.modelname;
  393. const versionName = this.dataset.version;
  394. const jobName = this.dataset.jobname;
  395. getModelInfo(repoPath, modelName, versionName, jobName);
  396. });
  397. function debugAgain(ID, debugUrl, redirect_to) {
  398. if ($("#" + ID + "-text").text() === "RUNNING") {
  399. window.open(debugUrl + "debug");
  400. } else {
  401. $.ajax({
  402. type: "POST",
  403. url: debugUrl + "restart?redirect_to=" + redirect_to,
  404. data: $("#debugAgainForm-" + ID).serialize(),
  405. success: function (res) {
  406. if (res["WechatRedirectUrl"]) {
  407. window.location.href = res["WechatRedirectUrl"];
  408. } else if (res.result_code === "0") {
  409. if (res.id !== ID) {
  410. location.reload();
  411. } else {
  412. $("#" + ID + "-icon")
  413. .removeClass()
  414. .addClass(res.status);
  415. $("#" + ID + "-text").text(res.status);
  416. $("#ai-debug-" + ID)
  417. .removeClass("blue")
  418. .addClass("disabled");
  419. $("#ai-delete-" + ID)
  420. .removeClass("blue")
  421. .addClass("disabled");
  422. $("#ai-debug-" + ID)
  423. .text(debug_button)
  424. .css("margin", "0 1rem");
  425. }
  426. } else {
  427. $(".alert")
  428. .html(res.error_msg)
  429. .removeClass("alert-success")
  430. .addClass("alert-danger")
  431. .show()
  432. .delay(2000)
  433. .fadeOut();
  434. }
  435. },
  436. error: function (res) {
  437. console.log(res);
  438. },
  439. });
  440. }
  441. }
  442. $(".ui.basic.ai_debug").click(function () {
  443. const ID = this.dataset.jobid;
  444. const repoPath = this.dataset.repopath;
  445. const redirect_to = this.dataset.linkpath;
  446. debugAgain(ID, repoPath, redirect_to);
  447. });
  448. function setWaitNums() {
  449. if ($(".cloudbrain-type").length === 0 && $(".gpu-type").length === 0) {
  450. return;
  451. }
  452. if (
  453. $(".cloudbrain-type").length !== 0 &&
  454. !$(".cloudbrain-type").data("queue")
  455. ) {
  456. return;
  457. }
  458. let waitNums = $(".cloudbrain-type").data("queue").split("map")[1];
  459. let test = new Map();
  460. let waitNumsArray = waitNums.split(" ");
  461. waitNumsArray.forEach((element, index) => {
  462. if (index === 0) {
  463. test.set(element.slice(1, -2), parseInt(element.slice(-1)));
  464. } else if (index === waitNumsArray.length - 1) {
  465. test.set(element.slice(0, -3), parseInt(element.slice(-2, -1)));
  466. } else {
  467. test.set(element.slice(0, -2), parseInt(element.slice(-1)));
  468. }
  469. });
  470. $(".ui.search.dropdown.gpu-type").dropdown({
  471. onChange: function (value, text, $selectedItem) {
  472. let gpuTypeNums = test.get(value);
  473. let gpuTypeNumString =
  474. $(".cloudbrain-type").data("queue-start") +
  475. " " +
  476. gpuTypeNums +
  477. " " +
  478. $(".cloudbrain-type").data("queue-end");
  479. $("#gpu-nums").text(gpuTypeNumString);
  480. },
  481. });
  482. }
  483. setWaitNums();
  484. }
  485. function userSearchControll() {
  486. if ($("#userCloud").length === 0) {
  487. return;
  488. }
  489. const params = new URLSearchParams(window.location.search);
  490. let cluster;
  491. if ($(".cloudbrain_debug").length === 1) {
  492. if (!params.get("cluster")) {
  493. cluster = $(".cloudbrain_debug").data("all-cluster");
  494. } else {
  495. if (params.get("cluster") === "resource_cluster_c2net") {
  496. cluster = $(".cloudbrain_debug").data("cluster-c2net");
  497. } else {
  498. cluster = $(".cloudbrain_debug").data("cluster-openi");
  499. }
  500. }
  501. }
  502. let jobType;
  503. if ($(".cloudbrain_debug").length === 1) {
  504. if (!params.get("jobType")) {
  505. jobType = $(".cloudbrain_debug").data("allTask");
  506. } else {
  507. if (params.get("jobType") === "DEBUG") {
  508. jobType = $(".cloudbrain_debug").data("debug-task");
  509. } else if (params.get("jobType") === "TRAIN") {
  510. jobType = $(".cloudbrain_debug").data("train-task");
  511. } else if (params.get("jobType") === "INFERENCE") {
  512. jobType = $(".cloudbrain_debug").data("inference-task");
  513. } else {
  514. jobType = $(".cloudbrain_debug").data("benchmark-task");
  515. }
  516. }
  517. }
  518. let aiCenter = !params.get("aiCenter")
  519. ? $(".cloudbrain_debug").data("all-aiCenter")
  520. : params.get("aiCenter");
  521. let listType = !params.get("listType")
  522. ? $(".cloudbrain_debug").data("all-compute")
  523. : params.get("listType");
  524. let jobStatus = !params.get("jobStatus")
  525. ? $(".cloudbrain_debug").data("all-status")
  526. : params.get("jobStatus").toUpperCase();
  527. const dropdownValueArray = [cluster, aiCenter, jobType, listType, jobStatus];
  528. $("#userCloud .default.text ").each(function (index, e) {
  529. $(e).text(dropdownValueArray[index]);
  530. });
  531. }
  532. function AdaminSearchControll() {
  533. if ($("#adminCloud").length === 0) {
  534. return;
  535. }
  536. const params = new URLSearchParams(window.location.search);
  537. let cluster;
  538. if ($(".cloudbrain_debug").length === 1) {
  539. if (!params.get("cluster")) {
  540. cluster = $(".cloudbrain_debug").data("all-cluster");
  541. } else {
  542. if (params.get("cluster") === "resource_cluster_c2net") {
  543. cluster = $(".cloudbrain_debug").data("cluster-c2net");
  544. } else {
  545. cluster = $(".cloudbrain_debug").data("cluster-openi");
  546. }
  547. }
  548. }
  549. let aiCenter = !params.get("aiCenter")
  550. ? $(".cloudbrain_debug").data("all-aiCenter")
  551. : params.get("aiCenter");
  552. let jobType = !params.get("jobType")
  553. ? $(".cloudbrain_debug").data("all-task")
  554. : params.get("jobType");
  555. let listType = !params.get("listType")
  556. ? $(".cloudbrain_debug").data("all-compute")
  557. : params.get("listType");
  558. let jobStatus = !params.get("jobStatus")
  559. ? $(".cloudbrain_debug").data("all-status")
  560. : params.get("jobStatus").toUpperCase();
  561. const dropdownValueArray = [cluster, aiCenter, jobType, listType, jobStatus];
  562. $("#adminCloud .default.text ").each(function (index, e) {
  563. $(e).text(dropdownValueArray[index]);
  564. });
  565. }
  566. userSearchControll();
  567. AdaminSearchControll();