Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4643,6 +4643,14 @@
"quotaInNamespace": 50000,
"owner": "testuser",
"bucketLayout": "OBJECT_STORE",
"replicationConfigInfo": {
"type": "RATIS",
"replicationConfig": {
"replicationType": "RATIS",
"replicationFactor": "THREE",
"requiredNodes": 3
}
},
"acls": [
{
"type": "USER",
Expand All @@ -4669,6 +4677,17 @@
"quotaInNamespace": 10000,
"owner": "testuser2",
"bucketLayout": "LEGACY",
"replicationConfigInfo": {
"type": "EC",
"replicationConfig": {
"replicationType": "EC",
"codec": "RS",
"data": 6,
"parity": 3,
"ecChunkSize": 1048576,
"requiredNodes": 9
}
},
"acls": [
{
"type": "GROUP",
Expand Down Expand Up @@ -4737,6 +4756,14 @@
"quotaInNamespace": -1,
"owner": "testuser3",
"bucketLayout": "OBJECT_STORE",
"replicationConfigInfo": {
"type": "STAND_ALONE",
"replicationConfig": {
"replicationType": "STANDALONE",
"replicationFactor": "ONE",
"requiredNodes": 1
}
},
"acls": [
{
"type": "GROUP",
Expand Down
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
Expand Up @@ -41,6 +41,7 @@ import {
Bucket,
BucketLayout,
BucketLayoutTypeList,
BucketReplicationConfig,
BucketsTableProps,
BucketStorage,
BucketStorageTypeList
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor

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/THREE and rs-6-3-1024k elsewhere, 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."?

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`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 codec.toLowerCase() here for consistency?

}
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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ const Buckets: React.FC<{}> = () => {
quotaInBytes: bucket.quotaInBytes,
quotaInNamespace: bucket.quotaInNamespace,
owner: bucket.owner,
acls: bucket.acls
acls: bucket.acls,
replicationConfigInfo: bucket.replicationConfigInfo
}));

const volumeBucketMap: Map<string, Set<Bucket>> = getVolumeBucketMap(buckets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These Ratis and EC response shapes are already defined as RatisInfo, EcInfo, and ReplicationInfo in insights.types.ts.

Could we add a StandaloneInfo variant there and reuse the shared ReplicationInfo here? That would avoid duplicating the serialized ReplicationConfig contract and would also include the backend’s minimumNodes field.

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;
Expand All @@ -53,6 +84,7 @@ export type Bucket = {
owner: string;
acls?: Acl[];
bucketLayout: BucketLayout;
replicationConfigInfo?: BucketReplicationConfig | null;
}

export type BucketResponse = {
Expand Down