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,15 @@
"quotaInNamespace": 50000,
"owner": "testuser",
"bucketLayout": "OBJECT_STORE",
"replicationConfigInfo": {
"type": "RATIS",
"replicationConfig": {
"replicationType": "RATIS",
"replicationFactor": "THREE",
"requiredNodes": 3,
"minimumNodes": 1
}
},
"acls": [
{
"type": "USER",
Expand All @@ -4669,6 +4678,18 @@
"quotaInNamespace": 10000,
"owner": "testuser2",
"bucketLayout": "LEGACY",
"replicationConfigInfo": {
"type": "EC",
"replicationConfig": {
"replicationType": "EC",
"codec": "RS",
"data": 6,
"parity": 3,
"ecChunkSize": 1048576,
"requiredNodes": 9,
"minimumNodes": 6
}
},
"acls": [
{
"type": "GROUP",
Expand Down Expand Up @@ -4737,6 +4758,15 @@
"quotaInNamespace": -1,
"owner": "testuser3",
"bucketLayout": "OBJECT_STORE",
"replicationConfigInfo": {
"type": "STAND_ALONE",
"replicationConfig": {
"replicationType": "STANDALONE",
"replicationFactor": "ONE",
"requiredNodes": 1,
"minimumNodes": 1
}
},
"acls": [
{
"type": "GROUP",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* 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,
minimumNodes: 1
}
})]}
/>
);

expect(screen.getByText('Ratis-3')).toBeInTheDocument();
});

test.each([
['RS', 6, 3, 1048576, 'rs-6-3-1024k'],
['RS', 3, 2, 1048576, 'rs-3-2-1024k'],
['RS', 10, 4, 1048576, 'rs-10-4-1024k'],
['XOR', 10, 4, 2097152, 'xor-10-4-2048k']
] as const)(
'renders an EC bucket with codec %s, %i data and %i parity and a %i byte chunk as %s',
(codec, data, parity, ecChunkSize, expected) => {
render(
<BucketsTable
{...defaultProps}
data={[getBucketWith('ec-bucket', {
type: 'EC',
replicationConfig: {
replicationType: 'EC',
codec,
data,
parity,
ecChunkSize,
requiredNodes: data + parity,
minimumNodes: data
}
})]}
/>
);

expect(screen.getByText(expected)).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,
minimumNodes: 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,
minimumNodes: 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'
};

// 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.toLowerCase()}-${data}-${parity}-${Math.floor(ecChunkSize / 1024)}k`;
}
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 @@ -145,9 +145,9 @@ const OpenKeysTable: React.FC<OpenKeysTableProps> = ({
render: (replicationInfo: ReplicationInfo) => (
<div>
{
(replicationInfo.replicationType === "RATIS")
? replicationInfo.replicationFactor
: `${replicationInfo.codec}-${replicationInfo.data}-${replicationInfo.parity}`
(replicationInfo.replicationType === "EC")
? `${replicationInfo.codec}-${replicationInfo.data}-${replicationInfo.parity}`
: replicationInfo.replicationFactor
}
</div>
)
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 @@ -17,6 +17,7 @@
*/

import { Acl } from "@/v2/types/acl.types";
import { ReplicationInfo } from '@/v2/types/insights.types';
import { Option as MultiOption } from "@/v2/components/select/multiSelect";

// Corresponds to OzoneManagerProtocolProtos.StorageTypeProto
Expand All @@ -37,6 +38,14 @@ export const BucketLayoutTypeList = [
export type BucketLayout = typeof BucketLayoutTypeList[number];


// Corresponds to the serialized org.apache.hadoop.hdds.client.DefaultReplicationConfig
// returned by the Recon bucket endpoint (BucketObjectDBInfo#replicationConfigInfo).
// The nested config is the same shape the OM DB insights endpoints return.
export type BucketReplicationConfig = {
type: string;
replicationConfig?: ReplicationInfo | null;
}

export type Bucket = {
volumeName: string;
name: string;
Expand All @@ -53,6 +62,7 @@ export type Bucket = {
owner: string;
acls?: Acl[];
bucketLayout: BucketLayout;
replicationConfigInfo?: BucketReplicationConfig | null;
}

export type BucketResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,16 @@ export interface EcInfo {
minimumNodes: number;
}

export type ReplicationInfo = RatisInfo | EcInfo;
// StandaloneReplicationConfig serializes its replicationType as STANDALONE,
// without the underscore used by the ReplicationType enum name STAND_ALONE
export interface StandaloneInfo {
replicationType: 'STANDALONE' | 'STAND_ALONE';
replicationFactor: string;
requiredNodes: number;
minimumNodes: number;
}

export type ReplicationInfo = RatisInfo | EcInfo | StandaloneInfo;

// Open Keys
export type OpenKeys = {
Expand Down