Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(portal-server): 新增 scowd GetAppLastSubmission 接口及其在 scow 中的调用 #1394

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
ddadaal marked this conversation as resolved.
Show resolved Hide resolved

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;
};
Loading