|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- export default async function initCloudrain() {
- let debug_button = $(".cloudbrain_debug").data("debug");
- let debug_again_button = $(".cloudbrain_debug").data("debug-again");
- let timeid = window.setInterval(loadJobStatus, 15000);
- let timeidShow = window.setInterval(loadShowJobStatus, 15000);
- $(document).ready(loadJobStatus);
- $(document).ready(loadShowJobStatus);
- function loadJobStatus() {
- $(".job-status").each((index, job) => {
- const ID = job.dataset.jobid;
- const repoPath = job.dataset.repopath;
- // const computeResource = job.dataset.resource
- const versionname = job.dataset.version;
- const status_text = $(`#${ID}-text`).text();
- const finalState = [
- "STOPPED",
- "CREATE_FAILED",
- "UNAVAILABLE",
- "DELETED",
- "RESIZE_FAILED",
- "SUCCEEDED",
- "IMAGE_FAILED",
- "SUBMIT_FAILED",
- "DELETE_FAILED",
- "KILLED",
- "COMPLETED",
- "FAILED",
- "CANCELED",
- "LOST",
- "START_FAILED",
- "SUBMIT_MODEL_FAILED",
- "DEPLOY_SERVICE_FAILED",
- "CHECK_FAILED",
- ];
- if (finalState.includes(status_text)) {
- return;
- }
- // const diffResource = computeResource == "NPU" ? 'modelarts/notebook' : 'cloudbrain'
- $.get(
- `/api/v1/repos/${repoPath}/${ID}?version_name=${versionname}`,
- (data) => {
- const ID = data.ID || data.JobID;
- const status = data.JobStatus;
- const duration = data.JobDuration;
- $("#duration-" + ID).text(duration);
- if (status != status_text) {
- $("#" + ID + "-icon")
- .removeClass()
- .addClass(status);
- $("#" + ID + "-text").text(status);
- finalState.includes(status) &&
- $("#" + ID + "-stop")
- .removeClass("blue")
- .addClass("disabled");
- }
- if (status === "RUNNING") {
- $("#ai-debug-" + ID)
- .removeClass("disabled")
- .addClass("blue")
- .text(debug_button)
- .css("margin", "0 1rem");
- $("#model-image-" + ID)
- .removeClass("disabled")
- .addClass("blue");
- }
- if (status !== "RUNNING") {
- // $('#model-debug-'+ID).removeClass('blue')
- // $('#model-debug-'+ID).addClass('disabled')
- $("#model-image-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- }
- if (
- ["CREATING", "STOPPING", "WAITING", "STARTING"].includes(status)
- ) {
- $("#ai-debug-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- }
- if (
- [
- "STOPPED",
- "FAILED",
- "START_FAILED",
- "CREATE_FAILED",
- "SUCCEEDED",
- ].includes(status)
- ) {
- $("#ai-debug-" + ID)
- .removeClass("disabled")
- .addClass("blue")
- .text(debug_again_button)
- .css("margin", "0");
- }
- if (["RUNNING", "WAITING"].includes(status)) {
- $("#ai-stop-" + ID)
- .removeClass("disabled")
- .addClass("blue");
- }
- if (
- [
- "CREATING",
- "STOPPING",
- "STARTING",
- "STOPPED",
- "FAILED",
- "START_FAILED",
- "SUCCEEDED",
- "COMPLETED",
- "CREATE_FAILED",
- ].includes(status)
- ) {
- $("#ai-stop-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- }
-
- if (
- [
- "STOPPED",
- "FAILED",
- "START_FAILED",
- "KILLED",
- "COMPLETED",
- "SUCCEEDED",
- "CREATE_FAILED",
- ].includes(status)
- ) {
- $("#ai-delete-" + ID)
- .removeClass("disabled")
- .addClass("blue");
- } else {
- $("#ai-delete-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- }
- }
- ).fail(function (err) {
- console.log(err);
- });
- });
- }
-
- function loadShowJobStatus() {
- $(".ui.accordion.border-according").each((index, job) => {
- const jobID = job.dataset.jobid;
- const repoPath = job.dataset.repopath;
- const versionname = job.dataset.version;
- // ['IMAGE_FAILED','SUBMIT_FAILED','DELETE_FAILED','KILLED','COMPLETED','FAILED','CANCELED','LOST','START_FAILED']
- // if (job.textContent.trim() == 'IMAGE_FAILED' || job.textContent.trim() == 'SUBMIT_FAILED' || job.textContent.trim() == 'DELETE_FAILED'
- // || job.textContent.trim() == 'KILLED' || job.textContent.trim() == 'COMPLETED' || job.textContent.trim() == 'FAILED'
- // || job.textContent.trim() == 'CANCELED' || job.textContent.trim() == 'LOST') {
- // return
- // }
- let status = $(`#${versionname}-status-span`).text();
-
- if (
- [
- "IMAGE_FAILED",
- "SUBMIT_FAILED",
- "DELETE_FAILED",
- "KILLED",
- "COMPLETED",
- "FAILED",
- "CANCELED",
- "LOST",
- "START_FAILED",
- "SUCCEEDED",
- "STOPPED",
- "CREATE_FAILED",
- ].includes(status)
- ) {
- return;
- }
- let stopArray = [
- "KILLED",
- "FAILED",
- "START_FAILED",
- "KILLING",
- "COMPLETED",
- "SUCCEEDED",
- "CREATE_FAILED",
- "STOPPED",
- ];
- $.get(
- `/api/v1/repos/${repoPath}/${jobID}?version_name=${versionname}`,
- (data) => {
- $(`#${versionname}-duration-span`).text(data.JobDuration);
- $(`#${versionname}-status-span span`).text(data.JobStatus);
- $(`#${versionname}-status-span i`).attr("class", data.JobStatus);
- // detail status and duration
- $("#" + versionname + "-duration").text(data.JobDuration);
- $("#" + versionname + "-status").text(data.JobStatus);
- if (stopArray.includes(data.JobStatus)) {
- $("#" + versionname + "-stop").addClass("disabled");
- }
- if (data.JobStatus === "COMPLETED") {
- $("#" + versionname + "-create-model")
- .removeClass("disabled")
- .addClass("blue");
- }
- }
- ).fail(function (err) {
- console.log(err);
- });
- });
- }
-
- function assertDelete(obj, versionName, repoPath) {
- if (obj.style.color == "rgb(204, 204, 204)") {
- return;
- } else {
- const delId = obj.parentNode.id;
- let flag = 1;
- $(".ui.basic.modal")
- .modal({
- onDeny: function () {
- flag = false;
- },
- onApprove: function () {
- if (!versionName) {
- document.getElementById(delId).submit();
- } else {
- deleteVersion(versionName, repoPath);
- }
- flag = true;
- },
- onHidden: function () {
- if (flag == false) {
- $(".alert")
- .html("您已取消操作")
- .removeClass("alert-success")
- .addClass("alert-danger")
- .show()
- .delay(1500)
- .fadeOut();
- }
- },
- })
- .modal("show");
- }
- }
- function deleteVersion(versionName, repoPath) {
- const url = `/api/v1/repos/${repoPath}`;
- $.post(url, { version_name: versionName }, (data) => {
- if (data.StatusOK === 0 || data.Code === 0) {
- location.reload();
- }
- }).fail(function (err) {
- console.log(err);
- });
- }
- $(".ui.basic.ai_delete").click(function () {
- const repoPath = this.dataset.repopath;
- const versionName = this.dataset.version;
- if (repoPath && versionName) {
- assertDelete(this, versionName, repoPath);
- } else {
- assertDelete(this);
- }
- });
- function stopDebug(ID, stopUrl) {
- $.ajax({
- type: "POST",
- url: stopUrl,
- data: $("#stopForm-" + ID).serialize(),
- success: function (res) {
- if (res.result_code === "0") {
- $("#" + ID + "-icon")
- .removeClass()
- .addClass(res.status);
- $("#" + ID + "-text").text(res.status);
- if (res.status === "STOPPED") {
- $("#ai-debug-" + ID)
- .removeClass("disabled")
- .addClass("blue")
- .text(debug_again_button)
- .css("margin", "0");
- $("#ai-image-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- $("#ai-model-debug-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- $("#ai-delete-" + ID)
- .removeClass("disabled")
- .addClass("blue");
- $("#ai-stop-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- } else {
- $("#ai-debug-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- $("#ai-stop-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- }
- } else {
- $(".alert")
- .html(res.error_msg)
- .removeClass("alert-success")
- .addClass("alert-danger")
- .show()
- .delay(2000)
- .fadeOut();
- }
- },
- error: function (res) {
- console.log(res);
- },
- });
- }
- $(".ui.basic.ai_stop").click(function () {
- const ID = this.dataset.jobid;
- const repoPath = this.dataset.repopath;
- stopDebug(ID, repoPath);
- });
-
- function stopVersion(version_name, ID, repoPath) {
- const url = `/api/v1/repos/${repoPath}/${ID}/stop_version`;
- $.post(url, { version_name: version_name }, (data) => {
- if (data.StatusOK === 0) {
- $("#ai-stop-" + ID).removeClass("blue");
- $("#ai-stop-" + ID).addClass("disabled");
- refreshStatus(version_name, ID, repoPath);
- }
- }).fail(function (err) {
- console.log(err);
- });
- }
- function refreshStatus(version_name, ID, repoPath) {
- const url = `/api/v1/repos/${repoPath}/${ID}/?version_name${version_name}`;
- $.get(url, (data) => {
- $(`#${ID}-icon`).attr("class", data.JobStatus);
- // detail status and duration
- $(`#${ID}-text`).text(data.JobStatus);
- if (
- [
- "STOPPED",
- "FAILED",
- "START_FAILED",
- "KILLED",
- "COMPLETED",
- "SUCCEEDED",
- "CREATE_FAILED",
- ].includes(data.JobStatus)
- ) {
- $("#ai-delete-" + ID)
- .removeClass("disabled")
- .addClass("blue");
- }
- }).fail(function (err) {
- console.log(err);
- });
- }
- $(".ui.basic.ai_stop_version").click(function () {
- const ID = this.dataset.jobid;
- const repoPath = this.dataset.repopath;
- const versionName = this.dataset.version;
- stopVersion(versionName, ID, repoPath);
- });
- function getModelInfo(repoPath, modelName, versionName, jobName) {
- $.get(
- `${repoPath}/modelmanage/show_model_info_api?name=${modelName}`,
- (data) => {
- if (data.length === 0) {
- $(`#${jobName}`).popup("toggle");
- } else {
- let versionData = data.filter((item) => {
- return item.Version === versionName;
- });
- if (versionData.length == 0) {
- $(`#${jobName}`).popup("toggle");
- } else {
- location.href = `${repoPath}/modelmanage/show_model_info?name=${modelName}`;
- }
- }
- }
- );
- }
- $(".goto_modelmanage").click(function () {
- const repoPath = this.dataset.repopath;
- const modelName = this.dataset.modelname;
- const versionName = this.dataset.version;
- const jobName = this.dataset.jobname;
- getModelInfo(repoPath, modelName, versionName, jobName);
- });
- function debugAgain(ID, debugUrl, redirect_to) {
- if ($("#" + ID + "-text").text() === "RUNNING") {
- window.open(debugUrl + "debug");
- } else {
- $.ajax({
- type: "POST",
- url: debugUrl + "restart?redirect_to=" + redirect_to,
- data: $("#debugAgainForm-" + ID).serialize(),
- success: function (res) {
- if (res["WechatRedirectUrl"]) {
- window.location.href = res["WechatRedirectUrl"];
- } else if (res.result_code === "0") {
- if (res.id !== ID) {
- location.reload();
- } else {
- $("#" + ID + "-icon")
- .removeClass()
- .addClass(res.status);
- $("#" + ID + "-text").text(res.status);
- $("#ai-debug-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- $("#ai-delete-" + ID)
- .removeClass("blue")
- .addClass("disabled");
- $("#ai-debug-" + ID)
- .text(debug_button)
- .css("margin", "0 1rem");
- }
- } else {
- $(".alert")
- .html(res.error_msg)
- .removeClass("alert-success")
- .addClass("alert-danger")
- .show()
- .delay(2000)
- .fadeOut();
- }
- },
- error: function (res) {
- console.log(res);
- },
- });
- }
- }
- $(".ui.basic.ai_debug").click(function () {
- const ID = this.dataset.jobid;
- const repoPath = this.dataset.repopath;
- const redirect_to = this.dataset.linkpath;
- debugAgain(ID, repoPath, redirect_to);
- });
-
- function setWaitNums() {
- if ($(".cloudbrain-type").length === 0 && $(".gpu-type").length === 0) {
- return;
- }
- if (
- $(".cloudbrain-type").length !== 0 &&
- !$(".cloudbrain-type").data("queue")
- ) {
- return;
- }
- let waitNums = $(".cloudbrain-type").data("queue").split("map")[1];
- let test = new Map();
- let waitNumsArray = waitNums.split(" ");
- waitNumsArray.forEach((element, index) => {
- if (index === 0) {
- test.set(element.slice(1, -2), parseInt(element.slice(-1)));
- } else if (index === waitNumsArray.length - 1) {
- test.set(element.slice(0, -3), parseInt(element.slice(-2, -1)));
- } else {
- test.set(element.slice(0, -2), parseInt(element.slice(-1)));
- }
- });
- $(".ui.search.dropdown.gpu-type").dropdown({
- onChange: function (value, text, $selectedItem) {
- let gpuTypeNums = test.get(value);
- let gpuTypeNumString =
- $(".cloudbrain-type").data("queue-start") +
- " " +
- gpuTypeNums +
- " " +
- $(".cloudbrain-type").data("queue-end");
- $("#gpu-nums").text(gpuTypeNumString);
- },
- });
- }
- setWaitNums();
- }
-
- function userSearchControll() {
- if ($("#userCloud").length === 0) {
- return;
- }
- const params = new URLSearchParams(window.location.search);
- let cluster;
- if ($(".cloudbrain_debug").length === 1) {
- if (!params.get("cluster")) {
- cluster = $(".cloudbrain_debug").data("all-cluster");
- } else {
- if (params.get("cluster") === "resource_cluster_c2net") {
- cluster = $(".cloudbrain_debug").data("cluster-c2net");
- } else {
- cluster = $(".cloudbrain_debug").data("cluster-openi");
- }
- }
- }
- let jobType;
- if ($(".cloudbrain_debug").length === 1) {
- if (!params.get("jobType")) {
- jobType = $(".cloudbrain_debug").data("allTask");
- } else {
- if (params.get("jobType") === "DEBUG") {
- jobType = $(".cloudbrain_debug").data("debug-task");
- } else if (params.get("jobType") === "TRAIN") {
- jobType = $(".cloudbrain_debug").data("train-task");
- } else if (params.get("jobType") === "INFERENCE") {
- jobType = $(".cloudbrain_debug").data("inference-task");
- } else {
- jobType = $(".cloudbrain_debug").data("benchmark-task");
- }
- }
- }
- let aiCenter = !params.get("aiCenter")
- ? $(".cloudbrain_debug").data("all-aiCenter")
- : params.get("aiCenter");
- let listType = !params.get("listType")
- ? $(".cloudbrain_debug").data("all-compute")
- : params.get("listType");
- let jobStatus = !params.get("jobStatus")
- ? $(".cloudbrain_debug").data("all-status")
- : params.get("jobStatus").toUpperCase();
- const dropdownValueArray = [cluster, aiCenter, jobType, listType, jobStatus];
- $("#userCloud .default.text ").each(function (index, e) {
- $(e).text(dropdownValueArray[index]);
- });
- }
-
- function AdaminSearchControll() {
- if ($("#adminCloud").length === 0) {
- return;
- }
- const params = new URLSearchParams(window.location.search);
- let cluster;
- if ($(".cloudbrain_debug").length === 1) {
- if (!params.get("cluster")) {
- cluster = $(".cloudbrain_debug").data("all-cluster");
- } else {
- if (params.get("cluster") === "resource_cluster_c2net") {
- cluster = $(".cloudbrain_debug").data("cluster-c2net");
- } else {
- cluster = $(".cloudbrain_debug").data("cluster-openi");
- }
- }
- }
- let aiCenter = !params.get("aiCenter")
- ? $(".cloudbrain_debug").data("all-aiCenter")
- : params.get("aiCenter");
- let jobType = !params.get("jobType")
- ? $(".cloudbrain_debug").data("all-task")
- : params.get("jobType");
- let listType = !params.get("listType")
- ? $(".cloudbrain_debug").data("all-compute")
- : params.get("listType");
- let jobStatus = !params.get("jobStatus")
- ? $(".cloudbrain_debug").data("all-status")
- : params.get("jobStatus").toUpperCase();
- const dropdownValueArray = [cluster, aiCenter, jobType, listType, jobStatus];
- $("#adminCloud .default.text ").each(function (index, e) {
- $(e).text(dropdownValueArray[index]);
- });
- }
- userSearchControll();
- AdaminSearchControll();
|