Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use both BSC and Whiteboard for disks #1564

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/components/PDiskPopup/PDiskPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ 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';
import {bytesToGB, isNumeric} from '../../utils/utils';
import {InfoViewer} from '../InfoViewer';
import type {InfoViewerItem} from '../InfoViewer';
import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon';
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 (isNumeric(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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we use only whiteboard data here (without bsc) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's data received from viewer/storage endpoint, it has only whiteboard data (TVDiskStateInfo)

);
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
Loading