Skip to content

Commit

Permalink
fix: use both BSC and Whiteboard for disks
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov committed Nov 1, 2024
1 parent 3287f99 commit 4f08ff4
Show file tree
Hide file tree
Showing 20 changed files with 976 additions and 163 deletions.
26 changes: 19 additions & 7 deletions src/components/PDiskPopup/PDiskPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {EFlag} from '../../types/api/enums';
import {valueIsDefined} from '../../utils';
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import {getPDiskId} from '../../utils/disks/helpers';
import type {PreparedPDisk} from '../../utils/disks/types';
import {useTypedSelector} from '../../utils/hooks';
import {bytesToGB} from '../../utils/utils';
Expand All @@ -21,12 +20,23 @@ export const preparePDiskData = (
nodeHost?: string,
withDeveloperUILink?: boolean,
) => {
const {AvailableSize, TotalSize, State, PDiskId, NodeId, Path, Realtime, Type, Device} = data;
const {
AvailableSize,
TotalSize,
State,
PDiskId,
NodeId,
StringifiedId,
Path,
Realtime,
Type,
Device,
} = data;

const pdiskData: InfoViewerItem[] = [
{
label: 'PDisk',
value: getPDiskId(NodeId, PDiskId) ?? EMPTY_DATA_PLACEHOLDER,
value: StringifiedId ?? EMPTY_DATA_PLACEHOLDER,
},
{label: 'State', value: State || 'not available'},
{label: 'Type', value: Type || 'unknown'},
Expand All @@ -44,10 +54,12 @@ export const preparePDiskData = (
pdiskData.push({label: 'Path', value: Path});
}

pdiskData.push({
label: 'Available',
value: `${bytesToGB(AvailableSize)} of ${bytesToGB(TotalSize)}`,
});
if (!isNaN(Number(TotalSize))) {
pdiskData.push({
label: 'Available',
value: `${bytesToGB(AvailableSize)} of ${bytesToGB(TotalSize)}`,
});
}

if (Realtime && errorColors.includes(Realtime)) {
pdiskData.push({label: 'Realtime', value: Realtime});
Expand Down
16 changes: 1 addition & 15 deletions src/components/VDiskPopup/VDiskPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {EFlag} from '../../types/api/enums';
import {valueIsDefined} from '../../utils';
import {cn} from '../../utils/cn';
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
import {stringifyVdiskId} from '../../utils/dataFormatters/dataFormatters';
import {createVDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import {isFullVDiskData} from '../../utils/disks/helpers';
import type {PreparedVDisk, UnavailableDonor} from '../../utils/disks/types';
Expand Down Expand Up @@ -203,22 +202,9 @@ export const VDiskPopup = ({data}: VDiskPopupProps) => {
if ('Donors' in data && data.Donors) {
const donors = data.Donors;
for (const donor of donors) {
const isFullDonorData = isFullVDiskData(donor);
donorsInfo.push({
label: 'VDisk',
value: (
<InternalLink to={getVDiskLink(donor)}>
{stringifyVdiskId(
isFullDonorData
? donor.VDiskId
: {
NodeId: donor.NodeId,
PDiskId: donor.PDiskId,
VSlotId: donor.VSlotId,
},
)}
</InternalLink>
),
value: <InternalLink to={getVDiskLink(donor)}>{donor.StringifiedId}</InternalLink>,
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/containers/Storage/Disks/Disks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {Flex, useLayoutContext} from '@gravity-ui/uikit';
import {VDisk} from '../../../components/VDisk/VDisk';
import {valueIsDefined} from '../../../utils';
import {cn} from '../../../utils/cn';
import {getPDiskId} from '../../../utils/disks/helpers';
import type {PreparedVDisk} from '../../../utils/disks/types';
import {PDisk} from '../PDisk';
import type {StorageViewContext} from '../types';
Expand Down Expand Up @@ -54,7 +53,7 @@ export function Disks({vDisks = [], viewContext}: DisksProps) {
<div className={b('pdisks-wrapper')}>
{vDisks?.map((vDisk) => (
<PDiskItem
key={getPDiskId(vDisk.NodeId, vDisk?.PDisk?.PDiskId)}
key={vDisk?.PDisk?.StringifiedId}
vDisk={vDisk}
highlightedVDisk={highlightedVDisk}
setHighlightedVDisk={setHighlightedVDisk}
Expand Down
9 changes: 4 additions & 5 deletions src/store/reducers/node/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {createSelector} from '@reduxjs/toolkit';

import {stringifyVdiskId} from '../../../utils/dataFormatters/dataFormatters';
import {preparePDiskData, prepareVDiskData} from '../../../utils/disks/prepareDisks';
import {prepareWhiteboardVDiskData} from '../../../utils/disks/prepareDisks';
import type {RootState} from '../../defaultStore';

import {nodeApi} from './node';
Expand Down Expand Up @@ -29,14 +29,13 @@ export const selectNodeStructure = createSelector(
const groups = pool.Groups;
groups?.forEach((group) => {
const vDisks = group.VDisks?.filter((el) => el.NodeId === nodeId).map(
prepareVDiskData,
prepareWhiteboardVDiskData,
);
vDisks?.forEach((vd) => {
const vDiskId = stringifyVdiskId(vd.VDiskId);
const preparedPDisk = preparePDiskData(vd.PDisk);
const pDiskId = preparedPDisk.PDiskId;
const pDiskId = vd.PDisk?.PDiskId;
if (!structure[String(pDiskId)]) {
structure[String(pDiskId)] = {vDisks: {}, ...preparedPDisk};
structure[String(pDiskId)] = {vDisks: {}, ...vd.PDisk};
}
structure[String(pDiskId)].vDisks[vDiskId] = {
...vd,
Expand Down
7 changes: 3 additions & 4 deletions src/store/reducers/node/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type {TVDiskStateInfo} from '../../../types/api/vdisk';
import type {PreparedPDisk} from '../../../utils/disks/types';
import type {PreparedPDisk, PreparedVDisk} from '../../../utils/disks/types';
import type {PreparedNodeSystemState} from '../../../utils/nodes';

interface RawStructurePDisk extends PreparedPDisk {
vDisks: Record<string, TVDiskStateInfo>;
vDisks: Record<string, PreparedVDisk>;
}

export type RawNodeStructure = Record<string, RawStructurePDisk>;

export interface PreparedStructureVDisk extends TVDiskStateInfo {
export interface PreparedStructureVDisk extends PreparedVDisk {
id: string;
order: number;
}
Expand Down
14 changes: 11 additions & 3 deletions src/store/reducers/pdisk/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type {TPDiskInfoResponse} from '../../../types/api/pdisk';
import type {TEvSystemStateResponse} from '../../../types/api/systemState';
import {getArray, valueIsDefined} from '../../../utils';
import {preparePDiskData, prepareVDiskData} from '../../../utils/disks/prepareDisks';
import {
prepareWhiteboardPDiskData,
prepareWhiteboardVDiskData,
} from '../../../utils/disks/prepareDisks';
import {prepareNodeSystemState} from '../../../utils/nodes';

import type {PDiskData, SlotItem} from './types';
Expand All @@ -18,7 +21,10 @@ export function preparePDiskDataResponse([pdiskResponse = {}, nodeResponse]: [
const {PDisk: WhiteboardPDiskData = {}, VDisks: WhiteboardVDisksData = []} = Whiteboard;
const {PDisk: BSCPDiskData = {}} = BSC;

const preparedPDisk = preparePDiskData(WhiteboardPDiskData, BSCPDiskData);
const preparedPDisk = prepareWhiteboardPDiskData({
...BSCPDiskData,
...WhiteboardPDiskData,
});

const NodeId = preparedPDisk.NodeId ?? preparedNode.NodeId;

Expand Down Expand Up @@ -48,7 +54,9 @@ export function preparePDiskDataResponse([pdiskResponse = {}, nodeResponse]: [
};
}

const preparedVDisks = WhiteboardVDisksData.map((disk) => prepareVDiskData({...disk, NodeId}));
const preparedVDisks = WhiteboardVDisksData.map((disk) =>
prepareWhiteboardVDiskData({...disk, NodeId}),
);
preparedVDisks.sort((disk1, disk2) => Number(disk2.VDiskSlotId) - Number(disk1.VDiskSlotId));

const vdisksSlots: SlotItem<'vDisk'>[] = preparedVDisks.map((preparedVDisk) => {
Expand Down
Loading

0 comments on commit 4f08ff4

Please sign in to comment.