Skip to content

Commit e64c3b0

Browse files
fix: use DC and Rack from Location for nodes (#713)
1 parent ef1c75b commit e64c3b0

File tree

13 files changed

+49
-18
lines changed

13 files changed

+49
-18
lines changed

src/components/BasicNodeViewer/BasicNodeViewer.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cn from 'bem-cn-lite';
22

3-
import type {TSystemStateInfo} from '../../types/api/nodes';
43
import type {AdditionalNodesProps} from '../../types/additionalProps';
4+
import type {PreparedNode} from '../../store/reducers/node/types';
55

66
import EntityStatus from '../EntityStatus/EntityStatus';
77
import {Tags} from '../Tags';
@@ -12,7 +12,7 @@ import './BasicNodeViewer.scss';
1212
const b = cn('basic-node-viewer');
1313

1414
interface BasicNodeViewerProps {
15-
node: TSystemStateInfo;
15+
node: PreparedNode;
1616
additionalNodesProps?: AdditionalNodesProps;
1717
className?: string;
1818
}
@@ -44,7 +44,7 @@ export const BasicNodeViewer = ({node, additionalNodesProps, className}: BasicNo
4444
<label>{node.NodeId}</label>
4545
</div>
4646

47-
{node.DataCenter && <Tags tags={[node.DataCenter]} />}
47+
{node.DC && <Tags tags={[node.DC]} />}
4848
{node.Roles && <Tags tags={node.Roles} tagsType="blue" />}
4949
</>
5050
) : (

src/components/FullNodeViewer/FullNodeViewer.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import cn from 'bem-cn-lite';
22

3-
import type {TSystemStateInfo} from '../../types/api/nodes';
4-
3+
import type {PreparedNode} from '../../store/reducers/node/types';
54
import {LOAD_AVERAGE_TIME_INTERVALS} from '../../utils/constants';
65
import {calcUptime} from '../../utils/dataFormatters/dataFormatters';
76

@@ -14,7 +13,7 @@ import './FullNodeViewer.scss';
1413
const b = cn('full-node-viewer');
1514

1615
interface FullNodeViewerProps {
17-
node: TSystemStateInfo | undefined;
16+
node: PreparedNode | undefined;
1817
className?: string;
1918
}
2019

@@ -34,7 +33,7 @@ export const FullNodeViewer = ({node, className}: FullNodeViewerProps) => {
3433
commonInfo.push(
3534
{label: 'Version', value: node?.Version},
3635
{label: 'Uptime', value: calcUptime(node?.StartTime)},
37-
{label: 'DC', value: node?.DataCenterDescription},
36+
{label: 'DC', value: node?.DataCenterDescription || node?.DC},
3837
{label: 'Rack', value: node?.Rack},
3938
);
4039

src/containers/Node/Node.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ function Node(props: NodeProps) {
4343
const dispatch = useDispatch();
4444
const location = useLocation();
4545

46-
const {loading, wasLoaded, error, data} = useTypedSelector((state) => state.node);
47-
const node = data?.SystemStateInfo?.[0];
46+
const {loading, wasLoaded, error, data: node} = useTypedSelector((state) => state.node);
4847

4948
const match =
5049
useRouteMatch<{id: string; activeTab: string}>(routes.node) ?? Object.create(null);

src/containers/Nodes/getNodesColumns.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {GetNodeRefFunc} from '../../types/additionalProps';
1414
import {getLoadSeverityForNode} from '../../store/reducers/nodes/utils';
1515
import {UsageLabel} from '../../components/UsageLabel/UsageLabel';
1616
import {CellWithPopover} from '../../components/CellWithPopover/CellWithPopover';
17+
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
1718

1819
const NODES_COLUMNS_IDS = {
1920
NodeId: 'NodeId',
@@ -69,7 +70,7 @@ const dataCenterColumn: NodesColumn = {
6970
name: NODES_COLUMNS_IDS.DC,
7071
header: 'DC',
7172
align: DataTable.LEFT,
72-
render: ({row}) => (row.DataCenter ? row.DataCenter : '—'),
73+
render: ({row}) => row.DC || EMPTY_DATA_PLACEHOLDER,
7374
width: 60,
7475
};
7576

src/containers/Storage/StorageNodes/getStorageNodesColumns.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {Column as VirtualTableColumn} from '../../../components/VirtualTabl
66
import {VISIBLE_ENTITIES} from '../../../store/reducers/storage/constants';
77
import {NodeHostWrapper} from '../../../components/NodeHostWrapper/NodeHostWrapper';
88
import {isSortableNodesProperty} from '../../../utils/nodes';
9+
import {EMPTY_DATA_PLACEHOLDER} from '../../../utils/constants';
910

1011
import {PDisk} from '../PDisk/PDisk';
1112
import {b} from './shared';
@@ -47,7 +48,7 @@ const getStorageNodesColumns = (additionalNodesProps: AdditionalNodesProps | und
4748
name: STORAGE_NODES_COLUMNS_IDS.DC,
4849
header: 'DC',
4950
width: 100,
50-
render: ({row}) => row.DataCenter || '—',
51+
render: ({row}) => row.DC || EMPTY_DATA_PLACEHOLDER,
5152
align: DataTable.LEFT,
5253
},
5354
{

src/store/reducers/node/node.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Reducer} from 'redux';
33
import {createRequestActionTypes, createApiRequest} from '../../utils';
44

55
import type {NodeAction, NodeState} from './types';
6+
import {prepareNodeData} from './utils';
67

78
export const FETCH_NODE = createRequestActionTypes('node', 'FETCH_NODE');
89
export const FETCH_NODE_STRUCTURE = createRequestActionTypes('node', 'FETCH_NODE_STRUCTURE');
@@ -82,6 +83,7 @@ export const getNodeInfo = (id: string) => {
8283
return createApiRequest({
8384
request: window.api.getNodeInfo(id),
8485
actions: FETCH_NODE,
86+
dataHandler: prepareNodeData,
8587
});
8688
};
8789

src/store/reducers/node/selectors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
RawNodeStructure,
1111
} from './types';
1212

13-
const selectNodeId = (state: NodeStateSlice) => state.node?.data?.SystemStateInfo?.[0].NodeId;
13+
const selectNodeId = (state: NodeStateSlice) => state.node?.data?.NodeId;
1414

1515
const selectRawNodeStructure = (state: NodeStateSlice) => state.node?.nodeStructure;
1616

src/store/reducers/node/types.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {IResponseError} from '../../../types/api/error';
2+
import type {TSystemStateInfo} from '../../../types/api/nodes';
23
import type {TPDiskStateInfo} from '../../../types/api/pdisk';
34
import type {TStorageInfo} from '../../../types/api/storage';
4-
import type {TEvSystemStateResponse} from '../../../types/api/systemState';
55
import type {TVDiskStateInfo} from '../../../types/api/vdisk';
66
import type {ApiRequestAction} from '../../utils';
77

@@ -24,8 +24,13 @@ export interface PreparedStructurePDisk extends TPDiskStateInfo {
2424

2525
export type PreparedNodeStructure = Record<string, PreparedStructurePDisk>;
2626

27+
export interface PreparedNode extends TSystemStateInfo {
28+
DC?: string;
29+
Rack?: string;
30+
}
31+
2732
export interface NodeState {
28-
data: TEvSystemStateResponse;
33+
data: PreparedNode;
2934
loading: boolean;
3035
wasLoaded: boolean;
3136
error?: IResponseError;
@@ -37,7 +42,7 @@ export interface NodeState {
3742
}
3843

3944
export type NodeAction =
40-
| ApiRequestAction<typeof FETCH_NODE, TEvSystemStateResponse, IResponseError>
45+
| ApiRequestAction<typeof FETCH_NODE, PreparedNode, IResponseError>
4146
| ApiRequestAction<typeof FETCH_NODE_STRUCTURE, TStorageInfo, IResponseError>
4247
| ReturnType<typeof resetNode>;
4348

src/store/reducers/node/utils.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type {TEvSystemStateResponse} from '../../../types/api/systemState';
2+
import type {PreparedNode} from './types';
3+
4+
export const prepareNodeData = (data: TEvSystemStateResponse): PreparedNode => {
5+
if (!data.SystemStateInfo?.length) {
6+
return {};
7+
}
8+
9+
const nodeData = data.SystemStateInfo[0];
10+
11+
return {
12+
...nodeData,
13+
DC: nodeData.Location?.DataCenter,
14+
Rack: nodeData.Location?.Rack,
15+
};
16+
};

src/store/reducers/nodes/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface NodesPreparedEntity {
2727
NodeId: number;
2828
Host?: string;
2929
SystemState?: EFlag;
30-
DataCenter?: string;
30+
DC?: string;
3131
Rack?: string;
3232
Version?: string;
3333
TenantName?: string;

src/store/reducers/nodes/utils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const prepareComputeNode = (node: TComputeNodeInfo, tenantName?: string) => {
1212
TenantName: node.Tenant ?? tenantName,
1313
SystemState: node?.Overall,
1414
Uptime: calcUptime(node?.StartTime),
15+
16+
DC: node.DataCenter,
1517
};
1618
};
1719

@@ -60,6 +62,9 @@ export const prepareNodesData = (data: TNodesInfo): NodesHandledResponse => {
6062
Uptime: calcUptime(node.SystemState?.StartTime),
6163
TenantName: node.SystemState?.Tenants?.[0],
6264

65+
DC: node.SystemState.Location?.DataCenter,
66+
Rack: node.SystemState.Location?.Rack,
67+
6368
SharedCacheUsed: node.SystemState.SharedCacheStats?.UsedBytes,
6469
SharedCacheLimit: sharedCacheLimit,
6570
};

src/store/reducers/storage/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export interface PreparedStorageNode extends TSystemStateInfo {
3232
PDisks: TPDiskStateInfo[] | undefined;
3333
VDisks: TVDiskStateInfo[] | undefined;
3434

35+
DC?: string;
36+
Rack?: string;
37+
3538
Missing: number;
3639
Uptime: string;
3740
}

src/store/reducers/storage/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ const prepareStorageNodeData = (node: TNodeInfo): PreparedStorageNode => {
177177
return {
178178
NodeId: node.NodeId,
179179
SystemState: systemState.SystemState,
180-
DataCenter: systemState.DataCenter,
181-
Rack: systemState.Rack,
180+
DC: systemState.Location?.DataCenter,
181+
Rack: systemState.Location?.Rack,
182182
Host: systemState.Host,
183183
Endpoints: systemState.Endpoints,
184184
Uptime: calcUptime(systemState.StartTime),

0 commit comments

Comments
 (0)