From e0c216be24e0bb750b5a5dce8312525dd0bb9d76 Mon Sep 17 00:00:00 2001 From: Miracle575 Date: Mon, 12 Aug 2024 06:05:21 +0000 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20scowd=20GetApp?= =?UTF-8?q?LastSubmission=20=E6=8E=A5=E5=8F=A3=E5=8F=8A=E5=85=B6=E5=9C=A8?= =?UTF-8?q?=20scow=20=E4=B8=AD=E7=9A=84=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/portal-server/src/clusterops/app.ts | 36 ++++++++++++++---- .../scowd/protos/api/application/app.proto | 37 +++++++++++++++++++ libs/scowd/src/client.ts | 5 ++- 3 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 libs/protos/scowd/protos/api/application/app.proto diff --git a/apps/portal-server/src/clusterops/app.ts b/apps/portal-server/src/clusterops/app.ts index 3a926ed0b8..fb9b3395fa 100644 --- a/apps/portal-server/src/clusterops/app.ts +++ b/apps/portal-server/src/clusterops/app.ts @@ -30,6 +30,7 @@ import { portalConfig } from "src/config/portal"; import { getClusterAppConfigs, splitSbatchArgs } from "src/utils/app"; import { callOnOne } from "src/utils/clusters"; import { getIpFromProxyGateway } from "src/utils/proxy"; +import { getScowdClient } from "src/utils/scowd"; import { getClusterLoginNode, sshConnect } from "src/utils/ssh"; import { displayIdToPort, getTurboVNCBinPath, parseDisplayId, refreshPassword, refreshPasswordByProxyGateway } from "src/utils/turbovnc"; @@ -247,17 +248,36 @@ export const appOps = (cluster: string): AppOps => { getAppLastSubmission: async (requset, logger) => { const { userId, appId } = requset; - return await sshConnect(host, userId, logger, async (ssh) => { + const file = join(portalConfig.appLastSubmissionDir, appId, APP_LAST_SUBMISSION_INFO); - const sftp = await ssh.requestSFTP(); - const file = join(portalConfig.appLastSubmissionDir, appId, APP_LAST_SUBMISSION_INFO); + const clusterInfo = configClusters[cluster]; + if (clusterInfo.scowd?.enabled) { + const client = getScowdClient(cluster); - if (!await sftpExists(sftp, file)) { return { lastSubmissionInfo: undefined }; } - const content = await sftpReadFile(sftp)(file); - const data = JSON.parse(content.toString()) as SubmissionInfo; + const data = await client.app.getAppLastSubmission({ userId, filePath: file }); + + const submitTime = !data.fileData?.submitTime ? undefined + : new Date(Number((data.fileData.submitTime.seconds * BigInt(1000)) + + BigInt(data.fileData.submitTime.nanos / 1000000))); + + return { lastSubmissionInfo: data.fileData ? { + ...data.fileData, + submitTime: submitTime?.toISOString(), + } : undefined }; + + } else { + return await sshConnect(host, userId, logger, async (ssh) => { + + const sftp = await ssh.requestSFTP(); + + if (!await sftpExists(sftp, file)) { return { lastSubmissionInfo: undefined }; } + const content = await sftpReadFile(sftp)(file); + const data = JSON.parse(content.toString()) as SubmissionInfo; + + return { lastSubmissionInfo: data }; + }); + } - return { lastSubmissionInfo: data }; - }); }, listAppSessions: async (request, logger) => { diff --git a/libs/protos/scowd/protos/api/application/app.proto b/libs/protos/scowd/protos/api/application/app.proto new file mode 100644 index 0000000000..2382ee4c2e --- /dev/null +++ b/libs/protos/scowd/protos/api/application/app.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package services.app; + +option go_package = "scowd/protos/gen/api/application;apiv1"; + +import "google/protobuf/timestamp.proto"; + +message SubmissionInfo { + string user_id = 1; + string cluster = 2; + string app_id = 3; + string app_name =4; + string account = 5; + optional string partition = 6; + optional string qos = 7; + uint32 core_count = 8; + uint32 max_time = 9; + google.protobuf.Timestamp submit_time = 10; + map custom_attributes = 11; + uint32 node_count = 12; + optional uint32 gpu_count = 13; +} + +message GetAppLastSubmissionRequest { + string user_id = 1; + string file_path = 2; +} + +message GetAppLastSubmissionResponse { + SubmissionInfo file_data = 1; +} + + +service AppService { + rpc GetAppLastSubmission(GetAppLastSubmissionRequest) returns (GetAppLastSubmissionResponse) {} +} diff --git a/libs/scowd/src/client.ts b/libs/scowd/src/client.ts index 9a8424a40f..08cacc4887 100644 --- a/libs/scowd/src/client.ts +++ b/libs/scowd/src/client.ts @@ -13,6 +13,7 @@ import type { ServiceType } from "@bufbuild/protobuf"; import { createPromiseClient, PromiseClient } from "@connectrpc/connect"; import { createConnectTransport } from "@connectrpc/connect-node"; +import { AppService } from "@scow/scowd-protos/build/application/app_connect"; import { DesktopService } from "@scow/scowd-protos/build/application/desktop_connect"; import { FileService } from "@scow/scowd-protos/build/storage/file_connect"; @@ -20,7 +21,8 @@ import { SslConfig } from "./ssl"; export interface ScowdClient { file: PromiseClient; - desktop: PromiseClient + desktop: PromiseClient; + app: PromiseClient; } export function getClient( @@ -40,5 +42,6 @@ export const getScowdClient = (scowdUrl: string, certificates?: SslConfig) => { return { file: getClient(scowdUrl, FileService, certificates), desktop: getClient(scowdUrl, DesktopService, certificates), + app: getClient(scowdUrl, AppService, certificates), } as ScowdClient; }; From 617b98ea478c8eddeafbb145b5239ce1df57bff5 Mon Sep 17 00:00:00 2001 From: Miracle575 Date: Mon, 12 Aug 2024 09:30:49 +0000 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=E6=96=B0=E5=A2=9E=20changeset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/slow-falcons-give.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changeset/slow-falcons-give.md diff --git a/.changeset/slow-falcons-give.md b/.changeset/slow-falcons-give.md new file mode 100644 index 0000000000..60fde76f45 --- /dev/null +++ b/.changeset/slow-falcons-give.md @@ -0,0 +1,8 @@ +--- +"@scow/portal-server": patch +"@scow/scowd-protos": patch +"@scow/lib-scowd": patch +--- + +scowd 新增 app service 和 GetAppLastSubmission 接口 +