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