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 19 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
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
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
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
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. export default async function initCloudrain() {
  2. function paddingZeros(str, len) {
  3. str = str.toString();
  4. if (str.length < len) {
  5. str = new Array(len - str.length).fill('0').join('') + str;
  6. }
  7. return str;
  8. }
  9. function timeFormat(date) {
  10. return `${date.getFullYear()}-${paddingZeros(date.getMonth() + 1, 2)}-${paddingZeros(date.getDate(), 2)} ${paddingZeros(date.getHours(), 2)}:${paddingZeros(date.getMinutes(), 2)}:${paddingZeros(date.getSeconds(), 2)}`;
  11. }
  12. let debug_button = $(".cloudbrain_debug").data("debug");
  13. let debug_again_button = $(".cloudbrain_debug").data("debug-again");
  14. let timeid = window.setInterval(loadJobStatus, 15000);
  15. let timeidShow = window.setInterval(loadShowJobStatus, 15000);
  16. $(document).ready(loadJobStatus);
  17. $(document).ready(loadShowJobStatus);
  18. function loadJobStatus() {
  19. $(".job-status").each((index, job) => {
  20. const ID = job.dataset.jobid;
  21. if (!ID) return;
  22. const repoPath = job.dataset.repopath;
  23. // const computeResource = job.dataset.resource
  24. const versionname = job.dataset.version;
  25. const bootfile = job.dataset.bootfile;
  26. console.log("bootfile---",bootfile)
  27. const status_text = $(`#${ID}-text`).text();
  28. const finalState = [
  29. "STOPPED",
  30. "CREATE_FAILED",
  31. "UNAVAILABLE",
  32. "DELETED",
  33. "RESIZE_FAILED",
  34. "SUCCEEDED",
  35. "IMAGE_FAILED",
  36. "SUBMIT_FAILED",
  37. "DELETE_FAILED",
  38. "KILLED",
  39. "COMPLETED",
  40. "FAILED",
  41. "CANCELED",
  42. "LOST",
  43. "START_FAILED",
  44. "SUBMIT_MODEL_FAILED",
  45. "DEPLOY_SERVICE_FAILED",
  46. "CHECK_FAILED",
  47. ];
  48. if (finalState.includes(status_text)) {
  49. return;
  50. }
  51. // const diffResource = computeResource == "NPU" ? 'modelarts/notebook' : 'cloudbrain'
  52. $.get(
  53. `/api/v1/repos/${repoPath}/${ID}?version_name=${versionname}`,
  54. (data) => {
  55. const ID = data.ID || data.JobID;
  56. const status = data.JobStatus;
  57. const duration = data.JobDuration;
  58. $("#duration-" + ID).text(duration);
  59. if (status != status_text) {
  60. $("#" + ID + "-icon")
  61. .removeClass()
  62. .addClass(status);
  63. $("#" + ID + "-text").text(status);
  64. finalState.includes(status) &&
  65. $("#" + ID + "-stop")
  66. .removeClass("blue")
  67. .addClass("disabled");
  68. }
  69. if (status === "RUNNING") {
  70. $("#ai-debug-" + ID)
  71. .removeClass("disabled")
  72. .addClass("blue")
  73. .text(debug_button)
  74. .css("margin", "0 1rem");
  75. $("#model-image-" + ID)
  76. .removeClass("disabled")
  77. .addClass("blue");
  78. }
  79. if (status !== "RUNNING") {
  80. // $('#model-debug-'+ID).removeClass('blue')
  81. // $('#model-debug-'+ID).addClass('disabled')
  82. $("#model-image-" + ID)
  83. .removeClass("blue")
  84. .addClass("disabled");
  85. }
  86. if (
  87. ["CREATING", "STOPPING", "WAITING", "STARTING"].includes(status)
  88. ) {
  89. $("#ai-debug-" + ID)
  90. .removeClass("blue")
  91. .addClass("disabled");
  92. }
  93. if (
  94. [
  95. "STOPPED",
  96. "FAILED",
  97. "START_FAILED",
  98. "CREATE_FAILED",
  99. "SUCCEEDED",
  100. ].includes(status)
  101. ) {
  102. if (!bootfile) {
  103. $("#ai-debug-" + ID)
  104. .removeClass("disabled")
  105. .addClass("blue")
  106. .text(debug_again_button)
  107. .css("margin", "0");
  108. } else {
  109. $("#ai-debug-" + ID).remove()
  110. }
  111. }
  112. if (["RUNNING", "WAITING"].includes(status)) {
  113. $("#ai-stop-" + ID)
  114. .removeClass("disabled")
  115. .addClass("blue");
  116. }
  117. if (
  118. [
  119. "CREATING",
  120. "STOPPING",
  121. "STARTING",
  122. "STOPPED",
  123. "FAILED",
  124. "START_FAILED",
  125. "SUCCEEDED",
  126. "COMPLETED",
  127. "CREATE_FAILED",
  128. ].includes(status)
  129. ) {
  130. $("#ai-stop-" + ID)
  131. .removeClass("blue")
  132. .addClass("disabled");
  133. }
  134. if (
  135. [
  136. "STOPPED",
  137. "FAILED",
  138. "START_FAILED",
  139. "KILLED",
  140. "COMPLETED",
  141. "SUCCEEDED",
  142. "CREATE_FAILED",
  143. ].includes(status)
  144. ) {
  145. $("#ai-delete-" + ID)
  146. .removeClass("disabled")
  147. .addClass("blue");
  148. } else {
  149. $("#ai-delete-" + ID)
  150. .removeClass("blue")
  151. .addClass("disabled");
  152. }
  153. }
  154. ).fail(function (err) {
  155. console.log(err);
  156. });
  157. });
  158. }
  159. function loadShowJobStatus() {
  160. $(".ui.accordion.border-according").each((index, job) => {
  161. const jobID = job.dataset.jobid;
  162. if (!jobID) return;
  163. const repoPath = job.dataset.repopath;
  164. const versionname = job.dataset.version;
  165. // ['IMAGE_FAILED','SUBMIT_FAILED','DELETE_FAILED','KILLED','COMPLETED','FAILED','CANCELED','LOST','START_FAILED']
  166. // if (job.textContent.trim() == 'IMAGE_FAILED' || job.textContent.trim() == 'SUBMIT_FAILED' || job.textContent.trim() == 'DELETE_FAILED'
  167. // || job.textContent.trim() == 'KILLED' || job.textContent.trim() == 'COMPLETED' || job.textContent.trim() == 'FAILED'
  168. // || job.textContent.trim() == 'CANCELED' || job.textContent.trim() == 'LOST') {
  169. // return
  170. // }
  171. let status = $(`#${versionname}-status-span`).text().trim();
  172. if (
  173. [
  174. "IMAGE_FAILED",
  175. "SUBMIT_FAILED",
  176. "DELETE_FAILED",
  177. "KILLED",
  178. "COMPLETED",
  179. "FAILED",
  180. "CANCELED",
  181. "LOST",
  182. "START_FAILED",
  183. "SUCCEEDED",
  184. "STOPPED",
  185. "CREATE_FAILED",
  186. ].includes(status)
  187. ) {
  188. return;
  189. }
  190. let stopArray = [
  191. "KILLED",
  192. "FAILED",
  193. "START_FAILED",
  194. "KILLING",
  195. "COMPLETED",
  196. "SUCCEEDED",
  197. "CREATE_FAILED",
  198. "STOPPED",
  199. ];
  200. let deleteArray = [
  201. "KILLED",
  202. "FAILED",
  203. "START_FAILED",
  204. "COMPLETED",
  205. "SUCCEEDED",
  206. "CREATE_FAILED",
  207. "STOPPED",
  208. ];
  209. $.get(
  210. `/api/v1/repos/${repoPath}/${jobID}?version_name=${versionname}`,
  211. (data) => {
  212. $(`#${versionname}-duration-span`).text(data.JobDuration);
  213. $(`#${versionname}-status-span span`).text(data.JobStatus);
  214. $(`#${versionname}-status-span i`).attr("class", data.JobStatus);
  215. // detail status and duration
  216. data.StartTime !== undefined && data.StartTime > 0 && $("#" + versionname + "-startTime").text(timeFormat(new Date(data.StartTime * 1000)));
  217. $("#" + versionname + "-duration").text(data.JobDuration);
  218. $("#" + versionname + "-status").text(data.JobStatus);
  219. $("#" + versionname + "-ai_center").text(data.AiCenter);
  220. if (stopArray.includes(data.JobStatus)) {
  221. $("#" + versionname + "-stop").addClass("disabled");
  222. }
  223. if (deleteArray.includes(data.JobStatus)) {
  224. $(`#${versionname}-delete`).removeClass("disabled");
  225. $(`#${versionname}-delete`).addClass("blue");
  226. }
  227. if (data.JobStatus === "COMPLETED") {
  228. $("#" + versionname + "-create-model")
  229. .removeClass("disabled")
  230. .addClass("blue");
  231. }
  232. }
  233. ).fail(function (err) {
  234. console.log(err);
  235. });
  236. });
  237. }
  238. function assertDelete(obj, versionName, repoPath) {
  239. if (obj.style.color == "rgb(204, 204, 204)") {
  240. return;
  241. } else {
  242. const delId = obj.parentNode.id;
  243. let flag = 1;
  244. $(".ui.basic.modal")
  245. .modal({
  246. onDeny: function () {
  247. flag = false;
  248. },
  249. onApprove: function () {
  250. if (!versionName) {
  251. document.getElementById(delId).submit();
  252. } else {
  253. deleteVersion(versionName, repoPath);
  254. }
  255. flag = true;
  256. },
  257. onHidden: function () {
  258. if (flag == false) {
  259. $(".alert")
  260. .html("您已取消操作")
  261. .removeClass("alert-success")
  262. .addClass("alert-danger")
  263. .show()
  264. .delay(1500)
  265. .fadeOut();
  266. }
  267. },
  268. })
  269. .modal("show");
  270. }
  271. }
  272. function deleteVersion(versionName, repoPath) {
  273. const url = `/api/v1/repos/${repoPath}`;
  274. $.post(url, { version_name: versionName }, (data) => {
  275. if (data.StatusOK === 0 || data.Code === 0) {
  276. location.reload();
  277. }
  278. }).fail(function (err) {
  279. console.log(err);
  280. });
  281. }
  282. $(".ui.basic.ai_delete").click(function () {
  283. const repoPath = this.dataset.repopath;
  284. const versionName = this.dataset.version;
  285. if (repoPath && versionName) {
  286. assertDelete(this, versionName, repoPath);
  287. } else {
  288. assertDelete(this);
  289. }
  290. });
  291. function stopDebug(ID, stopUrl,bootFile) {
  292. console.log("---------=-=-=-==--===")
  293. $.ajax({
  294. type: "POST",
  295. url: stopUrl,
  296. data: $("#stopForm-" + ID).serialize(),
  297. success: function (res) {
  298. if (res.result_code === "0") {
  299. $("#" + ID + "-icon")
  300. .removeClass()
  301. .addClass(res.status);
  302. $("#" + ID + "-text").text(res.status);
  303. if (res.status === "STOPPED") {
  304. if (!bootFile) {
  305. $("#ai-debug-" + ID)
  306. .removeClass("disabled")
  307. .addClass("blue")
  308. .text(debug_again_button)
  309. .css("margin", "0");
  310. } else {
  311. $("#ai-debug-" + ID).remove()
  312. }
  313. $("#ai-image-" + ID)
  314. .removeClass("blue")
  315. .addClass("disabled");
  316. $("#ai-model-debug-" + ID)
  317. .removeClass("blue")
  318. .addClass("disabled");
  319. $("#ai-delete-" + ID)
  320. .removeClass("disabled")
  321. .addClass("blue");
  322. $("#ai-stop-" + ID)
  323. .removeClass("blue")
  324. .addClass("disabled");
  325. } else {
  326. $("#ai-debug-" + ID)
  327. .removeClass("blue")
  328. .addClass("disabled");
  329. $("#ai-stop-" + ID)
  330. .removeClass("blue")
  331. .addClass("disabled");
  332. }
  333. } else {
  334. $(".alert")
  335. .html(res.error_msg)
  336. .removeClass("alert-success")
  337. .addClass("alert-danger")
  338. .show()
  339. .delay(2000)
  340. .fadeOut();
  341. }
  342. },
  343. error: function (res) {
  344. console.log(res);
  345. },
  346. });
  347. }
  348. $(".ui.basic.ai_stop").click(function () {
  349. const ID = this.dataset.jobid;
  350. const repoPath = this.dataset.repopath;
  351. const bootFile = this.dataset.bootfile
  352. stopDebug(ID, repoPath,bootFile);
  353. });
  354. function stopVersion(version_name, ID, repoPath) {
  355. const url = `/api/v1/repos/${repoPath}/${ID}/stop_version`;
  356. $.post(url, { version_name: version_name }, (data) => {
  357. if (data.StatusOK === 0) {
  358. $("#ai-stop-" + ID).removeClass("blue");
  359. $("#ai-stop-" + ID).addClass("disabled");
  360. refreshStatus(version_name, ID, repoPath);
  361. }
  362. }).fail(function (err) {
  363. console.log(err);
  364. });
  365. }
  366. function refreshStatus(version_name, ID, repoPath) {
  367. const url = `/api/v1/repos/${repoPath}/${ID}/?version_name${version_name}`;
  368. $.get(url, (data) => {
  369. $(`#${ID}-icon`).attr("class", data.JobStatus);
  370. // detail status and duration
  371. $(`#${ID}-text`).text(data.JobStatus);
  372. if (
  373. [
  374. "STOPPED",
  375. "FAILED",
  376. "START_FAILED",
  377. "KILLED",
  378. "COMPLETED",
  379. "SUCCEEDED",
  380. "CREATE_FAILED",
  381. ].includes(data.JobStatus)
  382. ) {
  383. $("#ai-delete-" + ID)
  384. .removeClass("disabled")
  385. .addClass("blue");
  386. }
  387. }).fail(function (err) {
  388. console.log(err);
  389. });
  390. }
  391. $(".ui.basic.ai_stop_version").click(function () {
  392. const ID = this.dataset.jobid;
  393. const repoPath = this.dataset.repopath;
  394. const versionName = this.dataset.version;
  395. stopVersion(versionName, ID, repoPath);
  396. });
  397. function getModelInfo(repoPath, modelName, versionName, jobName) {
  398. $.get(
  399. `${repoPath}/modelmanage/show_model_info_api?name=${modelName}`,
  400. (data) => {
  401. if (data.length === 0) {
  402. $(`#${jobName}`).popup("toggle");
  403. } else {
  404. let versionData = data.filter((item) => {
  405. return item.version === versionName;
  406. });
  407. if (versionData.length == 0) {
  408. $(`#${jobName}`).popup("toggle");
  409. } else {
  410. location.href = `${repoPath}/modelmanage/show_model_info?name=${modelName}`;
  411. }
  412. }
  413. }
  414. );
  415. }
  416. $(".goto_modelmanage").click(function () {
  417. const repoPath = this.dataset.repopath;
  418. const modelName = this.dataset.modelname;
  419. const versionName = this.dataset.version;
  420. const jobName = this.dataset.jobname;
  421. getModelInfo(repoPath, modelName, versionName, jobName);
  422. });
  423. function debugAgain(ID, debugUrl, redirect_to) {
  424. if ($("#" + ID + "-text").text() === "RUNNING") {
  425. window.open(debugUrl + "debug");
  426. } else {
  427. $.ajax({
  428. type: "POST",
  429. url: debugUrl + "restart?redirect_to=" + redirect_to,
  430. data: $("#debugAgainForm-" + ID).serialize(),
  431. success: function (res) {
  432. if (res["WechatRedirectUrl"]) {
  433. window.location.href = res["WechatRedirectUrl"];
  434. } else if (res.result_code === "0") {
  435. if (res.id !== ID) {
  436. location.reload();
  437. } else {
  438. $("#" + ID + "-icon")
  439. .removeClass()
  440. .addClass(res.status);
  441. $("#" + ID + "-text").text(res.status);
  442. $("#ai-debug-" + ID)
  443. .removeClass("blue")
  444. .addClass("disabled");
  445. $("#ai-delete-" + ID)
  446. .removeClass("blue")
  447. .addClass("disabled");
  448. $("#ai-debug-" + ID)
  449. .text(debug_button)
  450. .css("margin", "0 1rem");
  451. }
  452. } else {
  453. $(".ui.modal.debug-again-alert").modal("show");
  454. }
  455. },
  456. error: function (res) {
  457. console.log(res);
  458. },
  459. });
  460. }
  461. }
  462. $(".ui.basic.ai_debug").click(function () {
  463. const ID = this.dataset.jobid;
  464. const repoPath = this.dataset.repopath;
  465. const redirect_to = this.dataset.linkpath;
  466. debugAgain(ID, repoPath, redirect_to);
  467. });
  468. function setWaitNums() {
  469. if ($(".cloudbrain-type").length === 0 && $(".gpu-type").length === 0) {
  470. return;
  471. }
  472. if (
  473. $(".cloudbrain-type").length !== 0 &&
  474. !$(".cloudbrain-type").data("queue")
  475. ) {
  476. return;
  477. }
  478. let waitNums = $(".cloudbrain-type").data("queue").split("map")[1];
  479. let test = new Map();
  480. let waitNumsArray = waitNums.split(" ");
  481. waitNumsArray.forEach((element, index) => {
  482. if (index === 0) {
  483. test.set(element.slice(1, -2), parseInt(element.slice(-1)));
  484. } else if (index === waitNumsArray.length - 1) {
  485. test.set(element.slice(0, -3), parseInt(element.slice(-2, -1)));
  486. } else {
  487. test.set(element.slice(0, -2), parseInt(element.slice(-1)));
  488. }
  489. });
  490. $(".ui.search.dropdown.gpu-type").dropdown({
  491. onChange: function (value, text, $selectedItem) {
  492. let gpuTypeNums = test.get(value);
  493. let gpuTypeNumString =
  494. $(".cloudbrain-type").data("queue-start") +
  495. " " +
  496. gpuTypeNums +
  497. " " +
  498. $(".cloudbrain-type").data("queue-end");
  499. $("#gpu-nums").text(gpuTypeNumString);
  500. },
  501. });
  502. }
  503. setWaitNums();
  504. }
  505. function userSearchControll() {
  506. if ($("#userCloud").length === 0) {
  507. return;
  508. }
  509. const params = new URLSearchParams(window.location.search);
  510. let cluster;
  511. if ($(".cloudbrain_debug").length === 1) {
  512. if (!params.get("cluster")) {
  513. cluster = $(".cloudbrain_debug").data("all-cluster");
  514. } else {
  515. if (params.get("cluster") === "resource_cluster_c2net") {
  516. cluster = $(".cloudbrain_debug").data("cluster-c2net");
  517. } else {
  518. cluster = $(".cloudbrain_debug").data("cluster-openi");
  519. }
  520. }
  521. }
  522. let jobType;
  523. if ($(".cloudbrain_debug").length === 1) {
  524. if (!params.get("jobType")) {
  525. jobType = $(".cloudbrain_debug").data("allTask");
  526. } else {
  527. if (params.get("jobType") === "DEBUG") {
  528. jobType = $(".cloudbrain_debug").data("debug-task");
  529. } else if (params.get("jobType") === "TRAIN") {
  530. jobType = $(".cloudbrain_debug").data("train-task");
  531. } else if (params.get("jobType") === "INFERENCE") {
  532. jobType = $(".cloudbrain_debug").data("inference-task");
  533. } else {
  534. jobType = $(".cloudbrain_debug").data("benchmark-task");
  535. }
  536. }
  537. }
  538. let aiCenter = !params.get("aiCenter")
  539. ? $(".cloudbrain_debug").data("all-aiCenter")
  540. : params.get("aiCenter");
  541. let listType = !params.get("listType")
  542. ? $(".cloudbrain_debug").data("all-compute")
  543. : params.get("listType");
  544. let jobStatus = !params.get("jobStatus")
  545. ? $(".cloudbrain_debug").data("all-status")
  546. : params.get("jobStatus").toUpperCase();
  547. const dropdownValueArray = [cluster, aiCenter, jobType, listType, jobStatus];
  548. $("#userCloud .default.text ").each(function (index, e) {
  549. index != 1 && $(e).text(dropdownValueArray[index]);
  550. });
  551. }
  552. function AdaminSearchControll() {
  553. if ($("#adminCloud").length === 0) {
  554. return;
  555. }
  556. const params = new URLSearchParams(window.location.search);
  557. let cluster;
  558. if ($(".cloudbrain_debug").length === 1) {
  559. if (!params.get("cluster")) {
  560. cluster = $(".cloudbrain_debug").data("all-cluster");
  561. } else {
  562. if (params.get("cluster") === "resource_cluster_c2net") {
  563. cluster = $(".cloudbrain_debug").data("cluster-c2net");
  564. } else {
  565. cluster = $(".cloudbrain_debug").data("cluster-openi");
  566. }
  567. }
  568. }
  569. let aiCenter = !params.get("aiCenter")
  570. ? $(".cloudbrain_debug").data("all-aiCenter")
  571. : params.get("aiCenter");
  572. let jobType = !params.get("jobType")
  573. ? $(".cloudbrain_debug").data("all-task")
  574. : params.get("jobType");
  575. let listType = !params.get("listType")
  576. ? $(".cloudbrain_debug").data("all-compute")
  577. : params.get("listType");
  578. let jobStatus = !params.get("jobStatus")
  579. ? $(".cloudbrain_debug").data("all-status")
  580. : params.get("jobStatus").toUpperCase();
  581. const dropdownValueArray = [cluster, aiCenter, jobType, listType, jobStatus];
  582. $("#adminCloud .default.text ").each(function (index, e) {
  583. index != 1 && $(e).text(dropdownValueArray[index]);
  584. });
  585. }
  586. userSearchControll();
  587. AdaminSearchControll();
  588. $(".message .close").on("click", function () {
  589. $(this).closest(".message").transition("fade");
  590. });