import React, { useState, useEffect, useRef } from 'react'; import { Select, Form, Utils, AppContainer, Input, Button, ProTable, Badge, Tag, SearchInput, Divider } from 'knowdesign'; import { IconFont } from '@knowdesign/icons'; import BalanceDrawer from './BalanceDrawer'; import HistoryDrawer from './HistoryDrawer'; import DBreadcrumb from 'knowdesign/es/extend/d-breadcrumb'; import { getSizeAndUnit } from '../../constants/common'; import api from '../../api'; import './index.less'; import LoadRebalanceCardBar from '@src/components/CardBar/LoadRebalanceCardBar'; import { BalanceFilter } from './BalanceFilter'; import { ClustersPermissionMap } from '../CommonConfig'; import { tableHeaderPrefix } from '@src/constants/common'; const Balance_Status_OPTIONS = [ { label: '全部', value: null, }, { label: '已均衡', value: 0, }, { label: '未均衡', value: 2, }, ]; const balanceStatus: any = { 0: '已均衡', 2: '未均衡', }; const filterNorms: any = { ['disk']: 'Disk', ['bytesIn']: 'Byte In', ['bytesOut']: 'Byte Out', }; export const defaultPagination = { current: 1, pageSize: 10, position: 'bottomRight', showSizeChanger: true, pageSizeOptions: ['10', '20', '50', '100'], }; const LoadBalance: React.FC = (props: any) => { const [global] = AppContainer.useGlobalValue(); const [form] = Form.useForm(); const [pagination, setPagination] = useState(defaultPagination); const [loading, setLoading] = useState(true); const [data, setData] = useState([]); const [visible, setVisible] = useState(false); const [isCycle, setIsCycle] = useState(false); const [planVisible, setPlanVisible] = useState(false); const [circleFormData, setCircleFormData] = useState(null); const [trigger, setTrigger] = useState(false); const [filterList, setFilterList] = useState(null); const [balanceList, setBalanceList] = useState(null); const [searchKeywords, setSearchKeywords] = useState(''); const [searchValue, setSearchValue] = useState(''); const columns = () => [ { title: 'Broker ID', dataIndex: 'brokerId', key: 'brokerId', fixed: 'left', width: 140, }, { title: 'Host', dataIndex: 'host', key: 'host', width: 140, }, { title: 'Leader', dataIndex: 'leader', key: 'leader', width: 100, }, { title: 'Replicas', dataIndex: 'replicas', key: 'replicas', width: 100, }, // { // title: 'CPU', // children: [ // { // title: '规格', // dataIndex: 'cpu_spec', // key: 'cpu_spec', // render: (text: any, row: any) => { // return text !== null ? `${text}` : '-'; // }, // }, // { // title: 'AVG', // dataIndex: 'cpu_avg', // key: 'cpu_avg', // render: (text: any, row: any) => { // return text !== null ? `${text} (${(row.cpu_avg * 100 / row.cpu_spec).toFixed(2)}%)` : '-'; // }, // }, // { // title: '是否均衡', // dataIndex: 'cpu_status', // key: 'cpu_status', // render: (text: any, row: any) => { // // 0:已均衡,非0:未均衡 // return text !== null ? (text === 0 ? ( // // 已均衡 // // ) : ( // // 未均衡 // // )) : '-'; // }, // }, // ], // }, { title: 'Disk规格', dataIndex: 'disk_spec', key: 'disk_spec', width: '150px', render: (text: any, row: any) => { return text !== null ? `${text.toLocaleString()}GB` : '-'; }, }, { title: 'Disk AVG', dataIndex: 'disk_avg', key: 'disk_avg', width: '200px', render: (text: any, row: any) => { return text !== null ? ( {`${getSizeAndUnit(text, 'B').valueWithUnit.toLocaleString()} (${( (row.disk_avg * 100) / Utils.transGBToB(row.disk_spec) ).toFixed(2)}%)`} ) : ( '-' ); }, }, { title: 'BytesIn规格', dataIndex: 'bytesIn_spec', key: 'bytesIn_spec', width: '150px', render: (text: any, row: any) => { return text !== null ? `${text.toLocaleString()}MB/s` : '-'; }, }, { title: 'BytesIn AVG', dataIndex: 'bytesIn_avg', key: 'bytesIn_avg', width: '200px', render: (text: any, row: any) => { return text !== null ? ( {`${getSizeAndUnit(text, 'B/s').valueWithUnit.toLocaleString()} (${( (row.bytesIn_avg * 100) / (row.bytesIn_spec * 1024 * 1024) ).toFixed(2)}%)`} ) : ( '-' ); }, }, { title: 'BytesOut规格', dataIndex: 'bytesOut_spec', key: 'bytesOut_spec', width: '150px', render: (text: any, row: any) => { return text !== null ? `${text.toLocaleString()}MB/s` : '-'; }, }, { title: 'BytesOut AVG', dataIndex: 'bytesOut_avg', key: 'bytesOut_avg', width: '200px', // eslint-disable-next-line react/display-name render: (text: any, row: any) => { return text !== null ? ( {`${getSizeAndUnit(text, 'B/s').valueWithUnit.toLocaleString()} (${( (row.bytesOut_avg * 100) / (row.bytesOut_spec * 1024 * 1024) ).toFixed(2)}%)`} ) : ( '-' ); }, }, ]; useEffect(() => { getList(); }, []); const onTableChange = (curPagination: any) => { setPagination({ ...curPagination, }); getList({ pageNo: curPagination.current, pageSize: curPagination.pageSize }); }; const resetList = () => { setPagination({ ...pagination, pageNo: 1, }); getList(); }; const hostSearch = (e: any) => { setFilterList([]); setPagination({ ...pagination, pageNo: 1, }); setSearchKeywords(e); getList({ searchKeywords: e, stateParam: balanceList }); }; const getList = (query = {}) => { const formData = form.getFieldsValue(); const queryParams = { pageNo: pagination.current, pageSize: pagination.pageSize, ...formData, ...query, }; setLoading(true); Utils.request(api.getBalanceList(global?.clusterInfo?.id), { method: 'POST', data: queryParams, }).then( (res: any) => { const { pageNo, pageSize, pages, total } = res.pagination; setPagination({ ...pagination, current: pageNo, pageSize, total, }); const dataDe = res?.bizData || []; const dataHandle = dataDe.map((item: any) => { return { ...item, cpu_spec: item?.sub?.cpu?.spec, cpu_avg: item?.sub?.cpu?.avg, cpu_status: item?.sub?.cpu?.status, disk_spec: item?.sub?.disk?.spec, disk_avg: item?.sub?.disk?.avg, disk_status: item?.sub?.disk?.status, bytesIn_spec: item?.sub?.bytesIn?.spec, bytesIn_avg: item?.sub?.bytesIn?.avg, bytesIn_status: item?.sub?.bytesIn?.status, bytesOut_spec: item?.sub?.bytesOut?.spec, bytesOut_avg: item?.sub?.bytesOut?.avg, bytesOut_status: item?.sub?.bytesOut?.status, }; }); setData(dataHandle); setLoading(false); }, () => setLoading(false) ); }; const drawerClose = (sure?: boolean) => { if (sure) { setTrigger(!trigger); } setVisible(false); }; const balanceClick = (val: boolean) => { Utils.request(api.getBalanceForm(global?.clusterInfo?.id), { method: 'GET', }) .then((res: any) => { const dataDe = res || {}; setCircleFormData(dataDe); }) .catch(() => { setCircleFormData(null); }); setIsCycle(val); setVisible(true); }; const getNorms = (stateParamArr: any) => { const stateParam: any = {}; stateParamArr.forEach((item: any) => { stateParam[item.firstLevel] = item.secondLevel; }); setFilterList(stateParamArr); setPagination({ ...pagination, pageNo: 1, }); setBalanceList(stateParam); getList({ searchKeywords, stateParam }); }; const filterNormsClose = (rowId: any) => { const newFilterList = filterList.filter((item: any) => item.id !== rowId); getNorms(newFilterList); }; return ( <>
getList({ searchKeywords: searchValue, stateParam: balanceList })} >
{/*
*/}
{global.hasPermission(ClustersPermissionMap.REBALANCE_CYCLE) && ( )} {global.hasPermission(ClustersPermissionMap.REBALANCE_IMMEDIATE) && ( )}
{filterList && filterList.length > 0 && (
筛选结果:{pagination?.total || 0}条 {filterList.map((item: any) => { return ( filterNormsClose(item.id)} > {filterNorms[item.firstLevel]}: {balanceStatus[item.secondLevel]} ); })}
)}
{planVisible && ( { setPlanVisible(false); }} /> )}
); }; export default LoadBalance;