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

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. ].includes(status)
  126. ) {
  127. $("#ai-delete-" + ID)
  128. .removeClass("disabled")
  129. .addClass("blue");
  130. } else {
  131. $("#ai-delete-" + ID)
  132. .removeClass("blue")
  133. .addClass("disabled");
  134. }
  135. }
  136. ).fail(function (err) {
  137. console.log(err);
  138. });
  139. });
  140. }
  141. function loadShowJobStatus() {
  142. $(".ui.accordion.border-according").each((index, job) => {
  143. const jobID = job.dataset.jobid;
  144. const repoPath = job.dataset.repopath;
  145. const versionname = job.dataset.version;
  146. // ['IMAGE_FAILED','SUBMIT_FAILED','DELETE_FAILED','KILLED','COMPLETED','FAILED','CANCELED','LOST','START_FAILED']
  147. // if (job.textContent.trim() == 'IMAGE_FAILED' || job.textContent.trim() == 'SUBMIT_FAILED' || job.textContent.trim() == 'DELETE_FAILED'
  148. // || job.textContent.trim() == 'KILLED' || job.textContent.trim() == 'COMPLETED' || job.textContent.trim() == 'FAILED'
  149. // || job.textContent.trim() == 'CANCELED' || job.textContent.trim() == 'LOST') {
  150. // return
  151. // }
  152. let status = $(`#${versionname}-status-span`).text();
  153. if (
  154. [
  155. "IMAGE_FAILED",
  156. "SUBMIT_FAILED",
  157. "DELETE_FAILED",
  158. "KILLED",
  159. "COMPLETED",
  160. "FAILED",
  161. "CANCELED",
  162. "LOST",
  163. "START_FAILED",
  164. "SUCCEEDED",
  165. "STOPPED",
  166. ].includes(status)
  167. ) {
  168. return;
  169. }
  170. let stopArray = [
  171. "KILLED",
  172. "FAILED",
  173. "START_FAILED",
  174. "KILLING",
  175. "COMPLETED",
  176. "SUCCEEDED",
  177. "STOPPED",
  178. ];
  179. $.get(
  180. `/api/v1/repos/${repoPath}/${jobID}?version_name=${versionname}`,
  181. (data) => {
  182. $(`#${versionname}-duration-span`).text(data.JobDuration);
  183. $(`#${versionname}-status-span span`).text(data.JobStatus);
  184. $(`#${versionname}-status-span i`).attr("class", data.JobStatus);
  185. // detail status and duration
  186. $("#" + versionname + "-duration").text(data.JobDuration);
  187. $("#" + versionname + "-status").text(data.JobStatus);
  188. if (stopArray.includes(data.JobStatus)) {
  189. $("#" + versionname + "-stop").addClass("disabled");
  190. }
  191. if (data.JobStatus === "COMPLETED") {
  192. $("#" + versionname + "-create-model")
  193. .removeClass("disabled")
  194. .addClass("blue");
  195. }
  196. }
  197. ).fail(function (err) {
  198. console.log(err);
  199. });
  200. });
  201. }
  202. function assertDelete(obj, versionName, repoPath) {
  203. if (obj.style.color == "rgb(204, 204, 204)") {
  204. return;
  205. } else {
  206. const delId = obj.parentNode.id;
  207. let flag = 1;
  208. $(".ui.basic.modal")
  209. .modal({
  210. onDeny: function () {
  211. flag = false;
  212. },
  213. onApprove: function () {
  214. if (!versionName) {
  215. console.log("-----");
  216. document.getElementById(delId).submit();
  217. } else {
  218. deleteVersion(versionName, repoPath);
  219. }
  220. flag = true;
  221. },
  222. onHidden: function () {
  223. if (flag == false) {
  224. $(".alert")
  225. .html("您已取消操作")
  226. .removeClass("alert-success")
  227. .addClass("alert-danger")
  228. .show()
  229. .delay(1500)
  230. .fadeOut();
  231. }
  232. },
  233. })
  234. .modal("show");
  235. }
  236. }
  237. function deleteVersion(versionName, repoPath) {
  238. const url = `/api/v1/repos/${repoPath}`;
  239. $.post(url, { version_name: versionName }, (data) => {
  240. if (data.StatusOK === 0 || data.Code === 0) {
  241. location.reload();
  242. }
  243. }).fail(function (err) {
  244. console.log(err);
  245. });
  246. }
  247. $(".ui.basic.ai_delete").click(function () {
  248. const repoPath = this.dataset.repopath;
  249. const versionName = this.dataset.version;
  250. console.log("----this", this, this.dataset.version);
  251. if (repoPath && versionName) {
  252. console.log("----this", this);
  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. $("#refresh-status").click(function (e) {
  328. let version_name = $(this).data("version");
  329. let ID = $(`#accordion${version_name}`).data("jobid");
  330. let repoPath = $(`#accordion${version_name}`).data("repopath");
  331. refreshStatusShow(version_name, ID, repoPath);
  332. e.stopPropagation();
  333. });
  334. function refreshStatusShow(version_name, ID, repoPath) {
  335. $.get(
  336. `/api/v1/repos/${repoPath}/${ID}?version_name=${version_name}`,
  337. (data) => {
  338. $(`#${version_name}-status-span span`).text(data.JobStatus);
  339. $(`#${version_name}-status-span i`).attr("class", data.JobStatus);
  340. $(`#${version_name}-duration-span`).text(data.JobDuration);
  341. $("#" + versionname + "-duration").text(data.JobDuration);
  342. $("#" + versionname + "-status").text(data.JobStatus);
  343. }
  344. ).fail(function (err) {
  345. console.log(err);
  346. });
  347. }
  348. function refreshStatus(version_name, ID, repoPath) {
  349. const url = `/api/v1/repos/${repoPath}/${ID}/?version_name${version_name}`;
  350. $.get(url, (data) => {
  351. $(`#${ID}-icon`).attr("class", data.JobStatus);
  352. // detail status and duration
  353. $(`#${ID}-text`).text(data.JobStatus);
  354. if (
  355. [
  356. "STOPPED",
  357. "FAILED",
  358. "START_FAILED",
  359. "KILLED",
  360. "COMPLETED",
  361. "SUCCEEDED",
  362. ].includes(data.JobStatus)
  363. ) {
  364. $("#ai-delete-" + ID)
  365. .removeClass("disabled")
  366. .addClass("blue");
  367. }
  368. }).fail(function (err) {
  369. console.log(err);
  370. });
  371. }
  372. $(".ui.basic.ai_stop_version").click(function () {
  373. const ID = this.dataset.jobid;
  374. const repoPath = this.dataset.repopath;
  375. const versionName = this.dataset.version;
  376. stopVersion(versionName, ID, repoPath);
  377. });
  378. function getModelInfo(repoPath, modelName, versionName, jobName) {
  379. $.get(
  380. `${repoPath}/modelmanage/show_model_info_api?name=${modelName}`,
  381. (data) => {
  382. if (data.length === 0) {
  383. $(`#${jobName}`).popup("toggle");
  384. } else {
  385. let versionData = data.filter((item) => {
  386. return item.Version === versionName;
  387. });
  388. if (versionData.length == 0) {
  389. $(`#${jobName}`).popup("toggle");
  390. } else {
  391. location.href = `${repoPath}/modelmanage/show_model_info?name=${modelName}`;
  392. }
  393. }
  394. }
  395. );
  396. }
  397. $(".goto_modelmanage").click(function () {
  398. const repoPath = this.dataset.repopath;
  399. const modelName = this.dataset.modelname;
  400. const versionName = this.dataset.version;
  401. const jobName = this.dataset.jobname;
  402. getModelInfo(repoPath, modelName, versionName, jobName);
  403. });
  404. function debugAgain(ID, debugUrl, redirect_to) {
  405. if ($("#" + ID + "-text").text() === "RUNNING") {
  406. window.open(debugUrl + "debug");
  407. } else {
  408. $.ajax({
  409. type: "POST",
  410. url: debugUrl + "restart?redirect_to=" + redirect_to,
  411. data: $("#debugAgainForm-" + ID).serialize(),
  412. success: function (res) {
  413. if (res["WechatRedirectUrl"]) {
  414. window.location.href = res["WechatRedirectUrl"];
  415. } else if (res.result_code === "0") {
  416. if (res.id !== ID) {
  417. location.reload();
  418. } else {
  419. $("#" + ID + "-icon")
  420. .removeClass()
  421. .addClass(res.status);
  422. $("#" + ID + "-text").text(res.status);
  423. $("#ai-debug-" + ID)
  424. .removeClass("blue")
  425. .addClass("disabled");
  426. $("#ai-delete-" + ID)
  427. .removeClass("blue")
  428. .addClass("disabled");
  429. $("#ai-debug-" + ID)
  430. .text(debug_button)
  431. .css("margin", "0 1rem");
  432. }
  433. } else {
  434. $(".alert")
  435. .html(res.error_msg)
  436. .removeClass("alert-success")
  437. .addClass("alert-danger")
  438. .show()
  439. .delay(2000)
  440. .fadeOut();
  441. }
  442. },
  443. error: function (res) {
  444. console.log(res);
  445. },
  446. });
  447. }
  448. }
  449. $(".ui.basic.ai_debug").click(function () {
  450. const ID = this.dataset.jobid;
  451. const repoPath = this.dataset.repopath;
  452. const redirect_to = this.dataset.linkpath;
  453. debugAgain(ID, repoPath, redirect_to);
  454. });
  455. function setWaitNums() {
  456. console.log($(".cloudbrain-type"));
  457. if ($(".cloudbrain-type").length === 0 && $(".gpu-type").length === 0) {
  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 jobType;
  493. if ($(".cloudbrain_debug").length === 1) {
  494. if (!params.get("jobType")) {
  495. jobType = $(".cloudbrain_debug").data("allTask");
  496. } else {
  497. if (params.get("jobType") === "DEBUG") {
  498. jobType = $(".cloudbrain_debug").data("debug-task");
  499. } else if (params.get("jobType") === "TRAIN") {
  500. jobType = $(".cloudbrain_debug").data("train-task");
  501. } else if (params.get("jobType") === "INFERENCE") {
  502. jobType = $(".cloudbrain_debug").data("inference-task");
  503. } else {
  504. jobType = $(".cloudbrain_debug").data("benchmark-task");
  505. }
  506. }
  507. }
  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 = [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 jobType = !params.get("jobType")
  525. ? $(".cloudbrain_debug").data("all-task")
  526. : params.get("jobType");
  527. let listType = !params.get("listType")
  528. ? $(".cloudbrain_debug").data("all-compute")
  529. : params.get("listType");
  530. let jobStatus = !params.get("jobStatus")
  531. ? $(".cloudbrain_debug").data("all-status")
  532. : params.get("jobStatus").toUpperCase();
  533. const dropdownValueArray = [jobType, listType, jobStatus];
  534. $("#adminCloud .default.text ").each(function (index, e) {
  535. $(e).text(dropdownValueArray[index]);
  536. });
  537. }
  538. userSearchControll();
  539. AdaminSearchControll();