From 5b20a98f1adc5c94e7bfa4480c2d0074239ef25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=AB=A5=E5=B4=87?= <792998983@qq.com> Date: Mon, 29 Jul 2024 10:46:00 +0000 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96SCOW=E7=89=88=E6=9C=AC=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/mis-server/src/services/config.ts | 10 ++++++++++ apps/portal-server/src/services/config.ts | 13 +++++++++++-- protos/common/config.proto | 13 +++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/mis-server/src/services/config.ts b/apps/mis-server/src/services/config.ts index 260aa5b3f5..40a0a22076 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,13 @@ export const configServiceServer = plugin((server) => { return [{ clusterConfigs: clusterConfigsProto }]; }, + getVersion: async () => { + + const version = await JSON.parse(readFileSync(join(__dirname, "../../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..25089889c0 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,14 @@ export const staticConfigServiceServer = plugin((server) => { return [{ clusterConfigs: clusterConfigsProto }]; }, + getVersion: async () => { + + const version = await JSON.parse(readFileSync(join(__dirname, "../../package.json"), "utf-8")).version; + + const [major, minor, patch] = version.split(".").map(Number); + + return [{ major, minor, patch }]; + }, }); }); diff --git a/protos/common/config.proto b/protos/common/config.proto index ec68fb3af1..d861089f0c 100644 --- a/protos/common/config.proto +++ b/protos/common/config.proto @@ -165,6 +165,16 @@ message GetClusterConfigFilesResponse { repeated ClusterConfigSchemaProto cluster_configs = 1; } +message GetVersionRequest { + +} + +message GetVersionResponse { + 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 的版本,方便接入其它服务 + rpc GetVersion(GetVersionRequest) returns (GetVersionResponse); } From 8b6bda2b297aff042f9488742949835184164bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=AB=A5=E5=B4=87?= <792998983@qq.com> Date: Mon, 29 Jul 2024 11:18:15 +0000 Subject: [PATCH 2/8] test --- apps/mis-web/src/pages/api/getVersion.ts | 39 ++++++++++++++ apps/portal-server/tests/utils/config.test.ts | 54 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 apps/mis-web/src/pages/api/getVersion.ts create mode 100644 apps/portal-server/tests/utils/config.test.ts diff --git a/apps/mis-web/src/pages/api/getVersion.ts b/apps/mis-web/src/pages/api/getVersion.ts new file mode 100644 index 0000000000..e822cac342 --- /dev/null +++ b/apps/mis-web/src/pages/api/getVersion.ts @@ -0,0 +1,39 @@ +/** + * 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 { typeboxRouteSchema } from "@ddadaal/next-typed-api-routes-runtime"; +import { asyncClientCall } from "@ddadaal/tsgrpc-client"; +import { ConfigServiceClient } from "@scow/protos/build/common/config"; +import { Type } from "@sinclair/typebox"; +import { getClient } from "src/utils/client"; +import { route } from "src/utils/route"; + +export const GetVersionSchema = typeboxRouteSchema({ + + method: "GET", + + responses: { + 200: Type.Object({ + major: Type.Number(), + minor: Type.Number(), + patch: Type.Number(), + }), + + }, +}); + +export default route(GetVersionSchema, + async () => { + const client = getClient(ConfigServiceClient); + const reply = await asyncClientCall(client, "getVersion", { }); + return { 200: reply }; + }); 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..b941b79219 --- /dev/null +++ b/apps/portal-server/tests/utils/config.test.ts @@ -0,0 +1,54 @@ +/** + * 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 { 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, "getVersion", { query: {} }); + + expect(reply.major).toBeNumber(); + expect(reply.minor).toBeNumber(); + expect(reply.patch).toBeNumber(); +}); From 04ab95f42487bea62e6b2f0948e78ee3b5e577de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=AB=A5=E5=B4=87?= <792998983@qq.com> Date: Mon, 29 Jul 2024 11:27:53 +0000 Subject: [PATCH 3/8] changeset --- .changeset/kind-owls-buy.md | 5 +++++ .changeset/mean-boats-repair.md | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/kind-owls-buy.md create mode 100644 .changeset/mean-boats-repair.md diff --git a/.changeset/kind-owls-buy.md b/.changeset/kind-owls-buy.md new file mode 100644 index 0000000000..603e542e3f --- /dev/null +++ b/.changeset/kind-owls-buy.md @@ -0,0 +1,5 @@ +--- +"@scow/grpc-api": minor +--- + +增加获取 SCOW 版本的接口 diff --git a/.changeset/mean-boats-repair.md b/.changeset/mean-boats-repair.md new file mode 100644 index 0000000000..6c061f85af --- /dev/null +++ b/.changeset/mean-boats-repair.md @@ -0,0 +1,6 @@ +--- +"@scow/portal-server": patch +"@scow/mis-server": patch +--- + +增加获取 SCOW 版本的接口 From bf3877e3585ddb7df60658de13f3185ef03cf5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=AB=A5=E5=B4=87?= <792998983@qq.com> Date: Tue, 30 Jul 2024 01:34:03 +0000 Subject: [PATCH 4/8] fix --- apps/mis-web/src/pages/api/getVersion.ts | 39 ------------------------ 1 file changed, 39 deletions(-) delete mode 100644 apps/mis-web/src/pages/api/getVersion.ts diff --git a/apps/mis-web/src/pages/api/getVersion.ts b/apps/mis-web/src/pages/api/getVersion.ts deleted file mode 100644 index e822cac342..0000000000 --- a/apps/mis-web/src/pages/api/getVersion.ts +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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 { typeboxRouteSchema } from "@ddadaal/next-typed-api-routes-runtime"; -import { asyncClientCall } from "@ddadaal/tsgrpc-client"; -import { ConfigServiceClient } from "@scow/protos/build/common/config"; -import { Type } from "@sinclair/typebox"; -import { getClient } from "src/utils/client"; -import { route } from "src/utils/route"; - -export const GetVersionSchema = typeboxRouteSchema({ - - method: "GET", - - responses: { - 200: Type.Object({ - major: Type.Number(), - minor: Type.Number(), - patch: Type.Number(), - }), - - }, -}); - -export default route(GetVersionSchema, - async () => { - const client = getClient(ConfigServiceClient); - const reply = await asyncClientCall(client, "getVersion", { }); - return { 200: reply }; - }); From 4e99c92ac0c75700f72919e138cc26b321d48395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=AB=A5=E5=B4=87?= <792998983@qq.com> Date: Tue, 30 Jul 2024 01:49:23 +0000 Subject: [PATCH 5/8] fix --- apps/mis-server/src/services/config.ts | 2 +- apps/portal-server/src/services/config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/mis-server/src/services/config.ts b/apps/mis-server/src/services/config.ts index 40a0a22076..2e8e877cfa 100644 --- a/apps/mis-server/src/services/config.ts +++ b/apps/mis-server/src/services/config.ts @@ -80,7 +80,7 @@ export const configServiceServer = plugin((server) => { getVersion: async () => { - const version = await JSON.parse(readFileSync(join(__dirname, "../../package.json"), "utf-8")).version; + const version = await JSON.parse(readFileSync(join(__dirname, "../../../../package.json"), "utf-8")).version; const [major, minor, patch] = version.split(".").map(Number); diff --git a/apps/portal-server/src/services/config.ts b/apps/portal-server/src/services/config.ts index 25089889c0..fb838bf990 100644 --- a/apps/portal-server/src/services/config.ts +++ b/apps/portal-server/src/services/config.ts @@ -88,7 +88,7 @@ export const staticConfigServiceServer = plugin((server) => { getVersion: async () => { - const version = await JSON.parse(readFileSync(join(__dirname, "../../package.json"), "utf-8")).version; + const version = await JSON.parse(readFileSync(join(__dirname, "../../../../package.json"), "utf-8")).version; const [major, minor, patch] = version.split(".").map(Number); From 24f50baadd32f326c7b1e15ca35a3befa4c5c35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=AB=A5=E5=B4=87?= <792998983@qq.com> Date: Wed, 31 Jul 2024 05:44:32 +0000 Subject: [PATCH 6/8] fix --- apps/mis-server/src/services/config.ts | 5 +++-- apps/portal-server/src/services/config.ts | 5 +++-- apps/portal-server/tests/utils/config.test.ts | 14 ++++++++++---- protos/common/config.proto | 6 +++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/apps/mis-server/src/services/config.ts b/apps/mis-server/src/services/config.ts index 2e8e877cfa..8187f38c8d 100644 --- a/apps/mis-server/src/services/config.ts +++ b/apps/mis-server/src/services/config.ts @@ -78,9 +78,10 @@ export const configServiceServer = plugin((server) => { return [{ clusterConfigs: clusterConfigsProto }]; }, - getVersion: async () => { + getApiVersion: async () => { - const version = await JSON.parse(readFileSync(join(__dirname, "../../../../package.json"), "utf-8")).version; + 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); diff --git a/apps/portal-server/src/services/config.ts b/apps/portal-server/src/services/config.ts index fb838bf990..9688380ea9 100644 --- a/apps/portal-server/src/services/config.ts +++ b/apps/portal-server/src/services/config.ts @@ -86,9 +86,10 @@ export const staticConfigServiceServer = plugin((server) => { return [{ clusterConfigs: clusterConfigsProto }]; }, - getVersion: async () => { + getApiVersion: async () => { - const version = await JSON.parse(readFileSync(join(__dirname, "../../../../package.json"), "utf-8")).version; + 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); diff --git a/apps/portal-server/tests/utils/config.test.ts b/apps/portal-server/tests/utils/config.test.ts index b941b79219..4b49542c84 100644 --- a/apps/portal-server/tests/utils/config.test.ts +++ b/apps/portal-server/tests/utils/config.test.ts @@ -26,6 +26,8 @@ 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; @@ -46,9 +48,13 @@ afterEach(async () => { it("get scow version configs info", async () => { - const reply = await asyncUnaryCall(client, "getVersion", { query: {} }); + const reply = await asyncUnaryCall(client, "getApiVersion", { query: {} }); - expect(reply.major).toBeNumber(); - expect(reply.minor).toBeNumber(); - expect(reply.patch).toBeNumber(); + 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 d861089f0c..e0bbe8080d 100644 --- a/protos/common/config.proto +++ b/protos/common/config.proto @@ -165,11 +165,11 @@ message GetClusterConfigFilesResponse { repeated ClusterConfigSchemaProto cluster_configs = 1; } -message GetVersionRequest { +message GetApiVersionRequest { } -message GetVersionResponse { +message GetApiVersionResponse { uint32 major = 1; uint32 minor = 2; uint32 patch = 3; @@ -184,5 +184,5 @@ service ConfigService { rpc GetClusterConfigFiles(GetClusterConfigFilesRequest) returns (GetClusterConfigFilesResponse); // 获取当前部署 SCOW 的版本,方便接入其它服务 - rpc GetVersion(GetVersionRequest) returns (GetVersionResponse); + rpc GetApiVersion(GetApiVersionRequest) returns (GetApiVersionResponse); } From 9c8c6aa7d9ef15f0e08a012f290deed4ff5d8d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=AB=A5=E5=B4=87?= <792998983@qq.com> Date: Thu, 1 Aug 2024 01:56:40 +0000 Subject: [PATCH 7/8] fix --- protos/common/config.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protos/common/config.proto b/protos/common/config.proto index e0bbe8080d..9fdceeb455 100644 --- a/protos/common/config.proto +++ b/protos/common/config.proto @@ -183,6 +183,6 @@ service ConfigService { // 获取 SCOW 部署的集群配置文件中的集群信息 rpc GetClusterConfigFiles(GetClusterConfigFilesRequest) returns (GetClusterConfigFilesResponse); - // 获取当前部署 SCOW 的版本,方便接入其它服务 + // 获取当前部署 SCOW API 的版本,方便接入其它服务 rpc GetApiVersion(GetApiVersionRequest) returns (GetApiVersionResponse); } From efc6a9833f71b9ef6abc4fb414b425325d6824c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=AB=A5=E5=B4=87?= <792998983@qq.com> Date: Thu, 1 Aug 2024 02:02:25 +0000 Subject: [PATCH 8/8] fix --- .changeset/kind-owls-buy.md | 2 +- .changeset/mean-boats-repair.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/kind-owls-buy.md b/.changeset/kind-owls-buy.md index 603e542e3f..cccbedd57e 100644 --- a/.changeset/kind-owls-buy.md +++ b/.changeset/kind-owls-buy.md @@ -2,4 +2,4 @@ "@scow/grpc-api": minor --- -增加获取 SCOW 版本的接口 +增加获取 SCOW API 版本的接口 diff --git a/.changeset/mean-boats-repair.md b/.changeset/mean-boats-repair.md index 6c061f85af..569444e621 100644 --- a/.changeset/mean-boats-repair.md +++ b/.changeset/mean-boats-repair.md @@ -3,4 +3,4 @@ "@scow/mis-server": patch --- -增加获取 SCOW 版本的接口 +增加获取 SCOW API 版本的接口