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

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