devabhishekpal commented on code in PR #7168: URL: https://github.com/apache/ozone/pull/7168#discussion_r1760682498
########## hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/v2/components/tables/datanodesTable.tsx: ########## @@ -0,0 +1,315 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ReplicationIcon } from '@/utils/themeIcons'; +import DecommissionSummary from '@/v2/components/decommissioningSummary/decommissioningSummary'; +import StorageBar from '@/v2/components/storageBar/storageBar'; +import { Datanode, DatanodeOpState, DatanodeOpStateList, DatanodeState, DatanodeStateList, DatanodeTableProps } from '@/v2/types/datanode.types'; +import { Pipeline } from '@/v2/types/pipelines.types'; +import { CheckCircleFilled, CloseCircleFilled, HourglassFilled, InfoCircleOutlined, WarningFilled } from '@ant-design/icons'; +import { Popover, Tooltip } from 'antd' +import Table, { ColumnsType, TablePaginationConfig } from 'antd/es/table'; +import { TableRowSelection } from 'antd/es/table/interface'; +import moment from 'moment'; +import React from 'react'; + +moment.updateLocale('en', { + relativeTime: { + past: '%s ago', + s: '%ds', + m: '1min', + mm: '%dmins', + h: '1hr', + hh: '%dhrs', + d: '1d', + dd: '%dd', + M: '1m', + MM: '%dm', + y: '1y', + yy: '%dy' + } +}); + +let decommissioningUuids: string | string[] = []; + +const headerIconStyles: React.CSSProperties = { + display: 'flex', + alignItems: 'center' +} + +const renderDatanodeState = (state: DatanodeState) => { + const stateIconMap = { + HEALTHY: <CheckCircleFilled twoToneColor='#1da57a' className='icon-success' />, + STALE: <HourglassFilled className='icon-warning' />, + DEAD: <CloseCircleFilled className='icon-failure' /> + }; + const icon = state in stateIconMap ? stateIconMap[state] : ''; + return <span>{icon} {state}</span>; +}; + +const renderDatanodeOpState = (opState: DatanodeOpState) => { + const opStateIconMap = { + IN_SERVICE: <CheckCircleFilled twoToneColor='#1da57a' className='icon-success' />, + DECOMMISSIONING: <HourglassFilled className='icon-warning' />, + DECOMMISSIONED: <WarningFilled className='icon-warning' />, + ENTERING_MAINTENANCE: <HourglassFilled className='icon-warning' />, + IN_MAINTENANCE: <WarningFilled className='icon-warning' /> + }; + const icon = opState in opStateIconMap ? opStateIconMap[opState] : ''; + return <span>{icon} {opState}</span>; +}; + +const getTimeDiffFromTimestamp = (timestamp: number): string => { + const timestampDate = new Date(timestamp); + return moment(timestampDate).fromNow(); +} + +export const COLUMNS: ColumnsType<Datanode> = [ + { + title: 'Hostname', + dataIndex: 'hostname', + key: 'hostname', + sorter: (a: Datanode, b: Datanode) => a.hostname.localeCompare( + b.hostname, undefined, { numeric: true } + ), + defaultSortOrder: 'ascend' as const + }, + { + title: 'State', + dataIndex: 'state', + key: 'state', + filterMultiple: true, + filters: DatanodeStateList.map(state => ({ text: state, value: state })), + onFilter: (value, record: Datanode) => record.state === value, + render: (text: DatanodeState) => renderDatanodeState(text), + sorter: (a: Datanode, b: Datanode) => a.state.localeCompare(b.state) + }, + { + title: 'Operational State', + dataIndex: 'opState', + key: 'opState', + filterMultiple: true, + filters: DatanodeOpStateList.map(state => ({ text: state, value: state })), + onFilter: (value, record: Datanode) => record.opState === value, + render: (text: DatanodeOpState) => renderDatanodeOpState(text), + sorter: (a: Datanode, b: Datanode) => a.opState.localeCompare(b.opState) + }, + { + title: 'UUID', + dataIndex: 'uuid', + key: 'uuid', + sorter: (a: Datanode, b: Datanode) => a.uuid.localeCompare(b.uuid), + defaultSortOrder: 'ascend' as const, + render: (uuid: string, record: Datanode) => { + return ( + //1. Compare Decommission Api's UUID with all UUID in table and show Decommission Summary + (decommissioningUuids && decommissioningUuids.includes(record.uuid) && record.opState !== 'DECOMMISSIONED') ? + <DecommissionSummary uuid={uuid} /> : <span>{uuid}</span> + ); + } + }, + { + title: 'Storage Capacity', + dataIndex: 'storageUsed', + key: 'storageUsed', + sorter: (a: Datanode, b: Datanode) => a.storageRemaining - b.storageRemaining, + render: (_: string, record: Datanode) => ( + <StorageBar + strokeWidth={6} + capacity={record.storageTotal} + used={record.storageUsed} + remaining={record.storageRemaining} + committed={record.storageCommitted} /> + ) + }, + { + title: 'Last Heartbeat', + dataIndex: 'lastHeartbeat', + key: 'lastHeartbeat', + sorter: (a: Datanode, b: Datanode) => moment(a.lastHeartbeat).unix() - moment(b.lastHeartbeat).unix(), + render: (heartbeat: number) => { + return heartbeat > 0 ? getTimeDiffFromTimestamp(heartbeat) : 'NA'; + } + }, + { + title: 'Pipeline ID(s)', + dataIndex: 'pipelines', + key: 'pipelines', + render: (pipelines: Pipeline[], record: Datanode) => { + const renderPipelineIds = (pipelineIds: Pipeline[]) => { + return pipelineIds?.map((pipeline: any, index: any) => ( + <div key={index} className='pipeline-container-v2'> + <ReplicationIcon + replicationFactor={pipeline.replicationFactor} + replicationType={pipeline.replicationType} + leaderNode={pipeline.leaderNode} + isLeader={pipeline.leaderNode === record.hostname} /> + {pipeline.pipelineID} + </div > + )) + } + + return ( + <Popover + content={ + renderPipelineIds(pipelines) + } + title="Related Pipelines" + placement="bottomLeft" + trigger="hover"> + <strong>{pipelines.length}</strong> pipelines + </Popover> + ); + } + }, + { + title: () => ( + <span style={headerIconStyles} > + Leader Count Review Comment: I believe we can go over the searchable fields. For leader count it was just a number and I didn't think it was useful making it searchable -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
