ArafatKhan2198 commented on code in PR #7168: URL: https://github.com/apache/ozone/pull/7168#discussion_r1760666562
########## 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 + <Tooltip + title='The number of Ratis Pipelines in which the given datanode is elected as a leader.' > + <InfoCircleOutlined style={{ paddingLeft: '4px' }} /> + </Tooltip> + </span> + ), + dataIndex: 'leaderCount', + key: 'leaderCount', + sorter: (a: Datanode, b: Datanode) => a.leaderCount - b.leaderCount + }, + { + title: 'Containers', + dataIndex: 'containers', + key: 'containers', + sorter: (a: Datanode, b: Datanode) => a.containers - b.containers + }, + { + title: () => ( + <span style={headerIconStyles}> + Open Container + <Tooltip title='The number of open containers per pipeline.'> + <InfoCircleOutlined style={{ paddingLeft: '4px' }} /> + </Tooltip> + </span> + ), + dataIndex: 'openContainers', + key: 'openContainers', + sorter: (a: Datanode, b: Datanode) => a.openContainers - b.openContainers + }, + { + title: 'Version', Review Comment: We will also need to add search functionality for the Version column in the new UI. ########## 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: In the old UI, we had a searchable Leader Count column, but in the new UI, this search functionality is missing. The same applies to the Container ID column. <img width="471" alt="image" src="https://github.com/user-attachments/assets/a999b5ce-d212-4763-a3b7-3334bf12b155"> ########## 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 + <Tooltip + title='The number of Ratis Pipelines in which the given datanode is elected as a leader.' > + <InfoCircleOutlined style={{ paddingLeft: '4px' }} /> + </Tooltip> + </span> + ), + dataIndex: 'leaderCount', + key: 'leaderCount', + sorter: (a: Datanode, b: Datanode) => a.leaderCount - b.leaderCount + }, + { + title: 'Containers', + dataIndex: 'containers', + key: 'containers', + sorter: (a: Datanode, b: Datanode) => a.containers - b.containers + }, + { + title: () => ( + <span style={headerIconStyles}> + Open Container + <Tooltip title='The number of open containers per pipeline.'> + <InfoCircleOutlined style={{ paddingLeft: '4px' }} /> + </Tooltip> + </span> + ), + dataIndex: 'openContainers', + key: 'openContainers', + sorter: (a: Datanode, b: Datanode) => a.openContainers - b.openContainers + }, + { + title: 'Version', + dataIndex: 'version', + key: 'version', + sorter: (a: Datanode, b: Datanode) => a.version.localeCompare(b.version), + defaultSortOrder: 'ascend' as const + }, + { + title: 'Setup Time', + dataIndex: 'setupTime', + key: 'setupTime', + sorter: (a: Datanode, b: Datanode) => a.setupTime - b.setupTime, + render: (uptime: number) => { + return uptime > 0 ? moment(uptime).format('ll LTS') : 'NA'; + } + }, + { + title: 'Revision', Review Comment: I’m not sure if the searchable Revision field is useful in its current form. <img width="1139" alt="image" src="https://github.com/user-attachments/assets/0dbb2c01-7e18-4f14-a4b6-588a3e743f14"> ########## 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 + <Tooltip + title='The number of Ratis Pipelines in which the given datanode is elected as a leader.' > + <InfoCircleOutlined style={{ paddingLeft: '4px' }} /> + </Tooltip> + </span> + ), + dataIndex: 'leaderCount', + key: 'leaderCount', + sorter: (a: Datanode, b: Datanode) => a.leaderCount - b.leaderCount + }, + { + title: 'Containers', + dataIndex: 'containers', + key: 'containers', + sorter: (a: Datanode, b: Datanode) => a.containers - b.containers + }, + { + title: () => ( + <span style={headerIconStyles}> + Open Container + <Tooltip title='The number of open containers per pipeline.'> + <InfoCircleOutlined style={{ paddingLeft: '4px' }} /> + </Tooltip> + </span> + ), + dataIndex: 'openContainers', + key: 'openContainers', + sorter: (a: Datanode, b: Datanode) => a.openContainers - b.openContainers + }, + { + title: 'Version', + dataIndex: 'version', + key: 'version', + sorter: (a: Datanode, b: Datanode) => a.version.localeCompare(b.version), + defaultSortOrder: 'ascend' as const + }, + { + title: 'Setup Time', + dataIndex: 'setupTime', + key: 'setupTime', + sorter: (a: Datanode, b: Datanode) => a.setupTime - b.setupTime, + render: (uptime: number) => { + return uptime > 0 ? moment(uptime).format('ll LTS') : 'NA'; + } + }, + { + title: 'Revision', Review Comment: Let’s discuss offline whether these additional search functionalities are required for certain columns, or if we should limit it to only the use cases where it is really necessary and will assist users in debugging. ########## 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 don’t think adding a search feature for Leader Count is necessary, but I do believe having a search option for Container ID is important. While debugging, we need to be able to identify which node contains a problematic container. It turns out that the search feature for the Container ID column was faulty and didn’t work correctly in the old UI. ########## 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 + <Tooltip + title='The number of Ratis Pipelines in which the given datanode is elected as a leader.' > + <InfoCircleOutlined style={{ paddingLeft: '4px' }} /> + </Tooltip> + </span> + ), + dataIndex: 'leaderCount', + key: 'leaderCount', + sorter: (a: Datanode, b: Datanode) => a.leaderCount - b.leaderCount + }, + { + title: 'Containers', + dataIndex: 'containers', + key: 'containers', + sorter: (a: Datanode, b: Datanode) => a.containers - b.containers + }, + { + title: () => ( + <span style={headerIconStyles}> + Open Container + <Tooltip title='The number of open containers per pipeline.'> + <InfoCircleOutlined style={{ paddingLeft: '4px' }} /> + </Tooltip> + </span> + ), + dataIndex: 'openContainers', + key: 'openContainers', + sorter: (a: Datanode, b: Datanode) => a.openContainers - b.openContainers + }, + { + title: 'Version', + dataIndex: 'version', + key: 'version', + sorter: (a: Datanode, b: Datanode) => a.version.localeCompare(b.version), + defaultSortOrder: 'ascend' as const + }, + { + title: 'Setup Time', + dataIndex: 'setupTime', + key: 'setupTime', + sorter: (a: Datanode, b: Datanode) => a.setupTime - b.setupTime, + render: (uptime: number) => { + return uptime > 0 ? moment(uptime).format('ll LTS') : 'NA'; + } + }, + { + title: 'Revision', + dataIndex: 'revision', + key: 'revision', + sorter: (a: Datanode, b: Datanode) => a.revision.localeCompare(b.revision), + defaultSortOrder: 'ascend' as const + }, + { + title: 'Build Date', + dataIndex: 'buildDate', + key: 'buildDate', + sorter: (a: Datanode, b: Datanode) => a.buildDate.localeCompare(b.buildDate), + defaultSortOrder: 'ascend' as const + }, + { + title: 'Network Location', + dataIndex: 'networkLocation', + key: 'networkLocation', + sorter: (a: Datanode, b: Datanode) => a.networkLocation.localeCompare(b.networkLocation), + defaultSortOrder: 'ascend' as const + } +]; + +const DatanodesTable: React.FC<DatanodeTableProps> = ({ + data, + handleSelectionChange, + decommissionUuids, + selectedColumns, + loading = false, + selectedRows = [], + searchColumn = 'hostname', Review Comment: This issue is present in both the old and new UI: if a user accidentally adds a space at the end of their search input, the search doesn’t work. While it’s not a critical issue, we could remove any unnecessary spaces from the search input automatically. It’s a small improvement, but I noticed it when I was testing the search functionality. This issue is present in both the old and new UI: if a user accidentally adds a space at the end of their search input, the search doesn’t work. While it’s not a critical issue, we could remove any unnecessary spaces from the search input automatically. It’s a small improvement, but I noticed it when I was testing the search functionality. This issue is present in both the old and new UI: if a user accidentally adds a space at the end of their search input, the search doesn’t work. While it’s not a critical issue, we could remove any unnecessary spaces from the search input automatically. It’s a small improvement, but I noticed it when I was testing the search functionality. <img width="1016" alt="image" src="https://github.com/user-attachments/assets/9566f1bc-f1d6-466f-8e55-258420a200e2"> ########## hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/v2/pages/datanodes/datanodes.tsx: ########## @@ -0,0 +1,312 @@ +/* + * 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 React, { + useEffect, + useRef, + useState +} from 'react'; +import moment from 'moment'; +import { AxiosError } from 'axios'; +import { + Button, + Modal +} from 'antd'; +import { + DeleteOutlined, + WarningFilled, +} from '@ant-design/icons'; +import { ValueType } from 'react-select'; + +import Search from '@/v2/components/search/search'; +import MultiSelect, { Option } from '@/v2/components/select/multiSelect'; +import DatanodesTable, { COLUMNS } from '@/v2/components/tables/datanodesTable'; +import AutoReloadPanel from '@/components/autoReloadPanel/autoReloadPanel'; +import { showDataFetchError } from '@/utils/common'; +import { AutoReloadHelper } from '@/utils/autoReloadHelper'; +import { + AxiosGetHelper, + AxiosPutHelper, + cancelRequests +} from '@/utils/axiosRequestHelper'; + +import { useDebounce } from '@/v2/hooks/debounce.hook'; +import { + Datanode, + DatanodeDecomissionInfo, + DatanodeResponse, + DatanodesResponse, + DatanodesState +} from '@/v2/types/datanode.types'; + +import './datanodes.less' + + +const defaultColumns = COLUMNS.map(column => ({ + label: (typeof column.title === 'string') + ? column.title + : (column.title as Function)().props.children[0], + value: column.key as string +})); + +const SearchableColumnOpts = [{ + label: 'Hostname', + value: 'hostname' +}, { + label: 'UUID', + value: 'uuid' +}, { + label: 'Version', + value: 'version' +}, { + label: 'Revision', + value: 'revision' +}]; + +let decommissionUuids: string | string[] = []; +const COLUMN_UPDATE_DECOMMISSIONING = 'DECOMMISSIONING'; + +const Datanodes: React.FC<{}> = () => { + + const cancelSignal = useRef<AbortController>(); + const cancelDecommissionSignal = useRef<AbortController>(); + + const [state, setState] = useState<DatanodesState>({ + lastUpdated: 0, + columnOptions: defaultColumns, + dataSource: [] + }); + const [loading, setLoading] = useState<boolean>(false); + const [selectedColumns, setSelectedColumns] = useState<Option[]>(defaultColumns); + const [selectedRows, setSelectedRows] = useState<React.Key[]>([]); + const [searchTerm, setSearchTerm] = useState<string>(''); + const [searchColumn, setSearchColumn] = useState<'hostname' | 'uuid' | 'version' | 'revision'>('hostname'); + const [modalOpen, setModalOpen] = useState<boolean>(false); + + const debouncedSearch = useDebounce(searchTerm, 300); + + function handleColumnChange(selected: ValueType<Option, true>) { + setSelectedColumns(selected as Option[]); + } + + async function loadDecommisionAPI() { + decommissionUuids = []; + const { request, controller } = await AxiosGetHelper( + '/api/v1/datanodes/decommission/info', + cancelDecommissionSignal.current + ); + cancelDecommissionSignal.current = controller; + return request + }; + + async function loadDataNodeAPI() { + const { request, controller } = await AxiosGetHelper( + '/api/v1/datanodes', + cancelSignal.current + ); + cancelSignal.current = controller; + return request; + }; + + async function removeDatanode(selectedRowKeys: string[]) { + setLoading(true); + const { request, controller } = await AxiosPutHelper( + '/api/v1/datanodes/remove', + selectedRowKeys, + cancelSignal.current + ); + cancelSignal.current = controller; + request.then(() => { + loadData(); + }).catch((error) => { + showDataFetchError(error.toString()); + }).finally(() => { + setLoading(false); + setSelectedRows([]); + }); + } + + const loadData = async () => { + setLoading(true); + // Need to call decommission API on each interval to get updated status + // before datanode API call to compare UUID's + // update 'Operation State' column in table manually before rendering + try { + let decomissionResponse = await loadDecommisionAPI(); + decommissionUuids = decomissionResponse.data?.DatanodesDecommissionInfo?.map( + (item: DatanodeDecomissionInfo) => item.datanodeDetails.uuid + ); + } catch (error) { + decommissionUuids = []; + showDataFetchError((error as AxiosError).toString()); + } + + try { + const datanodesAPIResponse = await loadDataNodeAPI(); + const datanodesResponse: DatanodesResponse = datanodesAPIResponse.data; + const datanodes: DatanodeResponse[] = datanodesResponse.datanodes; + const dataSource: Datanode[] = datanodes?.map( + (datanode) => ({ + hostname: datanode.hostname, + uuid: datanode.uuid, + state: datanode.state, + opState: (decommissionUuids?.includes(datanode.uuid) && datanode.opState !== 'DECOMMISSIONED') + ? COLUMN_UPDATE_DECOMMISSIONING + : datanode.opState, + lastHeartbeat: datanode.lastHeartbeat, + storageUsed: datanode.storageReport.used, + storageTotal: datanode.storageReport.capacity, + storageCommitted: datanode.storageReport.committed, + storageRemaining: datanode.storageReport.remaining, + pipelines: datanode.pipelines, + containers: datanode.containers, + openContainers: datanode.openContainers, + leaderCount: datanode.leaderCount, + version: datanode.version, + setupTime: datanode.setupTime, + revision: datanode.revision, + buildDate: datanode.buildDate, + networkLocation: datanode.networkLocation + }) + ); + setLoading(false); + setState({ + ...state, + dataSource: dataSource, + lastUpdated: Number(moment()) + }); + } catch (error) { + setLoading(false); + showDataFetchError((error as AxiosError).toString()) + } + } + + const autoReloadHelper: AutoReloadHelper = new AutoReloadHelper(loadData); + + useEffect(() => { + autoReloadHelper.startPolling(); + loadData(); + + return (() => { + autoReloadHelper.stopPolling(); + cancelRequests([ + cancelSignal.current!, + cancelDecommissionSignal.current! + ]); + }); + }, []); + + function handleSelectionChange(rows: React.Key[]) { + setSelectedRows(rows); + } + + function handleModalOk() { + setModalOpen(false); + removeDatanode(selectedRows as string[]) + }; + + function handleModalCancel() { + setModalOpen(false); + setSelectedRows([]); + }; + + const { dataSource, lastUpdated, columnOptions } = state; + + return ( + <> + <div className='page-header-v2'> + Datanodes + <AutoReloadPanel + isLoading={loading} + lastRefreshed={lastUpdated} + togglePolling={autoReloadHelper.handleAutoReloadToggle} + onReload={loadData} /> + </div> + <div style={{ padding: '24px' }}> + <div className='content-div'> + <div className='table-header-section'> + <div className='table-filter-section'> + <MultiSelect + options={columnOptions} + defaultValue={selectedColumns} + selected={selectedColumns} + placeholder='Columns' + onChange={handleColumnChange} + onTagClose={() => { }} + fixedColumn='hostname' + columnLength={columnOptions.length} /> + {selectedRows.length > 0 && + <Button + type="primary" + icon={<DeleteOutlined />} + style={{ + background: '#FF4D4E', + borderColor: '#FF4D4E' + }} + loading={loading} + onClick={() => { setModalOpen(true) }}> Remove + </Button> + } + </div> + <Search + disabled={dataSource?.length < 1} + searchOptions={SearchableColumnOpts} + searchInput={searchTerm} + searchColumn={searchColumn} + onSearchChange={ + (e: React.ChangeEvent<HTMLInputElement>) => setSearchTerm(e.target.value) + } + onChange={(value) => { + setSearchTerm(''); + setSearchColumn(value as 'hostname' | 'uuid' | 'version' | 'revision') + }} /> + </div> + <DatanodesTable + loading={loading} + data={dataSource} + selectedColumns={selectedColumns} + selectedRows={selectedRows} + searchColumn={searchColumn} + searchTerm={debouncedSearch} + handleSelectionChange={handleSelectionChange} + decommissionUuids={decommissionUuids} /> + </div> + </div> + <Modal + title='' + centered={true} + visible={modalOpen} + onOk={handleModalOk} + onCancel={handleModalCancel} + closable={false} + width={400} > + <div style={{ + margin: '0px 0px 5px 0px', + fontSize: '16px', + fontWeight: 'bold' + }}> + <WarningFilled className='icon-warning' style={{paddingRight: '8px'}}/> + Stop Tracking Datanode + </div> + Are you sure, you want recon to stop tracking the selected <strong>{selectedRows.length}</strong> datanode(s)? Review Comment: Another issue I encountered is that when all datanodes are removed from the list (e.g., by shutting them down), the new UI crashes and displays an error. This behavior wasn’t present in the old UI, which handled this case by showing an empty list. <img width="944" alt="image" src="https://github.com/user-attachments/assets/36d59162-b4a1-4cd5-97fe-6a8c68a843dc"> -- 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]
