From 671caf541bd56d45d7fa97e17adab44f2f6e9bfb Mon Sep 17 00:00:00 2001 From: yangon <2689991790@qq.com> Date: Tue, 9 Apr 2024 18:58:09 +0800 Subject: [PATCH 1/4] fix:Correct the way resources are obtained (#292) --- ui/src/pages/Tenant/helper.ts | 12 ++++++------ ui/src/services/index.ts | 7 ------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/ui/src/pages/Tenant/helper.ts b/ui/src/pages/Tenant/helper.ts index 2b7e899b8..229d97d20 100644 --- a/ui/src/pages/Tenant/helper.ts +++ b/ui/src/pages/Tenant/helper.ts @@ -191,17 +191,17 @@ export function findMinParameter( }; } else { result = { - maxCPU: Math.max( + maxCPU: Math.min( result.maxCPU!, - essentialParameter[zone]['availableCPU'], + essentialParameter.obZoneResourceMap[zone]['availableCPU'], ), - maxLogDisk: Math.max( + maxLogDisk: Math.min( result.maxLogDisk!, - essentialParameter[zone]['availableLogDisk'], + essentialParameter.obZoneResourceMap[zone]['availableLogDisk'], ), - maxMemory: Math.max( + maxMemory: Math.min( result.maxMemory!, - essentialParameter[zone]['availableMemory'], + essentialParameter.obZoneResourceMap[zone]['availableMemory'], ), }; } diff --git a/ui/src/services/index.ts b/ui/src/services/index.ts index 6f783ecd1..8b1010d75 100644 --- a/ui/src/services/index.ts +++ b/ui/src/services/index.ts @@ -442,7 +442,6 @@ export async function getEssentialParameters({ ns, name, }: API.NamespaceAndName): Promise { - // return request(`${obClusterPrefix}/${ns}/${name}/resource-usages`); const r = await request(`${obClusterPrefix}/${ns}/${name}/resource-usages`); const formatResourceAttr = ['availableDataDisk','availableLogDisk','availableMemory'] if(r.successful){ @@ -450,17 +449,11 @@ export async function getEssentialParameters({ r.data.obServerResources.forEach((item)=>{ for(let attr of formatResourceAttr){ item[attr] = item[attr] / (1<<30) - // if(attr === 'availableMemory' && item.obZone === 'zone1'){ - // item[attr] = 3 - // } } }) Object.keys(r.data.obZoneResourceMap).forEach((key)=>{ for(let attr of formatResourceAttr){ r.data.obZoneResourceMap[key][attr] = r.data.obZoneResourceMap[key][attr] / (1 << 30); - // if(attr === 'availableMemory' && key === 'zone1'){ - // r.data.obZoneResourceMap[key][attr] = 3 - // } } }) return r From 70a625887000b02de6d870dd36de2ba3346da969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=B4=E6=99=96?= <2689991790@qq.com> Date: Sun, 28 Apr 2024 11:29:03 +0800 Subject: [PATCH 2/4] fix:The selected cluster exception display zone --- ui/src/services/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/services/index.ts b/ui/src/services/index.ts index 923e53744..0ba8f9b3c 100644 --- a/ui/src/services/index.ts +++ b/ui/src/services/index.ts @@ -157,8 +157,8 @@ export async function getSimpleClusterList(): Promise ({ - clusterId: clusterDetail.clusterId, + data:r.data.map((clusterDetail,index) => ({ + clusterId: clusterDetail.clusterId + index, name: clusterDetail.name, namespace: clusterDetail.namespace, topology: clusterDetail.topology, From c5e27d38883fefa1fa8c4069912c2fd8b8de6db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=B4=E6=99=96?= <2689991790@qq.com> Date: Sun, 28 Apr 2024 14:42:10 +0800 Subject: [PATCH 3/4] Use name+namespace as unique id --- ui/src/pages/Tenant/New/BasicInfo.tsx | 2 +- ui/src/pages/Tenant/New/ResourcePools.tsx | 4 ++-- ui/src/pages/Tenant/New/index.tsx | 10 +++++----- ui/src/pages/Tenant/helper.ts | 4 ++-- ui/src/services/index.ts | 18 +++++++++--------- ui/src/type/typings.d.ts | 1 + 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/ui/src/pages/Tenant/New/BasicInfo.tsx b/ui/src/pages/Tenant/New/BasicInfo.tsx index 0700f7b5a..1d0813216 100644 --- a/ui/src/pages/Tenant/New/BasicInfo.tsx +++ b/ui/src/pages/Tenant/New/BasicInfo.tsx @@ -24,7 +24,7 @@ export default function BasicInfo({ const clusterOptions = clusterList .filter((cluster) => cluster.status !== 'failed') .map((cluster) => ({ - value: cluster.clusterId, + value: cluster.id, label: cluster.name, status: cluster.status, })); diff --git a/ui/src/pages/Tenant/New/ResourcePools.tsx b/ui/src/pages/Tenant/New/ResourcePools.tsx index ec3e786b0..944e57e68 100644 --- a/ui/src/pages/Tenant/New/ResourcePools.tsx +++ b/ui/src/pages/Tenant/New/ResourcePools.tsx @@ -9,7 +9,7 @@ import { findMinParameter, modifyZoneCheckedStatus } from '../helper'; import styles from './index.less'; interface ResourcePoolsProps { - selectClusterId?: number; + selectClusterId?: string; clusterList: API.SimpleClusterList; form: FormInstance; setClusterList: React.Dispatch>; @@ -45,7 +45,7 @@ export default function ResourcePools({ ); }; const targetZoneList = clusterList - .filter((cluster) => cluster.clusterId === selectClusterId)[0] + .filter((cluster) => cluster.id === selectClusterId)[0] ?.topology.map((zone) => ({ zone: zone.zone, checked: zone.checked })); useEffect(() => { diff --git a/ui/src/pages/Tenant/New/index.tsx b/ui/src/pages/Tenant/New/index.tsx index c994db9b6..d440f6d04 100644 --- a/ui/src/pages/Tenant/New/index.tsx +++ b/ui/src/pages/Tenant/New/index.tsx @@ -22,7 +22,7 @@ export default function New() { const publicKey = usePublicKey(); const [form] = Form.useForm(); const [passwordVal, setPasswordVal] = useState(''); - const [selectClusterId, setSelectClusterId] = useState(); + const [selectClusterId, setSelectClusterId] = useState(); const [clusterList, setClusterList] = useState([]); useRequest(getSimpleClusterList, { onSuccess: ({ successful, data }) => { @@ -43,7 +43,7 @@ export default function New() { }); //Selected cluster's resource name and namespace const { name: clusterName, namespace: ns } = - clusterList.filter((cluster) => cluster.clusterId === selectClusterId)[0] || + clusterList.filter((cluster) => cluster.id === selectClusterId)[0] || {}; const essentialParameter = essentialParameterRes?.data; @@ -64,7 +64,7 @@ export default function New() { } const ns = clusterList.filter( - (cluster) => cluster.clusterId === selectClusterId, + (cluster) => cluster.id === selectClusterId, )[0]?.namespace; const res = await createTenantReportWrap({ namespace: ns, @@ -89,7 +89,7 @@ export default function New() { useUpdateEffect(() => { const { name, namespace } = clusterList.find( - (cluster) => cluster.clusterId === selectClusterId, + (cluster) => cluster.id === selectClusterId, ) || {}; if (name && namespace) { getEssentialParameters({ @@ -102,7 +102,7 @@ export default function New() { useEffect(() => { if (clusterList) { const cluster = clusterList.find( - (cluster) => cluster.clusterId === selectClusterId, + (cluster) => cluster.id === selectClusterId, ); cluster?.topology.forEach((zone) => { form.setFieldValue(['pools', zone.zone, 'checked'], zone.checked); diff --git a/ui/src/pages/Tenant/helper.ts b/ui/src/pages/Tenant/helper.ts index 6ede1652d..81bba4f99 100644 --- a/ui/src/pages/Tenant/helper.ts +++ b/ui/src/pages/Tenant/helper.ts @@ -222,13 +222,13 @@ export const modifyZoneCheckedStatus = ( zone: string, checked: boolean, target: { - id?: number; + id?: string; name?: string; }, ) => { const _clusterList = cloneDeep(clusterList); for (const cluster of _clusterList) { - if (cluster.clusterId === target.id || cluster.name === target.name) { + if (cluster.id === target.id || cluster.name === target.name) { cluster.topology.forEach((zoneItem) => { if (zoneItem.zone === zone) { zoneItem.checked = checked; diff --git a/ui/src/services/index.ts b/ui/src/services/index.ts index 0ba8f9b3c..bc54cec61 100644 --- a/ui/src/services/index.ts +++ b/ui/src/services/index.ts @@ -1,9 +1,8 @@ import { formatTopoData } from '@/components/TopoComponent/helper'; import { formatClusterData } from '@/pages/Cluster/Detail/Overview/helper'; -import { formatStatisticData } from '@/utils/helper'; +import { floorToTwoDecimalPlaces,formatStatisticData } from '@/utils/helper'; import { intl } from '@/utils/intl'; import { request } from '@umijs/max'; -import { floorToTwoDecimalPlaces } from '@/utils/helper'; import _ from 'lodash'; import moment from 'moment'; @@ -155,18 +154,19 @@ export async function getSimpleClusterList(): Promise ({ - clusterId: clusterDetail.clusterId + index, + data: r.data.map((clusterDetail) => ({ + clusterId: clusterDetail.clusterId, // clusterId is not unique + id: clusterDetail.name + clusterDetail.namespace, name: clusterDetail.name, namespace: clusterDetail.namespace, topology: clusterDetail.topology, clusterName: clusterDetail.clusterName, - status: clusterDetail.status - })) - } - }; + status: clusterDetail.status, + })), + }; + } return r; } diff --git a/ui/src/type/typings.d.ts b/ui/src/type/typings.d.ts index 5107b85fd..942853f8f 100644 --- a/ui/src/type/typings.d.ts +++ b/ui/src/type/typings.d.ts @@ -405,6 +405,7 @@ declare namespace API { namespace: string; topology: Topology[]; status: string; + id: string; }; type SimpleClusterList = SimpleCluster[]; From 95fd1957230de29088f4fff260b5cc6db0f56d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=B4=E6=99=96?= <2689991790@qq.com> Date: Mon, 29 Apr 2024 10:27:57 +0800 Subject: [PATCH 4/4] Properly generate id --- ui/src/services/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/services/index.ts b/ui/src/services/index.ts index bc54cec61..3aff68e48 100644 --- a/ui/src/services/index.ts +++ b/ui/src/services/index.ts @@ -158,7 +158,7 @@ export async function getSimpleClusterList(): Promise ({ clusterId: clusterDetail.clusterId, // clusterId is not unique - id: clusterDetail.name + clusterDetail.namespace, + id: `${clusterDetail.namespace}:${clusterDetail.name}`, name: clusterDetail.name, namespace: clusterDetail.namespace, topology: clusterDetail.topology,