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(portal): 修复集群配置文件中loginNodes配置为字符串数组时报错问题 #1339

Merged
merged 5 commits into from
Jul 8, 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
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
Loading