Skip to content

Commit

Permalink
fix(portal): 修复集群配置文件中loginNodes配置为字符串数组时报错问题 (#1339)
Browse files Browse the repository at this point in the history
### 问题:
获取集群配置信息的接口缺少兼容原有` loginNodes
`为字符串数组情况的类型映射,导致按登录节点名称和地址渲染路由时出现`undefined`

### 修复:

1.此PR修复上述问题,兼容`loginNodes `为字符串数组时的情况
2.由于是集群配置信息获取接口,补充了`loginNodes`中配置了`scowd`情况的返回值
3.同时此PR删除了 #977 中标注的 deprecated 公共组件已经被再利用的情况的 deprecated 注释

### 修改后:

```
loginNodes:
  # - name: login
  - name:
      i18n:
        default: 登录节点1
        en: loginNode1
        zh_cn: 登录节点1
    address: 111.11.11.111:0000
    scowd:
      port: 9999
```
上述配置形式时,集群接口配置文件中可以返回`scowd: { port: 9999 }`

loginNodes只配置了字符串地址时
```
loginNodes:
  - "111.11.11.111:0000"
```
页面渲染成功

![image](https://github.com/PKUHPC/SCOW/assets/43978285/b6f13c18-eed8-4487-aee5-ced328310b13)
  • Loading branch information
piccaSun authored Jul 8, 2024
1 parent bf32e8d commit 1a096de
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 31 deletions.
9 changes: 9 additions & 0 deletions .changeset/orange-beans-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@scow/portal-server": patch
"@scow/portal-web": patch
"@scow/config": patch
"@scow/lib-server": patch
"@scow/lib-web": patch
---

修复门户系统集群登录节点只配置地址时路由渲染失败的问题,在集群配置接口返回中加入 scowd 配置信息
3 changes: 0 additions & 3 deletions apps/mis-server/src/services/misConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import { ClusterRuntimeInfo_LastActivationOperation,
import { getActivatedClusters, getClustersRuntimeInfo } from "src/bl/clustersUtils";
import { Cluster, ClusterActivationStatus } from "src/entities/Cluster";

/**
* @deprecated Use the new API function GetAvailablePartitionsForCluster From configServiceServer instead.
*/
export const misConfigServiceServer = plugin((server) => {
server.addService<ConfigServiceServer>(ConfigServiceService, {

Expand Down
11 changes: 8 additions & 3 deletions apps/portal-server/tests/file/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/

import { ServiceError } from "@grpc/grpc-js";
import { LoginNode } from "@scow/config/build/cluster";
import { I18nStringType } from "@scow/config/build/i18n";
import { LoginNodesType } from "@scow/config/build/type";
import { sftpWriteFile, sshRawConnect, sshRmrf } from "@scow/lib-ssh";
import { ClusterConfigSchemaProto_LoginNodesProtoType } from "@scow/protos/build/common/config";
import { I18nStringProtoType } from "@scow/protos/build/common/i18n";
Expand Down Expand Up @@ -190,16 +190,21 @@ export const getI18nTypeFormat = (i18nProtoType: I18nStringProtoType | undefined

// protobuf中定义的grpc返回值的loginNodes类型映射到前端loginNode
export const getLoginNodesTypeFormat = (
protoType: ClusterConfigSchemaProto_LoginNodesProtoType | undefined): LoginNodesType => {
protoType: ClusterConfigSchemaProto_LoginNodesProtoType | undefined): LoginNode[] => {

if (!protoType?.value) return [];
if (protoType.value.$case === "loginNodeAddresses") {
return protoType.value.loginNodeAddresses.loginNodeAddressesValue;
return protoType.value.loginNodeAddresses.loginNodeAddressesValue.map((x) => ({
name: x,
address: x,
scowdPort: undefined,
}));
} else {
const loginNodeConfigs = protoType.value.loginNodeConfigs;
return loginNodeConfigs.loginNodeConfigsValue.map((x) => ({
name: getI18nTypeFormat(x.name),
address: x.address,
scowdPort: x.scowd?.port,
}));
}

Expand Down
4 changes: 1 addition & 3 deletions apps/portal-web/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ const buildRuntimeConfig = async (phase, basePath) => {

const configPath = mockEnv ? join(__dirname, "config") : undefined;

// Object.keys(clusters).map((id) => clusters[id].loginNodes = clusters[id].loginNodes.map(getLoginNode));

const uiConfig = getUiConfig(configPath, console);
const portalConfig = getPortalConfig(configPath, console);
const commonConfig = getCommonConfig(configPath, console);
Expand All @@ -126,7 +124,7 @@ const buildRuntimeConfig = async (phase, basePath) => {
DEFAULT_PRIMARY_COLOR,
MOCK_USER_ID: config.MOCK_USER_ID,
UI_CONFIG: uiConfig,
// 当前SCOW未使用
// 当前SCOW未使用
// LOGIN_NODES: parseKeyValue(config.LOGIN_NODES),
SERVER_URL: config.SERVER_URL,
SUBMIT_JOB_WORKING_DIR: portalConfig.submitJobDefaultPwd,
Expand Down
2 changes: 1 addition & 1 deletion apps/portal-web/src/layouts/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const userRoutes: (
user: User | undefined,
currentClusters: Cluster[],
defaultCluster: Cluster | undefined,
LoginNodes: Record<string, LoginNode[]>,
loginNodes: Record<string, LoginNode[]>,
enableLoginDesktop: boolean,
crossClusterFileTransferEnabled: boolean,
setDefaultCluster: (cluster: Cluster | undefined) => void,
Expand Down
1 change: 1 addition & 0 deletions apps/portal-web/src/pages/api/getClusterConfigFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default route(getClusterConfigFilesSchema,
if (!info) { return; }

const modifiedClusters: Record<string, ClusterConfigSchema> = await getClusterConfigFiles();

return {
200: { clusterConfigs: modifiedClusters },
};
Expand Down
4 changes: 2 additions & 2 deletions libs/config/src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export enum k8sRuntime {

const LoginNodeConfigSchema = Type.Object({
name: createI18nStringSchema({ description: "登录节点展示名" }),
address: Type.String({ description: "集群的登录节点地址" }),
address: Type.String({ description: "集群的登录节点地址" }),
scowd: Type.Optional(Type.Object({
port: Type.Number({ description: "scowd 端口号" }),
}, { description: "scowd 相关配置" })),
});

export type LoginNodeConfigSchema = Static<typeof LoginNodeConfigSchema>;

interface LoginNode {
export interface LoginNode {
name: I18nStringType;
address: string;
scowdPort?: number;
Expand Down
8 changes: 0 additions & 8 deletions libs/config/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,3 @@ export const ClusterRuntimeInfoSchema = Type.Object({
});

export type ClusterRuntimeInfo = Static<typeof ClusterRuntimeInfoSchema>;


export type LoginNodesType = string[] |
{
name: I18nStringType,
address: string,
}[];

9 changes: 4 additions & 5 deletions libs/server/src/typeConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
* See the Mulan PSL v2 for more details.
*/

import { ClusterConfigSchema } from "@scow/config/build/cluster";
import { ClusterConfigSchema, LoginNodeConfigSchema } from "@scow/config/build/cluster";
import { I18nStringType } from "@scow/config/build/i18n";
import { LoginNodesType } from "@scow/config/build/type";
import { ClusterConfigSchemaProto, clusterConfigSchemaProto_K8sRuntimeFromJSON,
ClusterConfigSchemaProto_LoginNodeConfigSchemaProto,
ClusterConfigSchemaProto_LoginNodesProtoType } from "@scow/protos/build/common/config";
import { I18nStringProtoType } from "@scow/protos/build/common/i18n";

Expand Down Expand Up @@ -44,7 +42,7 @@ export const getI18nSeverTypeFormat = (i18nConfig: I18nStringType): I18nStringPr
}
};

export const getLoginNodesSeverTypeFormat = (loginNodes: LoginNodesType):
export const getLoginNodesSeverTypeFormat = (loginNodes: string[] | LoginNodeConfigSchema[]):
ClusterConfigSchemaProto_LoginNodesProtoType | undefined => {

if (!loginNodes) return undefined;
Expand All @@ -57,7 +55,8 @@ ClusterConfigSchemaProto_LoginNodesProtoType | undefined => {
loginNodeConfigs: { loginNodeConfigsValue: loginNodes.map((node) => ({
name: getI18nSeverTypeFormat(node.name)!,
address: node.address,
})) as ClusterConfigSchemaProto_LoginNodeConfigSchemaProto[] },
scowd: node.scowd,
})) },
} };
}
};
Expand Down
17 changes: 11 additions & 6 deletions libs/web/src/utils/typeConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* See the Mulan PSL v2 for more details.
*/

import { ClusterConfigSchema } from "@scow/config/build/cluster";
import { ClusterConfigSchema, LoginNodeConfigSchema } from "@scow/config/build/cluster";
import { I18nStringType } from "@scow/config/build/i18n";
import { LoginNodesType } from "@scow/config/build/type";
import { ClusterConfigSchemaProto, clusterConfigSchemaProto_K8sRuntimeToJSON,
ClusterConfigSchemaProto_LoginNodesProtoType } from "@scow/protos/build/common/config";
import { I18nStringProtoType } from "@scow/protos/build/common/i18n";
Expand Down Expand Up @@ -40,17 +39,24 @@ export const getI18nTypeFormat = (i18nProtoType: I18nStringProtoType | undefined

// protobuf中定义的grpc返回值的loginNodes类型映射到前端loginNode
export const getLoginNodesTypeFormat = (
protoType: ClusterConfigSchemaProto_LoginNodesProtoType | undefined): LoginNodesType => {
protoType: ClusterConfigSchemaProto_LoginNodesProtoType | undefined): LoginNodeConfigSchema[] => {

if (!protoType?.value) return [];
if (protoType.value.$case === "loginNodeAddresses") {
return protoType.value.loginNodeAddresses.loginNodeAddressesValue;
return protoType.value.loginNodeAddresses.loginNodeAddressesValue.map((item) => ({
name: item,
address: item,
scowd: undefined,
}));
} else {
const loginNodeConfigs = protoType.value.loginNodeConfigs;

return loginNodeConfigs.loginNodeConfigsValue.map((x) => ({
name: getI18nTypeFormat(x.name),
address: x.address,
scowd: x.scowd,
}));

}

};
Expand All @@ -65,8 +71,7 @@ export const getClusterConfigsTypeFormat = (
const newCluster = {
...rest,
displayName: getI18nTypeFormat(cluster.displayName),
loginNodes: getLoginNodesTypeFormat(
cluster.loginNodes),
loginNodes: getLoginNodesTypeFormat(cluster.loginNodes),
k8s: cluster.k8s ? {
k8sRuntime: clusterConfigSchemaProto_K8sRuntimeToJSON(cluster.k8s.runtime).toLowerCase(),
kubeconfig: cluster.k8s.kubeconfig,
Expand Down

0 comments on commit 1a096de

Please sign in to comment.