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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. function refreshStatus(version_name, ID, repoPath) {
  328. const url = `/api/v1/repos/${repoPath}/${ID}/?version_name${version_name}`;
  329. $.get(url, (data) => {
  330. $(`#${ID}-icon`).attr("class", data.JobStatus);
  331. // detail status and duration
  332. $(`#${ID}-text`).text(data.JobStatus);
  333. if (
  334. [
  335. "STOPPED",
  336. "FAILED",
  337. "START_FAILED",
  338. "KILLED",
  339. "COMPLETED",
  340. "SUCCEEDED",
  341. "CREATE_FAILED",
  342. ].includes(data.JobStatus)
  343. ) {
  344. $("#ai-delete-" + ID)
  345. .removeClass("disabled")
  346. .addClass("blue");
  347. }
  348. }).fail(function (err) {
  349. console.log(err);
  350. });
  351. }
  352. $(".ui.basic.ai_stop_version").click(function () {
  353. const ID = this.dataset.jobid;
  354. const repoPath = this.dataset.repopath;
  355. const versionName = this.dataset.version;
  356. stopVersion(versionName, ID, repoPath);
  357. });
  358. function getModelInfo(repoPath, modelName, versionName, jobName) {
  359. $.get(
  360. `${repoPath}/modelmanage/show_model_info_api?name=${modelName}`,
  361. (data) => {
  362. if (data.length === 0) {
  363. $(`#${jobName}`).popup("toggle");
  364. } else {
  365. let versionData = data.filter((item) => {
  366. return item.Version === versionName;
  367. });
  368. if (versionData.length == 0) {
  369. $(`#${jobName}`).popup("toggle");
  370. } else {
  371. location.href = `${repoPath}/modelmanage/show_model_info?name=${modelName}`;
  372. }
  373. }
  374. }
  375. );
  376. }
  377. $(".goto_modelmanage").click(function () {
  378. const repoPath = this.dataset.repopath;
  379. const modelName = this.dataset.modelname;
  380. const versionName = this.dataset.version;
  381. const jobName = this.dataset.jobname;
  382. getModelInfo(repoPath, modelName, versionName, jobName);
  383. });
  384. function debugAgain(ID, debugUrl, redirect_to) {
  385. if ($("#" + ID + "-text").text() === "RUNNING") {
  386. window.open(debugUrl + "debug");
  387. } else {
  388. $.ajax({
  389. type: "POST",
  390. url: debugUrl + "restart?redirect_to=" + redirect_to,
  391. data: $("#debugAgainForm-" + ID).serialize(),
  392. success: function (res) {
  393. if (res["WechatRedirectUrl"]) {
  394. window.location.href = res["WechatRedirectUrl"];
  395. } else if (res.result_code === "0") {
  396. if (res.id !== ID) {
  397. location.reload();
  398. } else {
  399. $("#" + ID + "-icon")
  400. .removeClass()
  401. .addClass(res.status);
  402. $("#" + ID + "-text").text(res.status);
  403. $("#ai-debug-" + ID)
  404. .removeClass("blue")
  405. .addClass("disabled");
  406. $("#ai-delete-" + ID)
  407. .removeClass("blue")
  408. .addClass("disabled");
  409. $("#ai-debug-" + ID)
  410. .text(debug_button)
  411. .css("margin", "0 1rem");
  412. }
  413. } else {
  414. $(".alert")
  415. .html(res.error_msg)
  416. .removeClass("alert-success")
  417. .addClass("alert-danger")
  418. .show()
  419. .delay(2000)
  420. .fadeOut();
  421. }
  422. },
  423. error: function (res) {
  424. console.log(res);
  425. },
  426. });
  427. }
  428. }
  429. $(".ui.basic.ai_debug").click(function () {
  430. const ID = this.dataset.jobid;
  431. const repoPath = this.dataset.repopath;
  432. const redirect_to = this.dataset.linkpath;
  433. debugAgain(ID, repoPath, redirect_to);
  434. });
  435. function setWaitNums() {
  436. if ($(".cloudbrain-type").length === 0 && $(".gpu-type").length === 0) {
  437. return;
  438. }
  439. if (
  440. $(".cloudbrain-type").length !== 0 &&
  441. !$(".cloudbrain-type").data("queue")
  442. ) {
  443. return;
  444. }
  445. let waitNums = $(".cloudbrain-type").data("queue").split("map")[1];
  446. let test = new Map();
  447. let waitNumsArray = waitNums.split(" ");
  448. waitNumsArray.forEach((element, index) => {
  449. if (index === 0) {
  450. test.set(element.slice(1, -2), parseInt(element.slice(-1)));
  451. } else if (index === waitNumsArray.length - 1) {
  452. test.set(element.slice(0, -3), parseInt(element.slice(-2, -1)));
  453. } else {
  454. test.set(element.slice(0, -2), parseInt(element.slice(-1)));
  455. }
  456. });
  457. $(".ui.search.dropdown.gpu-type").dropdown({
  458. onChange: function (value, text, $selectedItem) {
  459. let gpuTypeNums = test.get(value);
  460. let gpuTypeNumString =
  461. $(".cloudbrain-type").data("queue-start") +
  462. " " +
  463. gpuTypeNums +
  464. " " +
  465. $(".cloudbrain-type").data("queue-end");
  466. $("#gpu-nums").text(gpuTypeNumString);
  467. },
  468. });
  469. }
  470. setWaitNums();
  471. }
  472. function userSearchControll() {
  473. if ($("#userCloud").length === 0) {
  474. return;
  475. }
  476. const params = new URLSearchParams(window.location.search);
  477. let cluster;
  478. if ($(".cloudbrain_debug").length === 1) {
  479. if (!params.get("cluster")) {
  480. cluster = $(".cloudbrain_debug").data("all-cluster");
  481. } else {
  482. if (params.get("cluster") === "resource_cluster_c2net") {
  483. cluster = $(".cloudbrain_debug").data("cluster-c2net");
  484. } else {
  485. cluster = $(".cloudbrain_debug").data("cluster-openi");
  486. }
  487. }
  488. }
  489. let jobType;
  490. if ($(".cloudbrain_debug").length === 1) {
  491. if (!params.get("jobType")) {
  492. jobType = $(".cloudbrain_debug").data("allTask");
  493. } else {
  494. if (params.get("jobType") === "DEBUG") {
  495. jobType = $(".cloudbrain_debug").data("debug-task");
  496. } else if (params.get("jobType") === "TRAIN") {
  497. jobType = $(".cloudbrain_debug").data("train-task");
  498. } else if (params.get("jobType") === "INFERENCE") {
  499. jobType = $(".cloudbrain_debug").data("inference-task");
  500. } else {
  501. jobType = $(".cloudbrain_debug").data("benchmark-task");
  502. }
  503. }
  504. }
  505. let aiCenter = !params.get("aiCenter")
  506. ? $(".cloudbrain_debug").data("all-aiCenter")
  507. : params.get("aiCenter");
  508. let listType = !params.get("listType")
  509. ? $(".cloudbrain_debug").data("all-compute")
  510. : params.get("listType");
  511. let jobStatus = !params.get("jobStatus")
  512. ? $(".cloudbrain_debug").data("all-status")
  513. : params.get("jobStatus").toUpperCase();
  514. const dropdownValueArray = [cluster, aiCenter, jobType, listType, jobStatus];
  515. $("#userCloud .default.text ").each(function (index, e) {
  516. $(e).text(dropdownValueArray[index]);
  517. });
  518. }
  519. function AdaminSearchControll() {
  520. if ($("#adminCloud").length === 0) {
  521. return;
  522. }
  523. const params = new URLSearchParams(window.location.search);
  524. let cluster;
  525. if ($(".cloudbrain_debug").length === 1) {
  526. if (!params.get("cluster")) {
  527. cluster = $(".cloudbrain_debug").data("all-cluster");
  528. } else {
  529. if (params.get("cluster") === "resource_cluster_c2net") {
  530. cluster = $(".cloudbrain_debug").data("cluster-c2net");
  531. } else {
  532. cluster = $(".cloudbrain_debug").data("cluster-openi");
  533. }
  534. }
  535. }
  536. let aiCenter = !params.get("aiCenter")
  537. ? $(".cloudbrain_debug").data("all-aiCenter")
  538. : params.get("aiCenter");
  539. let jobType = !params.get("jobType")
  540. ? $(".cloudbrain_debug").data("all-task")
  541. : params.get("jobType");
  542. let listType = !params.get("listType")
  543. ? $(".cloudbrain_debug").data("all-compute")
  544. : params.get("listType");
  545. let jobStatus = !params.get("jobStatus")
  546. ? $(".cloudbrain_debug").data("all-status")
  547. : params.get("jobStatus").toUpperCase();
  548. const dropdownValueArray = [cluster, aiCenter, jobType, listType, jobStatus];
  549. $("#adminCloud .default.text ").each(function (index, e) {
  550. $(e).text(dropdownValueArray[index]);
  551. });
  552. }
  553. userSearchControll();
  554. AdaminSearchControll();