Skip to content

Commit

Permalink
feat(portal-server): 新增 scowd GetAppLastSubmission 接口及其在 scow 中的调用 (#…
Browse files Browse the repository at this point in the history
…1394)

新增 scowd app service 和 GetAppLastSubmission 接口,并实现其在 scow 中的调用
由于目前只实现这一个接口,所以没有将 app service 中 ssh 和 scowd 像文件服务和桌面服务那样完全区分开

scowd 实现:PKUHPC/SCOWD#11
  • Loading branch information
Miracle575 authored Aug 13, 2024
1 parent d3de802 commit ac6805d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .changeset/slow-falcons-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@scow/portal-server": patch
"@scow/scowd-protos": patch
"@scow/lib-scowd": patch
---

scowd 新增 app service 和 GetAppLastSubmission 接口

36 changes: 28 additions & 8 deletions apps/portal-server/src/clusterops/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down
37 changes: 37 additions & 0 deletions libs/protos/scowd/protos/api/application/app.proto
Original file line number Diff line number Diff line change
@@ -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<string, string> 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) {}
}
5 changes: 4 additions & 1 deletion libs/scowd/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
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";

import { SslConfig } from "./ssl";

export interface ScowdClient {
file: PromiseClient<typeof FileService>;
desktop: PromiseClient<typeof DesktopService>
desktop: PromiseClient<typeof DesktopService>;
app: PromiseClient<typeof AppService>;
}

export function getClient<TService extends ServiceType>(
Expand All @@ -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;
};

0 comments on commit ac6805d

Please sign in to comment.