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