Skip to content

Commit

Permalink
Self-test function and interface environment test (#681)
Browse files Browse the repository at this point in the history
* chore: update openapi info

* fix CR

* feat: add  nfsInfo resourceDrawer in cluster detail

* improve: update ResourceDrawer  UI

* update ParametersModal and Parameters table

* fix CR

* improve: update parametersModal and  api

* feat:Self-test function and interface environment test

* fix CR
  • Loading branch information
TianWuwt authored Dec 19, 2024
1 parent 27945cc commit 9738fcb
Show file tree
Hide file tree
Showing 16 changed files with 403 additions and 159 deletions.
18 changes: 18 additions & 0 deletions ui/src/api/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5657,6 +5657,12 @@ export interface ResponseOBCluster {
* @memberof ResponseOBCluster
*/
'storage': ResponseOBServerStorage;
/**
*
* @type {boolean}
* @memberof ResponseOBCluster
*/
'supportStaticIP': boolean;
/**
*
* @type {Array<ResponseOBZone>}
Expand Down Expand Up @@ -5714,6 +5720,12 @@ export interface ResponseOBClusterMeta {
* @memberof ResponseOBClusterMeta
*/
'namespace': string;
/**
*
* @type {boolean}
* @memberof ResponseOBClusterMeta
*/
'supportStaticIP': boolean;
/**
*
* @type {string}
Expand Down Expand Up @@ -5783,6 +5795,12 @@ export interface ResponseOBClusterOverview {
* @memberof ResponseOBClusterOverview
*/
'statusDetail': string;
/**
*
* @type {boolean}
* @memberof ResponseOBClusterOverview
*/
'supportStaticIP': boolean;
/**
*
* @type {Array<ResponseOBZone>}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/api/generated/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { Configuration } from './configuration';
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
import globalAxios from 'axios';

export const BASE_PATH = "/api/v1".replace(/\/+$/, "");
export const BASE_PATH = "http://localhost".replace(/\/+$/, "");

/**
*
Expand Down
30 changes: 29 additions & 1 deletion ui/src/components/TopoComponent/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ const serverOperate: Topo.OperateTypeLabel = [
{
value: 'restartServer',
label: '重启server',
disabled: false,
},
{
value: 'deleteServer',
label: intl.formatMessage({
id: 'dashboard.Detail.Topo.constants.DeleteServer',
defaultMessage: '删除server',
defaultMessage: '删除 server',
}),
disabled: false,
},
// {
// value: 'add',
Expand Down Expand Up @@ -135,6 +137,31 @@ const getZoneOperateOfCluster = (
});
return zoneOperate;
};
const getServerOperateOfCluster = (
topoData: Topo.GraphNodeType | undefined,
disabled: boolean,
serverZone: string,
): Topo.OperateTypeLabel => {
if (!topoData) return [];
// 任何 zone 里面只剩一个 server 就不能删了
const supportStaticIPisDisabled = topoData?.supportStaticIP;
const zoneCurrent = topoData?.children?.find(
(zone) => zone.label === serverZone,
);

const serverCurrentisDisabled = zoneCurrent?.children?.length === 1;

serverOperate.forEach((operate) => {
if (disabled) {
operate.disabled = disabled;
}
if (operate.value === 'deleteServer')
operate.disabled = serverCurrentisDisabled;
if (operate.value === 'restartServer')
operate.disabled = !supportStaticIPisDisabled;
});
return serverOperate;
};

const getClusterOperates = (
clusterOperateList: Topo.OperateTypeLabel,
Expand All @@ -151,6 +178,7 @@ export {
clusterOperate,
clusterOperateOfTenant,
getClusterOperates,
getServerOperateOfCluster,
getZoneOperateOfCluster,
getZoneOperateOfTenant,
serverOperate,
Expand Down
2 changes: 2 additions & 0 deletions ui/src/components/TopoComponent/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function getChildren(zoneList: any, tenantReplicas?: API.ReplicaDetailType[]) {
img: SERVER_IMG_MAP.get(server.status),
badgeImg: BADGE_IMG_MAP.get(server.status),
disable: temp.disable,
zone: zone.zone,
};
});
children.push(temp);
Expand All @@ -138,6 +139,7 @@ export const formatTopoData = (
defaultMessage: '集群',
}),
status: responseData.status,
supportStaticIP: responseData.supportStaticIP,
type: 'cluster',
children: [],
img: CLUSTER_IMG_MAP.get(responseData.status),
Expand Down
60 changes: 51 additions & 9 deletions ui/src/components/TopoComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Spin, message } from 'antd';
import _ from 'lodash';
import { ReactElement, useEffect, useMemo, useRef, useState } from 'react';

import { obcluster } from '@/api';
import OperateModal from '@/components/customModal/OperateModal';
import showDeleteConfirm from '@/components/customModal/showDeleteConfirm';
import { RESULT_STATUS } from '@/constants';
Expand All @@ -28,9 +29,9 @@ import { ReactNode, config } from './G6register';
import {
clusterOperate,
clusterOperateOfTenant,
getServerOperateOfCluster,
getZoneOperateOfCluster,
getZoneOperateOfTenant,
serverOperate,
} from './constants';
import {
appenAutoShapeListener,
Expand Down Expand Up @@ -91,6 +92,8 @@ export default function TopoComponent({
const preTopoData = useRef<any>(null);
//The zone name selected when clicking the more icon
const chooseZoneName = useRef<string>('');
//The Server/Zone name selected when clicking the more icon
const chooseServerName = useRef<string>('');
//Number of servers in the selected zone
const [chooseServerNum, setChooseServerNum] = useState<number>(1);
//If the topoData cluster status is operating, it needs to be polled.
Expand All @@ -106,7 +109,6 @@ export default function TopoComponent({
});
const clusterStatus = useRef(originTopoData?.basicInfo?.status);
const tenantStatus = useRef(status);

//Node more icon click event
const handleClick = (evt: IG6GraphEvent) => {
if (modelRef.current) {
Expand Down Expand Up @@ -149,7 +151,20 @@ export default function TopoComponent({
}

case 'server': {
setOprateList(serverOperate);
const disabled = tenantReplicas
? clusterStatus.current !== 'running' ||
tenantStatus.current !== 'running'
: clusterStatus.current !== 'running';
const server = evt.item?._cfg?.model?.label as string;
const serverZone = evt.item?._cfg?.model?.zone as string;
setOprateList(
getServerOperateOfCluster(
originTopoData?.topoData,
disabled,
serverZone,
),
);
chooseServerName.current = server;
break;
}
}
Expand Down Expand Up @@ -264,6 +279,27 @@ export default function TopoComponent({
}
};

const { runAsync: deleteOBServers } = useRequest(obcluster.deleteOBServers, {
manual: true,
onSuccess: (res) => {
if (res.successful) {
message.success('删除 Server 已成功');
}
},
});

const { runAsync: restartOBServers } = useRequest(
obcluster.restartOBServers,
{
manual: true,
onSuccess: (res) => {
if (res.successful) {
message.success('重启 Server 已成功');
}
},
},
);

/**
* Call up the operation and maintenance operation modal
*/
Expand Down Expand Up @@ -333,16 +369,22 @@ export default function TopoComponent({
}
if (operate === 'deleteServer') {
showDeleteConfirm({
title: '你确定要删除该server吗?',
// TODO
onOk: () => {},
title: '你确定要删除该 server 吗?',
onOk: () => {
deleteOBServers(ns!, name!, {
observers: [chooseServerName.current],
});
},
});
}
if (operate === 'restartServer') {
showDeleteConfirm({
title: '你确定重启该server吗?',
// TODO
onOk: () => {},
title: '你确定重启该 server 吗?',
onOk: () => {
restartOBServers(ns!, name!, {
observers: [chooseServerName.current],
});
},
});
}
};
Expand Down
1 change: 1 addition & 0 deletions ui/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const CLUSTER_INFO_CONFIG = [
'rootPasswordSecret',
'mode',
'parameters',
'deletionProtection',
];

const TOPO_INFO_CONFIG = [
Expand Down
17 changes: 10 additions & 7 deletions ui/src/pages/Cluster/Detail/Overview/BasicInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function BasicInfo({
monitor,
clusterName,
style,
addDeletionProtection,
deletionProtection,
}: API.ClusterInfo & { style?: React.CSSProperties; extra?: boolean }) {
const statusItem = findByValue(STATUS_LIST, status);
const statusDetailItem = findByValue(STATUS_LIST, statusDetail);
Expand Down Expand Up @@ -109,13 +109,16 @@ export default function BasicInfo({
<Descriptions.Item label={'删除保护'}>
<Checkbox
// loading 态禁止操作,防止重复操作
disabled={loading}
defaultChecked={addDeletionProtection}
disabled={loading || status !== 'running'}
defaultChecked={deletionProtection}
onChange={(e) => {
const body = {
addDeletionProtection: e.target.checked,
};
patchOBCluster(name, namespace, body);
const body = {} as API.ParamPatchOBClusterParam;
if (!e.target.checked) {
body.removeDeletionProtection = e.target.checked;
} else {
body.addDeletionProtection = e.target.checked;
}
patchOBCluster(namespace, name, body);
}}
/>
</Descriptions.Item>
Expand Down
13 changes: 9 additions & 4 deletions ui/src/pages/Cluster/Detail/Overview/NFSInfoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const NFSInfoModal: React.FC<NFSInfoModalProps> = ({
}) => {
const [form] = Form.useForm<FormData>();

const { validateFields, resetFields } = form;
const { runAsync: patchOBCluster, loading } = useRequest(
obcluster.patchOBCluster,
{
Expand All @@ -32,6 +33,7 @@ const NFSInfoModal: React.FC<NFSInfoModalProps> = ({
if (res.successful) {
message.success(`修改${title}成功`);
onSuccess();
resetFields();
}
},
},
Expand All @@ -42,24 +44,27 @@ const NFSInfoModal: React.FC<NFSInfoModalProps> = ({
title={title}
open={visible}
destroyOnClose
onCancel={() => onCancel()}
onCancel={() => {
onCancel();
resetFields();
}}
confirmLoading={loading}
onOk={() => {
if (removeNFS) {
const body = {
removeBackupVolume: true,
};
patchOBCluster(name, namespace, body);
patchOBCluster(namespace, name, body);
} else {
form.validateFields().then((values) => {
validateFields().then((values) => {
const { address, path } = values;
const body = {
backupVolume: {
address,
path,
},
};
patchOBCluster(name, namespace, body);
patchOBCluster(namespace, name, body);
});
}
}}
Expand Down
18 changes: 14 additions & 4 deletions ui/src/pages/Cluster/Detail/Overview/ParametersModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ParametersModal: React.FC<ParametersModalProps> = ({
namespace,
}) => {
const [form] = Form.useForm<API.CreateClusterData>();
const { validateFields } = form;
const { validateFields, resetFields } = form;

const { runAsync: updateParameters, loading } = useRequest(
obcluster.patchOBCluster,
Expand Down Expand Up @@ -50,11 +50,21 @@ const ParametersModal: React.FC<ParametersModalProps> = ({
})}
open={visible}
destroyOnClose
onCancel={() => onCancel()}
onCancel={() => {
onCancel();
resetFields();
}}
width={520}
footer={
<Space>
<Button onClick={onCancel}>取消</Button>
<Button
onClick={() => {
onCancel();
resetFields();
}}
>
取消
</Button>
<Button
type="primary"
loading={loading}
Expand All @@ -63,7 +73,7 @@ const ParametersModal: React.FC<ParametersModalProps> = ({
const objValue = {
modifiedParameters: [values],
};
updateParameters(name, namespace, objValue, `编辑参数已成功`);
updateParameters(namespace, name, objValue, `编辑参数已成功`);
});
}}
>
Expand Down
Loading

0 comments on commit 9738fcb

Please sign in to comment.