Skip to content

Commit

Permalink
fix(mis): 修复系统初始化时作业价格表设置页面报错问题 (#1350)
Browse files Browse the repository at this point in the history
### 问题

系统初始化时 作业价格表设置页面 因集群排序参数为空数组报错
原因为管理系统集群排序列表的上下文context的获取逻辑中集群配置信息数据为{ }时也可以获取排序结果为[ ]

同时此PR在`getClustersRuntimeInfo`
和`getSimpleClustersInfoRomConfigFiles`中增加了403的返回,
修改了mis-web启动时因token过期等情况validation(token)验证没有通过导致api请求挂起的警告

**![image](https://github.com/PKUHPC/SCOW/assets/43978285/01ed6772-1258-441d-9243-49300afb1673)**

### 修改后
相关api请求正常返回403

![image](https://github.com/PKUHPC/SCOW/assets/43978285/ba399c02-374a-4324-8f8c-e79533bf91ce)

若是已初始化系统启动时
portal正常启动:

![image](https://github.com/PKUHPC/SCOW/assets/43978285/54bbec20-4f90-4510-b37a-caa2cf5fbd5c)
mis正常启动:

![image](https://github.com/PKUHPC/SCOW/assets/43978285/0e878523-82b1-4cca-bcd6-17df683ae45c)

若是未初始化系统启动时, 与集群、集群优先级排序数组相关数据获取正常

![image](https://github.com/PKUHPC/SCOW/assets/43978285/dc81fa06-f6a2-469d-b778-e174b2cf33c3)

![image](https://github.com/PKUHPC/SCOW/assets/43978285/200e4d47-1d9f-4c12-8bcb-dd5b930bdd41)

![image](https://github.com/PKUHPC/SCOW/assets/43978285/01e58a5a-ae75-403b-96b7-35977800b3a8)

![image](https://github.com/PKUHPC/SCOW/assets/43978285/c9901152-1e71-4b9e-8255-09fc3985b90e)
  • Loading branch information
piccaSun authored and OYX-1 committed Jul 11, 2024
1 parent 070f98b commit 9816224
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changeset/twelve-mugs-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@scow/mis-web": patch
"@scow/config": patch
"@scow/lib-web": patch
---

修复系统初始化时作业价格表设置页面查询参数报错问题
10 changes: 4 additions & 6 deletions apps/mis-web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,20 @@ MyApp.getInitialProps = async (appContext: AppContext) => {
}
}

const clustersRuntimeInfo = token ?
await api.getClustersRuntimeInfo({ query: { token } }).then((x) => x, () => undefined)
: await api.getClustersRuntimeInfo({ query: { } }).then((x) => x, () => undefined);
const clustersRuntimeInfo = await api.getClustersRuntimeInfo({ query: { token } }).then((x) => x, () => undefined);

// get deployed clusters' simple info (only clusterId, displayName and priority)
const simpleClustersInfo
= await api.getSimpleClustersInfoFromConfigFiles({}).then((x) => x, () => ({ clustersInfo: {} }));

extra.initialSimpleClustersInfo = simpleClustersInfo?.clustersInfo;
extra.initialSimpleClustersInfo = simpleClustersInfo?.clustersInfo ?? {};

const publicConfigClusters = Object.keys(extra.clusterConfigs).length > 0 ?
const publicConfigClusters = extra.clusterConfigs && Object.keys(extra.clusterConfigs).length > 0 ?
getPublicConfigClusters(extra.clusterConfigs) : getPublicConfigClusters(extra.initialSimpleClustersInfo) ?? {};

const activatedClusters
= formatActivatedClusters({
clustersRuntimeInfo: clustersRuntimeInfo?.results,
clustersRuntimeInfo: clustersRuntimeInfo?.results ?? [],
misConfigClusters: publicConfigClusters });

extra.initialActivatedClusters = activatedClusters.misActivatedClusters ?? {};
Expand Down
5 changes: 4 additions & 1 deletion apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const GetClustersRuntimeInfoSchema = typeboxRouteSchema({
200: Type.Object({
results: Type.Array(ClusterRuntimeInfoSchema),
}),

403: Type.Null(),
},
});

Expand All @@ -46,11 +48,12 @@ export default route(GetClustersRuntimeInfoSchema,

// if not initialized, every one can get clustersRuntimeInfo
if (await queryIfInitialized()) {

const { token } = req.query;
// when firstly used in getInitialProps, check the token
// when logged in, use auth()
const info = token ? await validateToken(token) : await auth(req, res);
if (!info) { return; }
if (!info) { return { 403: null }; }
}

const client = getClient(ConfigServiceClient);
Expand Down
4 changes: 3 additions & 1 deletion apps/mis-web/src/pages/api/simpleClustersInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const GetSimpleClustersInfoFromConfigFilesSchema = typeboxRouteSchema({

200: Type.Object({
clustersInfo: Type.Record(Type.String(), SimpleClusterSchema) }),

403: Type.Null(),
},
});

Expand All @@ -47,7 +49,7 @@ export default route(GetSimpleClustersInfoFromConfigFilesSchema,
// if not initialized, every one can getSimpleClusterInfo which includes clusterId, displayedName and priority
if (await queryIfInitialized()) {
const info = await auth(req, res);
if (!info) { return; }
if (!info) { return { 403: null }; }
}

const clustersFullInfo: Record<string, ClusterConfigSchema> = await getClusterConfigFiles();
Expand Down
12 changes: 9 additions & 3 deletions apps/mis-web/src/stores/ClusterInfoStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ export function ClusterInfoStore(
initialSimpleClusters: Record<string, SimpleClusterSchema>,
) {

const publicConfigClusters = getPublicConfigClusters(clusterConfigs)
?? getPublicConfigClusters(initialSimpleClusters) ?? {};
let publicConfigClusters: Record<string, Cluster> = {};
let clusterSortedIdList: string[] = [];

const clusterSortedIdList = getSortedClusterIds(clusterConfigs) ?? getSortedClusterIds(initialSimpleClusters) ?? [];
if (Object.keys(clusterConfigs).length > 0) {
clusterSortedIdList = getSortedClusterIds(clusterConfigs);
publicConfigClusters = getPublicConfigClusters(clusterConfigs);
} else {
clusterSortedIdList = getSortedClusterIds(initialSimpleClusters ?? {});
publicConfigClusters = getPublicConfigClusters(initialSimpleClusters ?? {});
}

const [activatedClusters, setActivatedClusters]
= useState<Record<string, Cluster>>(initialActivatedClusters);
Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const CLUSTER_CONFIG_BASE_PATH = "clusters";
export const SimpleClusterSchema = Type.Object({
clusterId: Type.String(),
displayName: createI18nStringSchema({ description: "集群名称" }),
priority: Type.Number(),
priority: Type.Number({ description: "集群使用的优先级, 数字越小越先展示", default: Number.MAX_SAFE_INTEGER }),
});
export type SimpleClusterSchema = Static<typeof SimpleClusterSchema>;

Expand Down
3 changes: 1 addition & 2 deletions libs/web/src/utils/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export const getSortedClusterIds = (clusters: Record<string, Partial<SimpleClust
return Object.keys(clusters)
.sort(
(a, b) => {
return (clusters[a].priority ?? Number.MAX_SAFE_INTEGER)
- (clusters[b].priority ?? Number.MIN_SAFE_INTEGER);
return clusters[a].priority! - clusters[b].priority!;
},
);
};
Expand Down

0 comments on commit 9816224

Please sign in to comment.