diff --git a/.changeset/kind-owls-buy.md b/.changeset/kind-owls-buy.md new file mode 100644 index 0000000000..cccbedd57e --- /dev/null +++ b/.changeset/kind-owls-buy.md @@ -0,0 +1,5 @@ +--- +"@scow/grpc-api": minor +--- + +增加获取 SCOW API 版本的接口 diff --git a/.changeset/mean-boats-repair.md b/.changeset/mean-boats-repair.md new file mode 100644 index 0000000000..569444e621 --- /dev/null +++ b/.changeset/mean-boats-repair.md @@ -0,0 +1,6 @@ +--- +"@scow/portal-server": patch +"@scow/mis-server": patch +--- + +增加获取 SCOW API 版本的接口 diff --git a/apps/mis-server/src/services/config.ts b/apps/mis-server/src/services/config.ts index 260aa5b3f5..8187f38c8d 100644 --- a/apps/mis-server/src/services/config.ts +++ b/apps/mis-server/src/services/config.ts @@ -19,6 +19,8 @@ import { convertClusterConfigsToServerProtoType, NO_CLUSTERS } from "@scow/lib-s import { scowErrorMetadata } from "@scow/lib-server/build/error"; import { libCheckActivatedClusters } from "@scow/lib-server/build/misCommon/clustersActivation"; import { ConfigServiceServer, ConfigServiceService } from "@scow/protos/build/common/config"; +import { readFileSync } from "fs"; +import { join } from "path"; import { getActivatedClusters, updateCluster } from "src/bl/clustersUtils"; export const configServiceServer = plugin((server) => { @@ -76,5 +78,14 @@ export const configServiceServer = plugin((server) => { return [{ clusterConfigs: clusterConfigsProto }]; }, + getApiVersion: async () => { + + const version = await JSON.parse(readFileSync(join(__dirname, + "../../node_modules/@scow/protos/package.json"), "utf-8")).version; + + const [major, minor, patch] = version.split(".").map(Number); + + return [{ major, minor, patch }]; + }, }); }); diff --git a/apps/portal-server/src/services/config.ts b/apps/portal-server/src/services/config.ts index 9c036ae646..9688380ea9 100644 --- a/apps/portal-server/src/services/config.ts +++ b/apps/portal-server/src/services/config.ts @@ -21,11 +21,12 @@ import { ConfigServiceServer, ConfigServiceService, Partition } from "@scow/prot import { ConfigServiceServer as runTimeConfigServiceServer, ConfigServiceService as runTimeConfigServiceService } from "@scow/protos/build/portal/config"; import { ApiVersion } from "@scow/utils/build/version"; +import { readFileSync } from "fs"; +import { join } from "path"; import { callOnOne, checkActivatedClusters } from "src/utils/clusters"; export const staticConfigServiceServer = plugin((server) => { return server.addService(ConfigServiceService, { - getClusterConfig: async ({ request, logger }) => { const { cluster } = request; await checkActivatedClusters({ clusterIds: cluster }); @@ -63,7 +64,7 @@ export const staticConfigServiceServer = plugin((server) => { availablePartitions = []; } - return [ { partitions: availablePartitions } ]; + return [{ partitions: availablePartitions }]; }, @@ -85,6 +86,15 @@ export const staticConfigServiceServer = plugin((server) => { return [{ clusterConfigs: clusterConfigsProto }]; }, + getApiVersion: async () => { + + const version = await JSON.parse(readFileSync(join(__dirname, + "../../node_modules/@scow/protos/package.json"), "utf-8")).version; + + const [major, minor, patch] = version.split(".").map(Number); + + return [{ major, minor, patch }]; + }, }); }); diff --git a/apps/portal-server/tests/utils/config.test.ts b/apps/portal-server/tests/utils/config.test.ts new file mode 100644 index 0000000000..4b49542c84 --- /dev/null +++ b/apps/portal-server/tests/utils/config.test.ts @@ -0,0 +1,60 @@ +/** + * 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. + */ + +/** + * 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 { asyncUnaryCall } from "@ddadaal/tsgrpc-client"; +import { Server } from "@ddadaal/tsgrpc-server"; +import { credentials } from "@grpc/grpc-js"; +import { ConfigServiceClient } from "@scow/protos/build/common/config"; +import { readFileSync } from "fs"; +import { join } from "path"; +import { createServer } from "src/app"; + +let server: Server; +let client: ConfigServiceClient; + +beforeEach(async () => { + + server = await createServer(); + + await server.start(); + + client = new ConfigServiceClient(server.serverAddress, credentials.createInsecure()); +}); + +afterEach(async () => { + await server.close(); +}); + +it("get scow version configs info", async () => { + + const reply = await asyncUnaryCall(client, "getApiVersion", { query: {} }); + + const version = await JSON.parse(readFileSync(join(__dirname, + "../../node_modules/@scow/protos/package.json"), "utf-8")).version; + const [major, minor, patch] = version.split(".").map(Number); + console.log(version); + expect(reply.major).toBe(major); + expect(reply.minor).toBe(minor); + expect(reply.patch).toBe(patch); +}); diff --git a/protos/common/config.proto b/protos/common/config.proto index ec68fb3af1..9fdceeb455 100644 --- a/protos/common/config.proto +++ b/protos/common/config.proto @@ -165,6 +165,16 @@ message GetClusterConfigFilesResponse { repeated ClusterConfigSchemaProto cluster_configs = 1; } +message GetApiVersionRequest { + +} + +message GetApiVersionResponse { + uint32 major = 1; + uint32 minor = 2; + uint32 patch = 3; +} + service ConfigService { rpc GetClusterConfig(GetClusterConfigRequest) returns (GetClusterConfigResponse); @@ -172,4 +182,7 @@ service ConfigService { // 获取 SCOW 部署的集群配置文件中的集群信息 rpc GetClusterConfigFiles(GetClusterConfigFilesRequest) returns (GetClusterConfigFilesResponse); + + // 获取当前部署 SCOW API 的版本,方便接入其它服务 + rpc GetApiVersion(GetApiVersionRequest) returns (GetApiVersionResponse); }