-
Notifications
You must be signed in to change notification settings - Fork 625
HDDS-13625. Recon UI: Add "Replication Type" col on Bucket page #10968
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| /* | ||
| * 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 { vi } from 'vitest'; | ||
| import { render, screen } from '@testing-library/react'; | ||
|
|
||
| import BucketsTable from '@/v2/components/tables/bucketsTable'; | ||
| import { Bucket, BucketsTableProps } from '@/v2/types/bucket.types'; | ||
|
|
||
| function getBucketWith( | ||
| name: string, | ||
| replicationConfigInfo: Bucket['replicationConfigInfo'] | ||
| ): Bucket { | ||
| return { | ||
| volumeName: 'vol1', | ||
| name, | ||
| versioning: false, | ||
| storageType: 'DISK', | ||
| creationTime: 1728280581608, | ||
| modificationTime: 1728280581608, | ||
| usedBytes: 0, | ||
| usedNamespace: 0, | ||
| quotaInBytes: -1, | ||
| quotaInNamespace: -1, | ||
| owner: 'om', | ||
| acls: [], | ||
| bucketLayout: 'FILE_SYSTEM_OPTIMIZED', | ||
| replicationConfigInfo | ||
| }; | ||
| } | ||
|
|
||
| const defaultProps: BucketsTableProps = { | ||
| loading: false, | ||
| data: [], | ||
| handleAclClick: vi.fn(), | ||
| searchColumn: 'name', | ||
| searchTerm: '', | ||
| selectedColumns: [ | ||
| { label: 'Bucket', | ||
| value: 'name' }, | ||
| { label: 'Volume', | ||
| value: 'volumeName' }, | ||
| { label: 'Replication Type', | ||
| value: 'replicationType' } | ||
| ] | ||
| }; | ||
|
|
||
| describe('BucketsTable Replication Type column', () => { | ||
| test('renders the Ratis variant for a Ratis bucket', () => { | ||
| render( | ||
| <BucketsTable | ||
| {...defaultProps} | ||
| data={[getBucketWith('ratis-bucket', { | ||
| type: 'RATIS', | ||
| replicationConfig: { | ||
| replicationType: 'RATIS', | ||
| replicationFactor: 'THREE', | ||
| requiredNodes: 3 | ||
| } | ||
| })]} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Ratis-3')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders the EC variant for an Erasure Coded bucket', () => { | ||
| render( | ||
| <BucketsTable | ||
| {...defaultProps} | ||
| data={[getBucketWith('ec-bucket', { | ||
| type: 'EC', | ||
| replicationConfig: { | ||
| replicationType: 'EC', | ||
| codec: 'RS', | ||
| data: 6, | ||
| parity: 3, | ||
| ecChunkSize: 1048576, | ||
| requiredNodes: 9 | ||
| } | ||
| })]} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('RS-6-3-1024k')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders the Standalone variant for a single replica bucket', () => { | ||
| render( | ||
| <BucketsTable | ||
| {...defaultProps} | ||
| data={[getBucketWith('standalone-bucket', { | ||
| type: 'STAND_ALONE', | ||
| replicationConfig: { | ||
| replicationType: 'STANDALONE', | ||
| replicationFactor: 'ONE', | ||
| requiredNodes: 1 | ||
| } | ||
| })]} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Standalone-1')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders the Standalone variant for the STAND_ALONE enum spelling', () => { | ||
| render( | ||
| <BucketsTable | ||
| {...defaultProps} | ||
| data={[getBucketWith('standalone-enum-bucket', { | ||
| type: 'STAND_ALONE', | ||
| replicationConfig: { | ||
| replicationType: 'STAND_ALONE', | ||
| replicationFactor: 'ONE', | ||
| requiredNodes: 1 | ||
| } | ||
| })]} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Standalone-1')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('falls back to the replication type when the nested config is absent', () => { | ||
| render( | ||
| <BucketsTable | ||
| {...defaultProps} | ||
| data={[getBucketWith('type-only-bucket', { type: 'RATIS' })]} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('RATIS')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('falls back to NA when replicationConfigInfo is missing', () => { | ||
| render( | ||
| <BucketsTable | ||
| {...defaultProps} | ||
| data={[getBucketWith('legacy-bucket', undefined)]} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('NA')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('falls back to NA when replicationConfigInfo is null', () => { | ||
| render( | ||
| <BucketsTable | ||
| {...defaultProps} | ||
| data={[getBucketWith('null-bucket', null)]} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('NA')).toBeInTheDocument(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ import { | |
| Bucket, | ||
| BucketLayout, | ||
| BucketLayoutTypeList, | ||
| BucketReplicationConfig, | ||
| BucketsTableProps, | ||
| BucketStorage, | ||
| BucketStorageTypeList | ||
|
|
@@ -78,6 +79,30 @@ function renderBucketLayout(bucketLayout: BucketLayout) { | |
| return <Tag color={color}>{bucketLayout}</Tag>; | ||
| }; | ||
|
|
||
| // StandaloneReplicationConfig serializes replicationType as STANDALONE, while the | ||
| // ReplicationType enum name is STAND_ALONE, so both spellings are mapped here | ||
| const REPLICATION_TYPE_LABELS: Record<string, string> = { | ||
| RATIS: 'Ratis', | ||
| STAND_ALONE: 'Standalone', | ||
| STANDALONE: 'Standalone' | ||
| }; | ||
|
|
||
| // Mirrors the replication strings Ozone uses elsewhere, e.g. Ratis-3 and RS-6-3-1024k | ||
| function formatReplicationType(replicationConfigInfo?: BucketReplicationConfig | null) { | ||
| const replicationConfig = replicationConfigInfo?.replicationConfig; | ||
| if (replicationConfig?.replicationType === 'EC') { | ||
| const { codec, data, parity, ecChunkSize } = replicationConfig; | ||
| return `${codec}-${data}-${parity}-${Math.floor(ecChunkSize / 1024)}k`; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Ozone itself prints rs-6-3-1024k (lowercase) everywhere else. Would it make sense to use |
||
| } | ||
| if (replicationConfig) { | ||
| const label = REPLICATION_TYPE_LABELS[replicationConfig.replicationType] | ||
| ?? replicationConfig.replicationType; | ||
| return `${label}-${replicationConfig.requiredNodes}`; | ||
| } | ||
| // Fall back to the bare type, then to NA for buckets with no default replication config | ||
| return replicationConfigInfo?.type ?? 'NA'; | ||
| }; | ||
|
|
||
| export const COLUMNS: ColumnsType<Bucket> = [ | ||
| { | ||
| title: 'Bucket', | ||
|
|
@@ -127,6 +152,15 @@ export const COLUMNS: ColumnsType<Bucket> = [ | |
| sorter: (a: Bucket, b: Bucket) => a.bucketLayout.localeCompare(b.bucketLayout), | ||
| render: (bucketLayout: BucketLayout) => renderBucketLayout(bucketLayout) | ||
| }, | ||
| { | ||
| title: 'Replication Type', | ||
| dataIndex: 'replicationConfigInfo', | ||
| key: 'replicationType', | ||
| sorter: (a: Bucket, b: Bucket) => formatReplicationType(a.replicationConfigInfo) | ||
| .localeCompare(formatReplicationType(b.replicationConfigInfo)), | ||
| render: (replicationConfigInfo: BucketReplicationConfig | null | undefined) => | ||
| formatReplicationType(replicationConfigInfo) | ||
| }, | ||
| { | ||
| title: 'Creation Time', | ||
| dataIndex: 'creationTime', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,37 @@ export const BucketLayoutTypeList = [ | |
| export type BucketLayout = typeof BucketLayoutTypeList[number]; | ||
|
|
||
|
|
||
| // Corresponds to the serialized org.apache.hadoop.hdds.client.RatisReplicationConfig | ||
| // and StandaloneReplicationConfig. The latter serializes its replicationType as | ||
| // STANDALONE, while the enum name used elsewhere is STAND_ALONE, so both spellings | ||
| // can reach the UI. | ||
| type BucketRatisReplicationConfig = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These Ratis and EC response shapes are already defined as Could we add a |
||
| replicationType: 'RATIS' | 'STAND_ALONE' | 'STANDALONE'; | ||
| replicationFactor: string; | ||
| requiredNodes: number; | ||
| } | ||
|
|
||
| // Corresponds to the serialized org.apache.hadoop.hdds.client.ECReplicationConfig | ||
| type BucketECReplicationConfig = { | ||
| replicationType: 'EC'; | ||
| codec: string; | ||
| data: number; | ||
| parity: number; | ||
| ecChunkSize: number; | ||
| requiredNodes: number; | ||
| } | ||
|
|
||
| type BucketReplicationInfo = | ||
| | BucketRatisReplicationConfig | ||
| | BucketECReplicationConfig; | ||
|
|
||
| // Corresponds to the serialized org.apache.hadoop.hdds.client.DefaultReplicationConfig | ||
| // returned by the Recon bucket endpoint (BucketObjectDBInfo#replicationConfigInfo) | ||
| export type BucketReplicationConfig = { | ||
| type: string; | ||
| replicationConfig?: BucketReplicationInfo | null; | ||
| } | ||
|
|
||
| export type Bucket = { | ||
| volumeName: string; | ||
| name: string; | ||
|
|
@@ -53,6 +84,7 @@ export type Bucket = { | |
| owner: string; | ||
| acls?: Acl[]; | ||
| bucketLayout: BucketLayout; | ||
| replicationConfigInfo?: BucketReplicationConfig | null; | ||
| } | ||
|
|
||
| export type BucketResponse = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Ozone uses formats such as
RATIS/THREEandrs-6-3-1024kelsewhere, rather than Ratis-3 and uppercase RS-.... Perhaps change it to a local description such as "Formats the bucket’s default replication configuration for display."?