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(mis/portal): 增加获取 SCOW API 版本的接口 #1381

Merged
merged 8 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/kind-owls-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/grpc-api": minor
---

增加获取 SCOW 版本的接口
6 changes: 6 additions & 0 deletions .changeset/mean-boats-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@scow/portal-server": patch
"@scow/mis-server": patch
---

增加获取 SCOW 版本的接口
10 changes: 10 additions & 0 deletions apps/mis-server/src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 }];
},
});
});
13 changes: 11 additions & 2 deletions apps/portal-server/src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigServiceServer>(ConfigServiceService, {

getClusterConfig: async ({ request, logger }) => {
const { cluster } = request;
await checkActivatedClusters({ clusterIds: cluster });
Expand Down Expand Up @@ -63,7 +64,7 @@ export const staticConfigServiceServer = plugin((server) => {
availablePartitions = [];
}

return [ { partitions: availablePartitions } ];
return [{ partitions: availablePartitions }];
},


Expand All @@ -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;
tongchong marked this conversation as resolved.
Show resolved Hide resolved

const [major, minor, patch] = version.split(".").map(Number);

return [{ major, minor, patch }];
},
});
});

Expand Down
54 changes: 54 additions & 0 deletions apps/portal-server/tests/utils/config.test.ts
Original file line number Diff line number Diff line change
@@ -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();
tongchong marked this conversation as resolved.
Show resolved Hide resolved
});
13 changes: 13 additions & 0 deletions protos/common/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,24 @@ 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);

rpc GetAvailablePartitionsForCluster(GetAvailablePartitionsForClusterRequest) returns (GetAvailablePartitionsForClusterResponse);

// 获取 SCOW 部署的集群配置文件中的集群信息
rpc GetClusterConfigFiles(GetClusterConfigFilesRequest) returns (GetClusterConfigFilesResponse);

// 获取当前部署 SCOW 的版本,方便接入其它服务
tongchong marked this conversation as resolved.
Show resolved Hide resolved
rpc GetVersion(GetVersionRequest) returns (GetVersionResponse);
tongchong marked this conversation as resolved.
Show resolved Hide resolved
}
Loading