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