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