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

fix: 区分SCOW和SCOW AI所使用的适配器调度器接口版本 #1361

Merged
merged 1 commit into from
Jul 17, 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
3 changes: 1 addition & 2 deletions apps/ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@
"@scow/lib-config": "workspace:*",
"@scow/lib-decimal": "workspace:*",
"@scow/lib-operation-log": "workspace:*",
"@scow/lib-scheduler-adapter": "workspace:*",
"@scow/lib-server": "workspace:*",
"@scow/lib-ssh": "workspace:*",
"@scow/lib-web": "workspace:*",
"@scow/scheduler-adapter-protos": "workspace:*",
"@scow/ai-scheduler-adapter-protos": "workspace:*",
"@scow/utils": "workspace:*",
"@scow/rich-error-model": "workspace:*",
"@sinclair/typebox": "0.32.34",
Expand Down
4 changes: 2 additions & 2 deletions apps/ai/src/server/trpc/route/jobs/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

import { asyncClientCall } from "@ddadaal/tsgrpc-client";
import { ServiceError } from "@ddadaal/tsgrpc-common";
import { JobInfo } from "@scow/ai-scheduler-adapter-protos/build/protos/job";
import { AppType } from "@scow/config/build/appForAi";
import { getPlaceholderKeys } from "@scow/lib-config/build/parse";
import { OperationResult, OperationType } from "@scow/lib-operation-log";
import { formatTime } from "@scow/lib-scheduler-adapter";
import { getAppConnectionInfoFromAdapter, getEnvVariables } from "@scow/lib-server";
import {
getUserHomedir,
Expand All @@ -25,7 +25,6 @@ import {
sftpRealPath,
sftpWriteFile,
} from "@scow/lib-ssh";
import { JobInfo } from "@scow/scheduler-adapter-protos/build/protos/job";
import { TRPCError } from "@trpc/server";
import fs from "fs";
import { join } from "path";
Expand All @@ -49,6 +48,7 @@ import {
import { logger } from "src/server/utils/logger";
import { paginate, paginationSchema } from "src/server/utils/pagination";
import { getClusterLoginNode, sshConnect } from "src/server/utils/ssh";
import { formatTime } from "src/utils/datetime";
import { isParentOrSameFolder } from "src/utils/file";
import { isPortReachable } from "src/utils/isPortReachable";
import { parseIp } from "src/utils/parse";
Expand Down
52 changes: 51 additions & 1 deletion apps/ai/src/server/utils/clusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,59 @@
* See the Mulan PSL v2 for more details.
*/

import { getSchedulerAdapterClient, SchedulerAdapterClient } from "@scow/lib-scheduler-adapter";
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

import { ChannelCredentials } from "@grpc/grpc-js";
import { AccountServiceClient } from "@scow/ai-scheduler-adapter-protos/build/protos/account";
import { AppServiceClient } from "@scow/ai-scheduler-adapter-protos/build/protos/app";
import { ConfigServiceClient } from "@scow/ai-scheduler-adapter-protos/build/protos/config";
import { JobServiceClient } from "@scow/ai-scheduler-adapter-protos/build/protos/job";
import { UserServiceClient } from "@scow/ai-scheduler-adapter-protos/build/protos/user";
import { VersionServiceClient } from "@scow/ai-scheduler-adapter-protos/build/protos/version";
import { clusters } from "src/server/config/clusters";

type ClientConstructor<TClient> =
new (address: string, credentials: ChannelCredentials) => TClient;

export interface SchedulerAdapterClient {
account: AccountServiceClient;
user: UserServiceClient;
job: JobServiceClient;
config: ConfigServiceClient;
version: VersionServiceClient;
app: AppServiceClient;
}

export function getClient<TClient>(
address: string, ctor: ClientConstructor<TClient>,
): TClient {
return new ctor(
address,
ChannelCredentials.createInsecure(),
);
}

export const getSchedulerAdapterClient = (address: string) => {
return {
account: getClient(address, AccountServiceClient),
user: getClient(address, UserServiceClient),
job: getClient(address, JobServiceClient),
config: getClient(address, ConfigServiceClient),
version: getClient(address, VersionServiceClient),
app: getClient(address, AppServiceClient),
} as SchedulerAdapterClient;
};

const adapterClientForClusters = Object.entries(clusters).reduce((prev, [cluster, c]) => {
const client = getSchedulerAdapterClient(c.adapterUrl);
prev[cluster] = client;
Expand Down
13 changes: 13 additions & 0 deletions libs/protos/ai-scheduler-adapter/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: v1
plugins:
- name: ts-proto
path: node_modules/ts-proto/protoc-gen-ts_proto
strategy: all
out: generated
opt:
- unrecognizedEnum=false
- useDate=string
- oneof=unions
- esModuleInterop=true
- useOptionals=messages
- outputServices=grpc-js
26 changes: 26 additions & 0 deletions libs/protos/ai-scheduler-adapter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@scow/ai-scheduler-adapter-protos",
"version": "1.0.0",
"description": "",
"main": "build/index.js",
"private": true,
"scripts": {
"generate": "rimraf generated && buf generate --template buf.gen.yaml https://github.com/PKUHPC/scow-scheduler-adapter-interface.git#branch=feat-ai-release",
"build": "rimraf build && tsc"
},
"files": [
"build",
"!**/*.map"
],
"dependencies": {
"@grpc/grpc-js": "1.10.9",
"long": "5.2.3",
"protobufjs": "7.3.2"
},
"devDependencies": {
"ts-proto": "1.180.0"
},
"keywords": [],
"author": "",
"license": "ISC"
}
13 changes: 13 additions & 0 deletions libs/protos/ai-scheduler-adapter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "build",
"baseUrl": "./"
},
"include": [
"generated/**/*.ts"
],
"exclude": [
"node_modules"
]
}
2 changes: 1 addition & 1 deletion libs/protos/scheduler-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "build/index.js",
"private": true,
"scripts": {
"generate": "rimraf generated && buf generate --template buf.gen.yaml https://github.com/PKUHPC/scow-scheduler-adapter-interface.git#branch=feat-ai-release",
"generate": "rimraf generated && buf generate --template buf.gen.yaml https://github.com/PKUHPC/scow-scheduler-adapter-interface.git#branch=v1.5.0",
"build": "rimraf build && tsc"
},
"files": [
Expand Down
25 changes: 19 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading