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